Not able to align tag elbow with given angle If the section cuts diagnolly.

Not able to align tag elbow with given angle If the section cuts diagnolly.

praveen.cMXB2H
Enthusiast Enthusiast
1,244 Views
15 Replies
Message 1 of 16

Not able to align tag elbow with given angle If the section cuts diagnolly.

praveen.cMXB2H
Enthusiast
Enthusiast

praveencMXB2H_0-1696310845731.png

 

This is my level plan. I can successfully align a tag on the floor or when sections are cut horizontally or vertically. However, when the section is cut diagonally, I encounter difficulty in aligning the tag at the desired angle.

 

praveencMXB2H_1-1696310959200.png

This is my code 

 

 

IndependentTag tag = doc.GetElement(ckt.ElementId) as IndependentTag;
if (tag != null)
{
tag.LeaderEndCondition = LeaderEndCondition.Free;
XYZ baseValue = tag.LeaderEnd;
double z2 = elboworigin.Z;
double x2 = 0;
double y2 = 0;
double x1 = baseValue.X;
double y1 = baseValue.Y;
double z1 = baseValue.Z;

double angleDegrees = 45.0;
double angleRadians = angleDegrees * Math.PI / 180.0;
double deltaZ = z2 - z1;
double tanTheta = Math.Tan(angleRadians);
double Lxy = deltaZ / tanTheta;
x2 = x1 + Lxy * Math.Cos(angleRadians);
y2 = y1 + Lxy * Math.Sin(angleRadians);
XYZ ElbowPosition = new XYZ(x2, y2, ElbowOriginZ);
tag.LeaderElbow = ElbowPosition;
XYZ headerPnt = new XYZ(elboworigin.X, ElbowOriginY, ElbowOriginZ);
tag.TagHeadPosition = headerPnt;

}

 

@jeremy_tammik

 

0 Likes
1,245 Views
15 Replies
Replies (15)
Message 2 of 16

jeremy_tammik
Alumni
Alumni

Dear Praveen, 

  

I sincerely hope that you pay more attention to your coding than to your spelling. Please spell check your posts, especially the descriptive title, in order to simplify searching and finding related issues later on.

  

Regarding your question: Please explain more precisely what exactly you wish to achieve. I cannot tell from you images or by reverse engineering your code.

  

Thank you!

  

Best regards

  

Jeremy

  

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

praveen.cMXB2H
Enthusiast
Enthusiast

Dear Jeremy,

 

I apologize for any inconvenience caused by my earlier oversight. It appears I neglected to check the spelling in my initial question, for which I take full responsibility.

 

To clarify, my question pertains to the alignment of tags at specific angles when dealing with sections that are cut diagonally. I have successfully aligned tags on flat surfaces as well as in cases where sections are cut either horizontally or vertically.

 

For a more concrete example, let's say I have a tag labeled 'elbow,' and I'd like to align it precisely at a 60-degree angle when the section is cut diagonally. What steps or methods should I follow to achieve this level of alignment?

 

In summary, my ultimate objective is to consistently align tags at predetermined angles, regardless of where the section is cut diagonally within the structure. Your guidance on accomplishing this would be greatly appreciated.

Thank you for your assistance.   

 

Best regards,

Praveen Kumar.

0 Likes
Message 4 of 16

jeremy_tammik
Alumni
Alumni

I see no problem with your task. Tags can be aligned at any desired angle. Please search this forum for existing issues, e.g., using terms such as "place tag angle":

  

  

I see a large number of solutions listed for various situations.

  

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

praveen.cMXB2H
Enthusiast
Enthusiast

I have already searched,  but unfortunately, I didn't find the solution I needed.

 

Please guide me;

 

I want to align this tag at the elbow with a 60-degree angle.

 

XYZ elboworigin = uiApp.ActiveUIDocument.Selection.PickPoint("Pick the Elbow");

IndependentTag tag = doc.GetElement(ckt.ElementId) as IndependentTag;
if (tag != null)
{
tag.LeaderEndCondition = LeaderEndCondition.Free;
XYZ baseValue = tag.LeaderEnd;
double z2 = elboworigin.Z;
double x2 = 0;
double y2 = 0;
double x1 = baseValue.X;
double y1 = baseValue.Y;
double z1 = baseValue.Z;

double angleDegrees = 60;
double angleRadians = angleDegrees * Math.PI / 180.0;

XYZ ElbowPosition = new XYZ(x2 = ?, y2 = ?, ElbowOriginZ);
tag.LeaderElbow = ElbowPosition;
XYZ headerPnt = new XYZ(elboworigin.X, ElbowOriginY, ElbowOriginZ);
tag.TagHeadPosition = headerPnt;

}

 

