C# lock dimensions

Code is drawing segmented dimensions - so a row of dimensions.

I want to lock the dims… But I get a warning about it having more than one segment.

How do I overcome this?

I tried something along these lines:

// Create the first perpendicular dimension line (start)
Line dimensionLineStart = Line.CreateBound(Start, End);
Dimension newDimension1 = doc.Create.NewDimension(view, dimensionLineStart, gridReferences);

// Lock the dimension
newDimension1.IsLocked = true;

You’ll have to get the array of Dimension Segments <Dimension.Segments> and iterate through the list and change the IsLocked property. of each DimensionSegment.
Don’t know if there is a node for that, but the python is pretty straightforward.

2 Likes

Ty, it’s in C#.

after completing the dimension use this

EDIT: modified for your code

foreach (DimensionSegment seg in newDimension1.Segments)
{
    seg.IsLocked = true;
}
3 Likes

…but you’ll need a little if then action.
Check Dimension.HasOneSegment. If true, then you’ll need your first operation. Otherwise - iterate.

4 Likes

that’s true, I didn’t account for single segment dim. Good catch!

2 Likes

Thanks both, I’ll try it tomorrow. :slight_smile:

1 Like

Whooo!! It works. Thank you :slight_smile:

1 Like

I will add that it can be good to have access to revit lookup, because looking at all the objects/properties on a object can help to understand these little areas of quirks as you can drill down the data and see where the information is saved.

Then of course can dig correctly in the SDK, learning resources or even online help to navigate to the correct methods.

2 Likes