Finding Tag'sleader start andend point

Finding Tag'sleader start andend point

Hans_Dwe
Enthusiast Enthusiast
960 Views
14 Replies
Message 1 of 15

Finding Tag'sleader start andend point

Hans_Dwe
Enthusiast
Enthusiast

Hallo ! i have a quesion relating to Tags, i am trying to move the Tag's head to a center of a grid point, but in order to move it correctly i need to find the coordination of the leaderstart point and leaderend point. is there to method to find this out? as well what the boundingbox of the tags is it the TagsHead only or as well including the Leaders ? thank you so much !

 

Hans_Dwe_0-1690381412660.png

 

0 Likes
Accepted solutions (1)
961 Views
14 Replies
Replies (14)
Message 2 of 15

jeremy_tammik
Alumni
Alumni

Have you checked what properties and relationship of your tags can be inspected using RevitLookup? That would be the standard approach to this programming task:

  

https://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-onto...

  

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

Hans_Dwe
Enthusiast
Enthusiast

Hallo @jeremy_tammik, i checked it, i found only the position of the Stag's Head, my problem is that i am trying to move the tags, but somehow the moving of the tags while its has a leader are not predictable. if this is way to find the leader points are not possible, is it possible to create the tags without leader then move it and create the leader after that or not? 

thank you 

Hans_Dwe_0-1690451165227.png

 

0 Likes
Message 4 of 15

Mohamed_Arshad
Advisor
Advisor

Hi @Hans_Dwe 
At Which Point you need to move the Tag? Can you please show case the point which tag need to move and place.

I saw some similar post regarding moving the Tag. Kindly check the below link.

URL : https://forums.autodesk.com/t5/revit-api-forum/revit-tag-point-of-origin/td-p/10791943 


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 5 of 15

Hans_Dwe
Enthusiast
Enthusiast

Hi @Mohamed_Arshad

i am trying to move the Tagshead to center point of Grid, somehow the center of the Head tags are not in the center, and the leader distance affects that the tag placed propely over the grid. 

 

this 

Hans_Dwe_2-1690543915216.png

 

 

to this 

 

Hans_Dwe_1-1690543868169.png

 

 

0 Likes
Message 6 of 15

Mohamed_Arshad
Advisor
Advisor

HI @Hans_Dwe 

its a floor texture grid?


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 7 of 15

Hans_Dwe
Enthusiast
Enthusiast

Hi @Mohamed_Arshad, no it a 3d objects which have center points

0 Likes
Message 8 of 15

Mohamed_Arshad
Advisor
Advisor

Hi @Hans_Dwe 

If its possible can you please share the sample here so that I will create a workaround in my end


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 9 of 15

Hans_Dwe
Enthusiast
Enthusiast

Hi @Mohamed_Arshad , my goal is to aligne the start of the leader with it end, i just created a Tag without leader at the beggining then after the move part i just created it, because it was occuring a problem is this possible ?, here just a sample "

ElementMulticategoryFilter multiCatFilter = new ElementMulticategoryFilter(categories);
try
{
FilteredElementCollector linkedCollector = new FilteredElementCollector(linkedDoc, doc.ActiveView.Id)
.WherePasses(multiCatFilter).WhereElementIsNotElementType();

foreach (Element RVT_Links_Elements in linkedCollector)
{
bb = RVT_Links_Elements.get_BoundingBox(doc.ActiveView);

if (bb != null)
{
XYZ centerBounding = (bb.Min + bb.Max) / 2.0;

ref_link = new Reference(RVT_Links_Elements).CreateLinkReference(element);

// Create a new tag
IndependentTag tag = IndependentTag.Create(doc, doc.ActiveView.Id, ref_link, false, tmode, toriant, centerBounding);

// Add the tag to the list of created tags
tags.Add(tag);

}
}
}"  and here is the move part "

