How to connect expressions with Sketch linear dimensions?

Hey NXOpen Users ;)

I desperately tried to link created expressions with linear dimensions, but I just don´t get it. It would be really awesome if someone could tell me how this works :)

Below you can find a C# Code Snippet of my Journal. Initially the Journal creates a sketch (containing only a line). Then it creates a number expression and adds a linear dimension to the line. If I run my journal, I get an error,saying that the object referene is not set on an object instance..

// Get the unit
NXOpen.Unit mm = (Unit)thePart.UnitCollection.FindObject("MilliMeter");
//Create the Expression
NXOpen.Expression expression1;
expression1 = thePart.Expressions.CreateNumberExpression("Length = 200", mm);

// Create the linear dimension
NXOpen.Annotations.Dimension nuller = null;
SketchLinearDimensionBuilder linDimension1;
linDimension1 = thePart.Sketches.CreateLinearDimensionBuilder(nuller);

// Connect the linear dimension to the geometry of the sketch
linDimension1.FirstAssociativity.SetValue(InferSnapType.SnapType.Start, lino, thePart.ModelingViews.WorkView, sp, null, null, origin);

linDimension1.SecondAssociativity.SetValue(InferSnapType.SnapType.End, lino, thePart.ModelingViews.WorkView, ep, null, null, origin);

//Connect the linear dimension with the expression
linDimension1.Driving.ExpressionValue.SetFormula("Length");

linDimension1.Driving.ExpressionMode = NXOpen.Annotations.DrivingValueBuilder.DrivingExpressionMode.KeepExpression;

Found the solution! Instead of the SketchLinearDimensionBuilder I am now using the SketchDimensional COnstraint.

Maybe the Code is helpful for someone :)

NXOpen.Expression expression1;
expression1 = thePart.Expressions.CreateNumberExpression("Length = 200", mm);

SketchDimensionalConstraint sketchDimensionalConstraint ;

Sketch.DimensionGeometry dimensionGeometry1 = new Sketch.DimensionGeometry();
dimensionGeometry1.Geometry = lino;
dimensionGeometry1.AssocType = Sketch.AssocType.StartPoint;
dimensionGeometry1.AssocValue = 0;

Sketch.DimensionGeometry dimensionGeometry2 = new Sketch.DimensionGeometry();
dimensionGeometry2.Geometry = lino;
dimensionGeometry2.AssocType = Sketch.AssocType.EndPoint;
dimensionGeometry2.AssocValue = 0;

sketchDimensionalConstraint = sketch1.CreateDimension(Sketch.ConstraintType.HorizontalDim, dimensionGeometry1, dimensionGeometry2, origin, expression1);