SpatialElementTag Leader position

SpatialElementTag Leader position

tamas.deri
Advocate Advocate
773 Views
5 Replies
Message 1 of 6

SpatialElementTag Leader position

tamas.deri
Advocate
Advocate

I'm trying to manipulate the SpatialElementTag and its leaders coordinates, but although the Revit API docs states that both LeaderEnd, LeaderElbow and TagHeadPosition can be set, it doesn't work. Nothing happens, no exception, just nothing. Its the same for version 2020, and 2021 as well. It works with any tags of the IndependentTag class, and I'm trying the same with the SpatialElementTag without success. What is the magic, if there is any?

0 Likes
774 Views
5 Replies
Replies (5)
Message 2 of 6

franciscopossetto
Advocate
Advocate

Hey,

 

I have tested this, in Revit 2020 and it worked.

 

Document doc = uiDoc.Document;
Reference pickObject = uiDoc.Selection.PickObject(ObjectType.Element);
SpatialElementTag tag = doc.GetElement(pickObject.ElementId) as SpatialElementTag;

XYZ currentPosition1 = tag.LeaderEnd;
XYZ newPosition1 = new XYZ(currentPosition1.X, currentPosition1.Y + 3, currentPosition1.Z);

XYZ currentPosition2 = tag.LeaderElbow;
XYZ newPosition2 = new XYZ(currentPosition2.X, currentPosition2.Y + 3, currentPosition2.Z);

XYZ currentPosition3 = tag.TagHeadPosition;
XYZ newPosition3 = new XYZ(currentPosition3.X, currentPosition3.Y + 3, currentPosition3.Z);

using (Transaction t = new Transaction(doc, "Change leader position"))
{
    t.Start();
    tag.LeaderEnd = newPosition1;
    tag.LeaderElbow = newPosition2;
    tag.TagHeadPosition = newPosition3;
    t.Commit();
}

 

 

 

I used the Room tag that is by default in the Revit Sample Project. The location of the 3 points was modified correctly. The only caveat I got while testing was that the LeaderEnd has to be inside the room, which makes sense.

 

I hope it helps,

Kind regards!

Github:
https://github.com/franpossetto
0 Likes
Message 3 of 6

tamas.deri
Advocate
Advocate

I've tried your code as a Macro, and it did work. However if I only apply

tag.TagHeadPosition = newPosition3;

the outcome is not visible on the screen, like nothing happened, but once I hit undo and redo, the change is visible. It seems  there is some weird issue with regenerating. I'll attach a screen recording.

0 Likes
Message 4 of 6

Sean_Page
Collaborator
Collaborator

Could try Regenerating the document after the changes?

Regenerate Method (revitapidocs.com)

 

Or update the current view

RefreshActiveView Method (revitapidocs.com)

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 5 of 6

tamas.deri
Advocate
Advocate

None of the above works, unfortunately. I understand that there is an automatic doc.Regenerate() at the end of each transaction, and calling it after commiting the transaction throws an InvalidOperationException that there is no open transactions, which is quite strange, why would I need a Transaction, to regenerate?

0 Likes
Message 6 of 6

gankeyu
Community Visitor
Community Visitor

I ran into the same problem. It turns out you need to set LeaderElbow in the same transaction to force a update. No regen is required. For example of straight RoomTags: 

tag.TagHeadPosition = SomeNewValue();
tag.LeaderElbow = (tag.LeaderEnd + tag.TagHeadPosition) / 2;

for elbowed tags, I think

tag.LeaderElbow = tag.LeaderElbow;

will do.

 

0 Likes