So I've been making some stuff with the Revit API for a little bit now and mostly understand what I'm doing based on examples I've seen or just trying stuff out. this has mostly worked out for me and I'm actually getting stuff done quite well but I've run into an issue with a plugin I'm making where i can't figure out how to do it. Hopefully, someone here can help me.
My plugin gets the structural concrete walls in a project and generates views
for them for formwork or rebar detailing, For this i need 3 plans, an elevation a section, and a floorplan. The elevation and section part works like a charm but im having issues with the floorplan.
I would like not to use a callout from a reference plan but rather a section to make the floor plan. Manually I can create this by placing a section vertically in my elevation and then rotating it 90 degrees so it looks up or down. how would I do this exact same step via the Revit API?
My current attempt looks like this where i get the rotation axis (Line) perpendicular to the wall with the GetrotationVector function which i then use to rotate the floorplanview.Location, this however throws a Nullrefrence exception "object is not set to an instance of an object"
BoundingBoxXYZ Perpendicular_sectionBox = GetSectionPerpendiculartToWall(wall);
BoundingBoxXYZ Parallel_sectionBox = GetSectionParallelToWall(wall);
Line rotation_Vector = GetrotationVector(wall);
// Create sections
Autodesk.Revit.DB.View parallelview = ViewSection.CreateSection(doc, vft.Id, Parallel_sectionBox);
Autodesk.Revit.DB.View perpendicularview = ViewSection.CreateSection(doc, vft.Id, Perpendicular_sectionBox);
Autodesk.Revit.DB.View floorplanview = ViewSection.CreateSection(doc, vft.Id, Perpendicular_sectionBox);
floorplanview.Location.Rotate(rotation_Vector, (Math.PI /180)*90 );
If anyone could show me how to achieve this that would be much appreciated!
Solved! Go to Solution.
Solved by sragan. Go to Solution.
This is probably a good place for you to start looking:
https://thebuildingcoder.typepad.com/blog/2017/02/moving-the-section-view-location.html
You have to get the section box and rotate that. Here is a C# macro that rotates a section called "MySection" as an example.
public void RotateSectionView()
{
// rotate the view section with the name "MySection":
string name = "MySection";
UIDocument uidoc = this.ActiveUIDocument;
Document doc = this.ActiveUIDocument.Document;
View activeView = doc.ActiveView;
// find the view named "MySection" with a filtered element collector:
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.WherePasses(new ElementCategoryFilter(BuiltInCategory.OST_Views));
var viewElements = from element in collector
where element.Name == name
select element;
// show error message if the view was not found
List<Autodesk.Revit.DB.Element> sectionViews = viewElements.ToList<Autodesk.Revit.DB.Element>();
if (sectionViews.Count == 0)
{
TaskDialog.Show("Message", "Cannot find the view name " + name + "\n The operation will be canceled.");
throw new Exception("Error - view not found");
}
// get the element id of the view section
ElementId sectionId = sectionViews[0].Id;
using (Transaction trans = new Transaction(doc, "rotate"))
{
trans.Start();
XYZ p1 = new XYZ(0,0,0);
XYZ p2 = new XYZ(1,0,0);
Line axis = Line.CreateBound(p1, p2);
// the lines below rotate the named view
collector = new FilteredElementCollector(doc).WherePasses(new ElementParameterFilter
(new FilterElementIdRule(new ParameterValueProvider(new ElementId(Convert.ToInt32(BuiltInParameter.ID_PARAM))),
new FilterNumericEquals(), sectionId)));
ElementId sectionboxId = collector.ToElementIds().Except(new List<ElementId>(new ElementId[] { sectionId })).FirstOrDefault();
ElementTransformUtils.RotateElement(doc, sectionboxId, axis, Math.PI/2);
uidoc.RefreshActiveView ();
//TaskDialog.Show("Revit","Rotated");
trans.Commit();
}
}
Normally, for rotating a section in a plan view, p2 would be (0,0,1) to give a rotation axis pointing in the Z direction (up out of the plan). To rotate in a elevation view, I used an elevation looking right, and then drew a vertical section looking left. Doing this, and setting p2 as (1,0,0) as shown rotates the section to look up. Rotating by 3*(Math.Pi/2) should rotate to look down.
You will probably have to do some additional work to find the right vector for every case, since you may be looking at different directions in different elevations.
You may also have to do some more work to set the center of rotation.
Thankyou!, I think this is prettymuch what i needed, ill try and implement it today and see if i can get it working
Thanks a ton, worked like a charm. still have to edit some stuff to get it to how i want but this helped me with the bigest problem, so thanks a lot!.😊
No idea what kind of magic you did to get the view sectionboxid, dont understand it currently but hopefully someday.
Yeah, the code to get the section ID was copied from somewhere, or provided by someone else, so I can't take credit for it, but glad it helped.
That probably goes for most of that code too.
Can't find what you're looking for? Ask the community or share your knowledge.