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

Section Mark Angle

johnjebasundar
Participant

Section Mark Angle

johnjebasundar
Participant
Participant

Gentlmen,

I am new to Revit API. I want to align the existing section parallel to Duct.

I read Jeremy Tammik's "section view parallel to wall". But I couldn't understand the Transform.

 

All I want is to get the angle of the existing section. Once I get the angle, I will rotate with the duct rotation angle.

 

Can you please share the c# code to get the existing section angle?

0 Likes
Reply
684 Views
4 Replies
Replies (4)

stever66
Advisor
Advisor

The bounding box provides basic area that is visible in the view.  The transform seems to provide unit vectors that give the basic view directions.  So as the section view is rotated, the unit vectors will change.  Therefore, we just need a little math to figure out the angle.

 

I don't think this is 100% correct - you will probably have to refine it for all the quadrants the section rotation could be in. 

And I sure haven't tried it with a section drawn in anything but a plan view. 

 

But this seems to give the angle as a negative (CCW) rotation from the X axis (looking straight down) for rotations less than 90 degrees.  You have to be in the section view to run it.  YOu can edit it if you want to find the rotation of a selected section mark.  (I ran this as a macro:  You may have to edit to run as a External Command or Application).

 

public void SectionDirection()
        {
            //Get the current view
            UIDocument uidoc = ActiveUIDocument;
            Document doc = ActiveUIDocument.Document;
            Autodesk.Revit.DB.View pView = ActiveUIDocument.Document.ActiveView;
            string message = "";
            
            message += "\nView name : " + pView.Name;
            
            BoundingBoxXYZ boundingBox = pView.get_BoundingBox(pView);
            
            Transform trf = boundingBox.Transform;
            
            message += "\nX Transform : " + trf.BasisX;
            message += "\nY Transform : " + trf.BasisY;
            message += "\nZ Transform : " + trf.BasisZ;
                
            //use the Z transform to find the angle
             
             double myX= trf.BasisZ.X;
            double myY= trf.BasisZ.Y;
            double myAngle = Math.Atan (myX/myY);
            double myDeg = myAngle * 180/Math.PI;
            
            message += "\nZ Transform = Arctan(X/Y) : " + myDeg.ToString ();
            
            TaskDialog.Show("Revit", message);
            
            
            
        }

 

johnjebasundar
Participant
Participant

Thank you stever66.

I will try your code

0 Likes

Anonymous
Not applicable

I understand everyone is here to learn and debug their code. But I wanted to point you to an existing plugin in the app store that I think is already doing what you are trying to achieve. I recently discovered this myself, and it is quite handy. 

Section View Aligner

johnjebasundar
Participant
Participant
Great.
Thank you Pat.Hague
0 Likes