Lock / Unlock Dimensions

Continuing the discussion from Dimension lock (several):

I have attempted to use the final Python Script that Jacob Small provided, unfortunately the dimensions don’t seem to be adjusting.

I notice the post is a little old. I suspect I need to update the script to be compatible with current versions but i’m not sure how.

I’m using Revit 2021.1.7 and Dynamo 2.6.2

The Python Node is not giving any error’s so not sure where to start troubleshooting this one.
I’ve selected Dims that are locked, and ones that are unlocked, neither appear to do anything when run

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitAPI")

import Autodesk
from  Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
dims = UnwrapElement(IN[0])
lock = IN[1]

if not hasattr(dims,'__iter__'):
	dims = [dims]

TransactionManager.Instance.EnsureInTransaction(doc)

for dim in dims:
	if dim.NumberOfSegments>0:
		for ds in dim.Segments:
			ds.IsLocked = lock
	else:
		dim.IsLocked = lock
        
TransactionManager.Instance.TransactionTaskDone()

OUT = dims

If anyone could point me in the right direction would be great :slight_smile:
edit The Python node does seem to process - i get a list of the input dimension on the output - it’s just that they don’t lock or unlock in Revit.

Checking the specifics of what type of data this property is expecting, and when things can be set, raises a question, are any of the below conditions present that would stop the dimensions being locked?

Remarks
This property always returns false if the dimension is a radial or spot dimension. This property cannot be set if the dimension has been labeled, or if the dimension shape is arc-length, radial, diameter or spot, or if the dimension is linear with more than one segment.

Hey Ewan,
Thanks for taking a look.

Some good questions. I have double checked using this on a simple linear dimension, no labels and with only 1 segment (although I believe the “for ds in dim.segments:” loop should take care of multi segment dimensions?).

I have used Revit Lookup to check out the .IsLocked property and i’m confused.

CanBeLocked = true
But regardless of whether I lock the dim or leave it unlocked, the IsLocked property always says false, (as you alluded to)

I’m still thinking that something must have changed between versions, because others have reported that python code working properly for them (I think that was about a year ago though, and not sure what versions they were running)

I just had a wee-look through the API docs at versions 2019 to 2023 and the Class for Dimensions still has the IsLocked property as ‘Unchanged’ between versions.

I’ll have a look soon when I’m back at the PC.

No problem at all, thanks again for taking a look :slight_smile:

So I can replicate the behavior.

ClKoNT37I3

The python code only works if the Dimension or Multiple Segment dimension is Unlocked to start with, and has not been locked via a user-click. Why this would be the case now becomes the question…

Does a user-defined-lock update additional parameters within the Dimension instance?
Thoughts @jacob.small :thinking:

1 Like

Not sure what’s happening here. I’ll try and take a look this week, but may not have time and I have a conference next week. Revit API forum might be a good place look for further help here.

1 Like

Thanks for that tip Ewan.

Continuing to search a few different sources, I’ve read that a constraint element is created when the user locks the dimension. In this Link (Building Coder Article on Dimension Constraints) Jeremy talks about a method to delete the constraints thereby unlocking the dimension.

I found a post by L.Maas (Message 2 of 4 in the thread) showing a dynamo graph to achieve this. However when i tried to replicate i’m getting different results. My attempt below:


The Constraint elements in my graph seem to be causing errors due to nulls, which they don’t seem to do in the sample provided by L.Maas

Also of note, I am unable to select the constraint elements in Revit (select by ID) I get the error “The Following Element IDs can’t be selected in this mode:”

So far i haven’t been able to nail down which constraint is related to which element/dimension etc. I have been wondering if the constraints in the list are also showing me constraints between other elements? maybe sketch lines, or top/bottom constraints? Would that make sense? Or locked dimensions in loaded families?

And another thing that I don’t understand was the fact that I’m getting Automatic sketch dimensions in the list when i have nothing selected in Revit. I would try to filter out some of the dimensions but the constraint dimensions in the list keep causing nulls and I get errors in my filtering nodes.
I’m not certain why the screen shot in L.Maas attempt showed blank information on the constraint elements, whilst i’m getting nulls.