I would like to find the coordinates (x2, y2).

0 Likes
Message 6 of 16

jeremy_tammik
Alumni
Alumni

You wish to convert an angle to cartesian coordinates? You probably learned that in school when you were in your early teens:

  

  

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

praveen.cMXB2H
Enthusiast
Enthusiast
Dear Jeremy,

I am able to find coordinates, but they do not match a given angle for
diagonal sections.



Thanks and regards,
Praveen Kumar.
0 Likes
Message 8 of 16

praveen.cMXB2H
Enthusiast
Enthusiast

I am able to find coordinates, but they do not match a given angle for diagonal sections.

0 Likes
Message 9 of 16

jeremy_tammik
Alumni
Alumni

Aha. Thank you for clarifying. Can you make a sketch to illustrate and explain why they do not match? I do not see the problem off-hand. Thank you.

  

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

praveen.cMXB2H
Enthusiast
Enthusiast

praveencMXB2H_0-1696495426908.png

 

It appears that the elbow alignment in the code does not match the specified 60-degree angle; instead, it aligns with a 64-degree angle, and the angles vary for different sections. 

 

Code :

 

XYZ tagLocation = tag.LeaderElbow;
XYZ elementLocation = tag.LeaderEnd;
double x1 = elementLocation.X;
double y1 = elementLocation.Y;
double z1 = elementLocation.Z;
double z2 = elboworigin.Z;
double angleDegrees = 60.0;
// Convert the angle from degrees to radians
double angleRadians = angleDegrees * Math.PI / 180.0;
// Calculate the z-difference
double deltaZ = z2 - z1;
// Calculate the horizontal (xy-plane) distance Lxy
double tanTheta = Math.Tan(angleRadians);
double Lxy = deltaZ / tanTheta;
// Calculate the coordinates (x2, y2)
double x2 = x1 + Lxy * Math.Cos(angleRadians);
double y2 = y1 + Lxy * Math.Sin(angleRadians);

tag.LeaderElbow = new XYZ(x2 , y2, z2);
tag.TagHeadPosition = new XYZ(elboworigin.X, elboworigin.Y, elboworigin.Z);

 

 

0 Likes
Message 11 of 16

jeremy_tammik
Alumni
Alumni

Well, I still do not understand neither your task nor your problem in full detail. I am glad to see that it appears to be a purely trigonometric calculation, problem, though, and not a problem with the Revit API. One aspect that confuses me now is that I previously thought it was a purely 2D planar issue. Now I see a mention of a Z difference, and don't quite understand how the Z difference is supposed to affect the 2D angle calculation. Or is it actually a 3D angle calculation? 

  

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

praveen.cMXB2H
Enthusiast
Enthusiast

It is 3D angle calculation.

 

When working with floors, if sections are cut horizontally or vertically, it functions effectively within the context of a 2D representation. However, when sections are cut diagonally, it engages with the 3D aspect of the design.

0 Likes
Message 13 of 16

jeremy_tammik
Alumni
Alumni

Aha. Well, an angle in 3D space cannot be specified with one single number, such as 60 degrees. So, you will have to reformulate the problem in a suitable manner for a 3D angle before we can talk at all. Please work through some basic material about this topic before we continue, e.g.:

 

  

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

praveen.cMXB2H
Enthusiast
Enthusiast

Dear Jeremy,

 

I have reviewed all the provided links, but I am unable to find a suitable solution. If you could provide some sample code to help us match the angle, it would be greatly appreciated.

Thank you.

0 Likes
Message 15 of 16

jeremy_tammik
Alumni
Alumni

Dear Praveen,

  

Oh dear, I'm sorry to hear that. Really, you should be talking with a math teacher, not with me, and not here in the Revit API forum. I'll gladly try to help if I can. However, you have not yet described your problem or your task in a manner that I can understand. Remember, I am not a Revit user, so I do not know how to handle a tag or a section view optimally. All I know about are programming and geometry, e.g., in this case, cartesian coordinates and trigonometry. You stated above that you wish to orient something in 3D space at 60 degrees. Well, as said, that is insufficient information. Please specify sufficient information to define an exact 3D orientation. Read the articles I pointed out to learn what data might be used for that. Thank you.

   

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

praveen.cMXB2H
Enthusiast
Enthusiast

Dear Jeremy,

 

I have attached a video. Please watch it as I have explained my issue clearly.

 

@jeremy_tammik 

0 Likes