- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi guys!
I have hard times rotating views in Revit 2019.
I've got assemblies in my project that are faced to different directions (N,S,E,W. We can assume, that absolute values of ( X , Y ) are either (0,1) or (1,0) )
With single transaction I create multiple sheets with views on them. I try to rotate the view using the subtransaction (it might be the issue).
Initial call:
using (transaction)
{
List<ViewSheet> sheets = new List<ViewSheet>();
transaction.Start();
Utility.Sheets.CreateSheets(Document, elementId, 9, out sheets);
//Creating sheets and views
//sheet 1
Utility.Sheets.Create3DSheet(Document, elementId, sheets[0]);
//sheet 2
Utility.Sheets.CreateCasingDrawing(Document, elementId, sheets[1]);
//sheet 3
Document.Regenerate();
transaction.Commit();
transaction.Start();
for (int i = 0; i < sheets.Count; i++)
{
Utility.Sheets.SetSheetParameters(Document, elementId, sheets[i], i+1);
}
transaction.Commit();
}
code snippet from Utility.Sheets.CreateCasingDrawing
ViewSection vsFront2 = AssemblyViewUtils.CreateDetailSection(document, id, orientations[0], viewFront, isAssigned: true);
ViewSection vsUp2 = AssemblyViewUtils.CreateDetailSection(document, id, AssemblyDetailViewOrientation.HorizontalDetail, viewSection, isAssigned: true);
ViewSection vsLeft2 = AssemblyViewUtils.CreateDetailSection(document, id, orientations[2], viewSection, isAssigned: true);
ViewSchedule matSched2 = AssemblyViewUtils.CreateSingleCategorySchedule(document, id, scheduleCategoryId: schedTypeElement.Category.Id, schedule, isAssigned: true);
Viewport.Create(document, sheet.Id, vsFront2.Id, new XYZ(-0.75459, 0.63812, -0.241));
Viewport.Create(document, sheet.Id, vsUp2.Id, new XYZ(-0.75459, 0.259682048822124, -0.351351502340035));
Utility.Sheets.RotateHorizontalView(document, vsUp2, orientations[0]);
Viewport.Create(document, sheet.Id, vsLeft2.Id, new XYZ(-0.108762048822124, 0.634839160104988, -0.225465616797901));
Utility.Sheets.RotateHorizontalView is supposed to do the trick by analyzing the assembly orientation and rotating the Plan view accordingly.
So far, I've tried 3 solutions:
1. Directly setting the Cropbox.Transform properties. Ain't working, just like the docs state. (Why do they have public setter though?)
2. https://thebuildingcoder.typepad.com/blog/2013/09/rotating-a-plan-view.html Seems like the thing I'm looking for, except there's no Cropbox Element in Revit 2019. Throws a NullReferenceException, as expected
3. I've modified the 2nd solution and now I'm trying to rotate the OST_Viewer. It executes, though the result is completely different from what I expect.
Here're code samples with the results:
Var 1:
SubTransaction rotation = new SubTransaction(document);
Transform transform = view.CropBox.Transform;
rotation.Start();
view.CropBoxActive = true;
rotation.Commit();
rotation.Start();
if (orientation == AssemblyDetailViewOrientation.ElevationLeft)
{
transform.BasisX = new XYZ(0, -1, 0);
transform.BasisY = new XYZ(1, 0, 0);
}
if (orientation == AssemblyDetailViewOrientation.ElevationRight)
{
transform.BasisX = new XYZ(0, 1, 0);
transform.BasisY = new XYZ(1, 0, 0);
}
if (orientation == AssemblyDetailViewOrientation.ElevationBack)
{
transform.BasisX = new XYZ(-1, 0, 0);
transform.BasisY = new XYZ(0, -1, 0);
}
rotation.Commit();
rotation.Start();
view.CropBoxActive = false;
rotation.Commit();
Result:
(the front view is ok, the cropbox has been activated and not deactivated)
Var3:
SubTransaction rotation = new SubTransaction(document);
//Var 3
Element cropBoxElement = new FilteredElementCollector(document, view.Id).OfCategory(BuiltInCategory.OST_Viewers).FirstElement();
XYZ top = view.CropBox.Max;
XYZ bottom = view.CropBox.Min;
XYZ center = 0.5 * (bottom + top);
XYZ centerPlus = new XYZ(center.X, center.Y, center.Z + 1);
Line axis = Line.CreateBound(center, centerPlus);
rotation.Start();
if (orientation == AssemblyDetailViewOrientation.ElevationLeft)
{
angle = System.Math.PI / 2;
}
if (orientation == AssemblyDetailViewOrientation.ElevationRight)
{
angle = 3 * System.Math.PI / 2;
}
if (orientation == AssemblyDetailViewOrientation.ElevationBack)
{
angle = System.Math.PI;
}
ElementTransformUtils.RotateElement(document, cropBoxElement.Id, axis, angle);
rotation.Commit();
Result:
(Instead of the plan, the front view has been transformed)
What am I doing wrong? What might be the issue?
I'm clearly making a mistake, I cannot see.
Thanks in advance!
Solved! Go to Solution.