SetElementIds does not show lock icon on Alignment constraints

SetElementIds does not show lock icon on Alignment constraints

steven.williams.as
Advocate Advocate
486 Views
4 Replies
Message 1 of 5

SetElementIds does not show lock icon on Alignment constraints

steven.williams.as
Advocate
Advocate

I would like to replicate Select by ID for Alignment elements. For example, I can get a constraint element Id using RevitLookup → GetDependentElements → Dimensions.

 

2022-05-22 14.32.48 Revit_EJSiZMXs9P.png

 

Then I can use Manage → Inquiry → Select by ID to find the constraining line. If only one ID is typed in, both the line and the constraint lock are displayed. Revit annoyingly makes the lock disappear if multiple IDs are entered, but that issue is for another day.

 

2022-05-22 14.33.16 Revit_FoBHeYBUED.png2022-05-22 14.33.53 Revit_0DXppg7DXx.png

 

The important point here is the lock, which is usually only displayed when using the Align tool, and otherwise cannot easily be unlocked. Figuring out which elements have which constraints graphically is thus time-consuming and difficult to do. This is the frustration I am trying to circumvent.

 

2022-05-22 14.39.34 Revit_dbU77Pf6T4.png

 

I can select the offending locks with a macro, but it does not show the lock icons.

 

 

public void ShowAlignments()
{
	UIApplication uiapp = new UIApplication(Application);
	
	IList<ElementId> selectedIds = new List<ElementId>();
	IList<Reference> selectedRefs = uiapp.ActiveUIDocument.Selection.PickObjects(ObjectType.Element, "Pick an element");
	
	foreach (Reference r in selectedRefs)
	{
		selectedIds.Add(r.ElementId);
	}
	
	HashSet<ElementId> allAlignmentIds = new HashSet<ElementId>();
	foreach (ElementId id in selectedIds)
	{
		var cst = BuiltInCategory.OST_Constraints;
		var cef = new ElementCategoryFilter(cst);
		allAlignmentIds.UnionWith(doc.GetElement(id).GetDependentElements(cef));
	}
	
	uiapp.ActiveUIDocument.Selection.SetElementIds(allAlignmentIds);
}

 

 

One more thing -- Reveal Constraints is unhelpful here. Using either Select by ID (UI) or SetElementIds (API) in that view mode, the display is no more helpful, and only turns some of the constraint lines blue to indicate selection. If the same line is used in another element constraint, it remains red even when selected. In the following example, the two blue vertical lines on the left and the two red horizontal lines are both selected.

 

2022-05-22 15.34.42 Revit_GU3lhxk4Rt.png

 

How do I make the lock icon show up like it does using the Select by ID tool? Bonus points for showing multiple locks to identify each of the constraints.

Accepted solutions (1)
487 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

Maybe you can run the built-in Select by ID tool using PostCommand?

 

One serious problem is that it will pop up the standard user interface prompting for the element id to be entered manually.

 

You might be able to use the native Windows API to trap that dialogue when it is displayed, programmatically enter the required value, and programmatically click the Show or OK button. Tricky hacking.

  

 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5

steven.williams.as
Advocate
Advocate

I can confirm that Post command works for opening the Select by ID tool. This blog post has more information for anyone else interested.

 

// copy the ID to the clipboard for the user to paste it in
Clipboard.SetText(yourElementIdHere);

// get the command and post it
RevitCommandId ID = RevitCommandId.LookupPostableCommandId(PostableCommand.SelectById);
uiapp.PostCommand(ID);

 

However, it doesn't automatically fill in the details, as you mentioned. Copying the Id's to the clipboard would be a quick "fix." Philosophically, I don't like that idea because it shifts to automating the UI instead of implementing the API.

Message 4 of 5

jeremy_tammik
Alumni
Alumni
Accepted solution

Well, it won't hurt to submit this as a wish to the Revit Idea Station.

 

Whenever you require new or enhanced Revit product or Revit API functionality, the Revit Idea Station is the place to go.

 

Please search there for a corresponding wish list entry for the suggested functionality and add your comments to it, or create a new one, if none already exists:

 

https://forums.autodesk.com/t5/revit-ideas/idb-p/302

 

Tag it as an API wish:

 

https://forums.autodesk.com/t5/revit-ideas/idb-p/302/tab/most-recent/label-name/api

 

Ensuring that a wish gets as many votes as possible helps underline its importance to you and the rest of the developer community.

 

The Revit Idea Station is currently one of the main driving input forces for Revit API enhancements.

 

The Revit development team look there. Your comment here in the discussion forum might be overlooked.

 

Thank you!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 5 of 5

steven.williams.as
Advocate
Advocate

I think this is basically confirmation that the feature is not implemented or available in the API at this point. Thanks for your feedback and clarification. I did not find an existing idea like this, so I have submitted the idea here.