using (Transaction transMoveTags = new Transaction(doc, "Move Tags to Center of Lines"))
{
transMoveTags.Start();

for (int i = 0; i < tags.Count; i++)
{
IndependentTag tag = tags[i];
XYZ tagCenter = GetTagCenter(tag);

// Find the closest rectangle center to the tag
XYZ nearestRectangleCenter = rectangleCenters
.OrderBy(center => center.DistanceTo(tagCenter))
.FirstOrDefault();

if (nearestRectangleCenter != null)
{
// Move the tag to the nearest rectangle center
ElementTransformUtils.MoveElement(doc, tag.Id, nearestRectangleCenter - tagCenter);

// Remove the used rectangle center from the list
rectangleCenters.Remove(nearestRectangleCenter);
}

tag.HasLeader = true; // make sure the tag has a leader
tag.LeaderEndCondition = LeaderEndCondition.Free; // allow the leader end to be moved freely

}

transMoveTags.Commit();
}" 

Hans_Dwe_0-1691056929158.png

 

0 Likes
Message 10 of 15

michael-coffey
Advocate
Advocate

The TagHeadPosition property has a setter.  Try setting the property with an XYZ instead of using the move method.

0 Likes
Message 11 of 15

Hans_Dwe
Enthusiast
Enthusiast

Hallo @michael-coffey thanks for the answer, i tried it and worked partially, it worked for the tags that have a horizantal Host element but not for the vertical, i would like to ask if you might know why its not working for vertical cases. i would be very appricated for any suggesstions. 

List<Tuple<IndependentTag, Reference>> tagsWithReferences = new List<Tuple<IndependentTag, Reference>>();

 

// Create a new tag at the center of the longest side of the bounding box
IndependentTag tag = IndependentTag.Create(doc, doc.ActiveView.Id, ref_link, false, tmode, toriant, centerOfLongestSide);
tagsWithReferences.Add(new Tuple<IndependentTag, Reference>(tag, ref_link));
"using (Transaction transStraightenLeader = new Transaction(doc, "Straighten Tag Leaders"))
{
transStraightenLeader.Start();



foreach (var tagWithReference in tagsWithReferences)
{

IndependentTag tag = tagWithReference.Item1;
tag.HasLeader = true;
tag.LeaderEndCondition = LeaderEndCondition.Free;

Reference tagReference = tagWithReference.Item2;

// Get the TagHead position
XYZ tagHeadPosition = tag.TagHeadPosition;

// Get the LeaderEnd position using the reference
XYZ leaderEndPosition = tag.GetLeaderEnd(tagReference);

// Get the bounding box of the host element associated with the tag
Element hostElement = doc.GetElement(tagReference);
BoundingBoxXYZ hostBB = hostElement.get_BoundingBox(doc.ActiveView);

// Check if the bounding box is more vertical or horizontal
double width = bb.Max.X - bb.Min.X;
double height = bb.Max.Y - bb.Min.Y;

// Create a new LeaderEnd point that aligns with the TagHead
XYZ newLeaderEnd;

if (width > height) // If the bounding box is horizontal
{
newLeaderEnd = new XYZ(tagHeadPosition.X, leaderEndPosition.Y, tagHeadPosition.Z);
}
else // If the bounding box is vertical
{
newLeaderEnd = new XYZ(leaderEndPosition.X, tagHeadPosition.Y, tagHeadPosition.Z);
}

// Set the new LeaderEnd to the tag
tag.SetLeaderEnd(tagReference, newLeaderEnd);
}

transStraightenLeader.Commit();
}

"

0 Likes
Message 12 of 15

Hans_Dwe
Enthusiast
Enthusiast

Hans_Dwe_0-1691569557459.png

 

0 Likes
Message 13 of 15

michael-coffey
Advocate
Advocate
Accepted solution

Perhaps if you provided a working macro, currently the code is not testable.  Also, there shouldn't be a need to create a tuple of a tag with its reference, because the reference can easily be obtained with IndependentTag.GetTaggedReferences method.

0 Likes
Message 14 of 15

Hans_Dwe
Enthusiast
Enthusiast

Hallo Micaheal, i checked the whole Code again, you are right, it was straight forward, i made a mistake. thank you so much for the solution.

0 Likes
Message 15 of 15

george.potts
Enthusiast
Enthusiast

Hi did you ever find a way of reliably setting the tag leader start point, so it keeps it as a straight line? Encountered a similar problem.

0 Likes