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?
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);
}
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.
Can't find what you're looking for? Ask the community or share your knowledge.