The Building Coder

Flipping a Section View and Forge Webinar 3

I already created a starting point for the new roomedit3d incarnation last week, in its own repository roomedit3dv3.

However, please forget that right away.

This week, I agreed with Philippe to retain the new project in an own dedicated roomedit3d branch within his original Forge boilerplate code sample collection.

Hopefully, that will simplify keeping my BIM sample synchronised with any future updates make to that.

Now I need to get started implementing and testing the actual viewer extension functionality itself.

My main topic today is something different and purely Revit API oriented, besides the next Forge session:

Flipping a Section View

Here is a recent interesting little case handled by Jim Jia and answered by Paolo Serra:

Question: I want to create a new model with a section view based on an existing one with the same cross-sectional view but a different crop box.

To do so, I perform, these steps:

  1. Open the old model file, find the required cross-sectional view.

  2. Create a new model within the same bounding box, using the old model view CropBox created like this:

  Transform transform = view.CropBox.Transform;
  BoundingBoxXYZ box = new BoundingBoxXYZ();
  box.Enabled = true;
  XYZ maxPoint = view.CropBox.Max;
  XYZ minPoint = view.CropBox.Min;
  box.Transform = transform;
  box.Max = maxPoint;
  box.Min = minPoint;
  ViewSection viewSection = ViewSection.CreateSection( 
    doc, view.GetTypeId(), box );

This works and I can create a cross-sectional view through this method, but in the opposite direction of the existing view, like this:

Section view flipped

How can I flip the view direction to solve this problem?

Answer: A few days ago I was trying to do the same.

What worked for me was to reverse the RightDirection vector of the original view and recreate a transform to apply to the BoundingBoxXYZ.

You should also take into consideration the different transforms you might have in the two documents.

  Transform tr = view.CropBox.Transform;

  tr.BasisX = -view.RightDirection;
  tr.BasisY = XYZ.BasisZ;
  tr.BasisZ = tr.BasisX.CrossProduct( tr.BasisY );

  BoundingBoxXYZ bb = new BoundingBoxXYZ();
  bb.Transform = tr;
  XYZ min = view.CropBox.Min;
  XYZ max = view.CropBox.Max;
  bb.Min = new XYZ( min.X, min.Y, 0 );
  bb.Max = new XYZ( max.X, max.Y, -min.Z );

  ElementId vftId = new FilteredElementCollector( doc )
    .OfClass( typeofViewFamilyType ) )
    .WhereElementIsElementType()
    .Cast<ViewFamilyType>()
    .First( x => x.ViewFamily == ViewFamily.Section )
    .Id;

  View newView = ViewSection.CreateSection( doc, vftId, bb );

Response: Thanks a lot, it works!

Many thanks to Jim and Paolo for sharing this!

Forge Webinar Series

Tomorrow we are presenting the third session in the ongoing Forge webinar series, on the Model Derivative API.

Support documentation and recordings from the first two sessions for your future reference and enjoyment:

Upcoming sessions continuing during the remainder of the Autodesk App Store Forge and Fusion 360 Hackathon until the end of October:

Forge – build the future of making things together