Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Independent tag Bounding Box getting null for the second time.

praveen.cMXB2H
Enthusiast

Independent tag Bounding Box getting null for the second time.

praveen.cMXB2H
Enthusiast
Enthusiast

UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
UIDocument uidoc = commandData.Application.ActiveUIDocument;

IndependentTag tag = doc.GetElement(ckt) as IndependentTag;

BoundingBoxXYZ tagBox = tag.get_BoundingBox(uidoc.Document.ActiveView);

//tagBox not null

IndependentTag tag2 = doc.GetElement(ckt) as IndependentTag;

// Same tag (ckt)

 



using (Transaction trans = new Transaction(doc, "Tag D"))
{
trans.Start("Start");
tag.HasLeader = false;
trans.Commit();
}

BoundingBoxXYZ tagBox2 = tag2.get_BoundingBox(uidoc.Document.ActiveView);
//tagBox  null

//With using below code every time getting Bounding Box, but it is generating graphics for every tag and taking long //time.

View sec = doc.GetElement(tag.OwnerViewId) as View;

BoundingBoxXYZ tagBox = tag.get_BoundingBox(sec);

 

//Is there any other method to get bounding box without generating graphics.

0 Likes
Reply
855 Views
10 Replies
Replies (10)

scgq425
Advocate
Advocate

Hi praveen.cMXB2H:

i debug u code in my machine , is right . so u can monitor the result : hasleader or u indenpendtag family 

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes

praveen.cMXB2H
Enthusiast
Enthusiast

I did not understand , can you please explain clearly.

0 Likes

scgq425
Advocate
Advocate

Hi  praveen.cMXB2H:

i use this code in my code ,is ok ,. u can post u file or check the tag.hasleader()'s result

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes

TripleM-Dev.net
Advisor
Advisor

Hi @praveen.cMXB2H ,

 

From this line:

//With using below code every time getting Bounding Box, but it is generating graphics for every tag and taking long //time.

View sec = doc.GetElement(tag.OwnerViewId) as View;

 

This is after you set the HasLeader to false?

Are you using a seperate transaction for each HasLeader change?, this will cause numerous regenerations of the view/model. This would explane the long time processing.

 

Place all the edits in one Transaction and buffer the Tag elements, then retrieve the view for each element.

I have multiple commands like this, for 1000's elements this runs in under a second.

Also first  check if the leader is actually enabled before setting it to false.

 

- M

0 Likes

praveen.cMXB2H
Enthusiast
Enthusiast

using (Transaction rvtTransaction = new Transaction(doc))
{
rvtTransaction.Start("Move Tags");

IndependentTag tag = doc.GetElement(tags[0]) as IndependentTag;

BoundingBoxXYZ tagBox = tag.get_BoundingBox(doc.ActiveView);

//Getting Bounding Box

rvtTransaction.Commit();

IndependentTag tag2 = doc.GetElement(tags[0]) as IndependentTag;

BoundingBoxXYZ tagBox2 = tag2.get_BoundingBox(doc.ActiveView);

 

//Getting BoundingBox null


//For the same tag after rvtTransaction.Commit(); Bounding Box getting null
}

0 Likes

Mohamed_Arshad
Advisor
Advisor

HI @praveen.cMXB2H 

 

       I tested you code using Wall Tags, For me second time also it is not null, I think you need to debug complete code and find out the bug or the share the project that you're facing error. So that I can test in my end.

 

Debug Reference Images

Mohamed_Arshad_0-1711125357302.png

 

Mohamed_Arshad_1-1711125383012.png

Hope this will Helps 🙂

Thanks & Regards,
Mohamed Arshad K
0 Likes

ctm_mka
Advocate
Advocate

@praveen.cMXB2H As Mohamed stated, getting the tag2 after  the transaction will fix the null issue. The reason, i believe, is in your original code the definition of tag2 is changed so it becomes null, sort of. as for performance issues, why do you need the bounding box of the same tag three times?

0 Likes

TripleM-Dev.net
Advisor
Advisor

Propably the HasLeader property is set to False in the transaction. (like in the first code sample)

This could cause the Tag to move to another location that's maybe outside the views bounds, that would explane the geometry issue.

0 Likes

praveen.cMXB2H
Enthusiast
Enthusiast

Hi @Mohamed_Arshad , 

 

Please look at the attached sample file for tags. These tags are used to obtain bounding boxes within this file. However, the same tags do not seem to retrieve bounding boxes for larger files. Please review the code as well.

 

 

//Sample code

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;

IList<Reference> refs = null;

try
{
refs = uiApp.ActiveUIDocument.Selection.PickObjects(ObjectType.Element);
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException exception)
{
return Result.Succeeded;

}


double ElbowOriginY;
double ElbowOriginX;
double ElbowOriginZ;
using (Transaction rvtTransaction = new Transaction(doc))
{
rvtTransaction.Start("Move Tags");
XYZ elboworigin = new XYZ(0.0, 0.0, 0.0);
try
{
try
{
elboworigin = uiApp.ActiveUIDocument.Selection.PickPoint("Pick the Elbow");
}
catch (Autodesk.Revit.Exceptions.InvalidOperationException icpointException)
{

}
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException excpt)
{

}
ElbowOriginY = elboworigin.Y;
ElbowOriginX = elboworigin.X;
ElbowOriginZ = elboworigin.Z;
rvtTransaction.Commit();
}

using (Transaction rvtTransaction = new Transaction(doc))
{
rvtTransaction.Start("Move Tags");
foreach (Reference ckt in refs)
{
IndependentTag tag = doc.GetElement(ckt.ElementId) as IndependentTag;
tag.LeaderEndCondition = LeaderEndCondition.Free;
XYZ baseValue2 = tag.GetLeaderEnd(tag.GetTaggedReferences().First());
double tagBaseX2 = baseValue2.X;
double tagBaseY2 = baseValue2.Y;

if (tag != null)
{
double A = (ElbowOriginY) - tagBaseY2;
double AngleXvalue = A / (60) + tagBaseX2;
XYZ ElbowPosition = new XYZ(AngleXvalue, ElbowOriginY, 0.000000000);
tag.SetLeaderElbow(tag.GetTaggedReferences().First(), ElbowPosition);

XYZ headerPnt = new XYZ(ElbowOriginX, ElbowOriginY, 0.000000000);
tag.TagHeadPosition = headerPnt;
}

}

rvtTransaction.Commit();
}


using (Transaction rvtTransaction2 = new Transaction(doc))
{
rvtTransaction2.Start("Move");

foreach (Reference ckt in refs)
{
IndependentTag tag = doc.GetElement(ckt.ElementId) as IndependentTag;
BoundingBoxXYZ tagBox = tag.get_BoundingBox(doc.ActiveView);
}

rvtTransaction2.Commit();
}

return Result.Succeeded;
}

 

 

0 Likes

Mohamed_Arshad
Advisor
Advisor

HI @praveen.cMXB2H 

 

       As you say code is running without errors at my end, And all tags are obtaining BoundingBox, I don't understand your problem still. And your code is also good.

Thanks & Regards,
Mohamed Arshad K
0 Likes