Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Section Mark Angle

4 REPLIES 4
Reply
Message 1 of 5
johnjebasundar
562 Views, 4 Replies

Section Mark Angle

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?

4 REPLIES 4
Message 2 of 5
stever66
in reply to: johnjebasundar

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);
            
            
            
        }

 

Message 3 of 5
johnjebasundar
in reply to: stever66

Thank you stever66.

I will try your code

Message 4 of 5
Anonymous
in reply to: johnjebasundar

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

Message 5 of 5
johnjebasundar
in reply to: Anonymous

Great.
Thank you Pat.Hague

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community