Moving the Section View Location

Today, let's recap the Revit API discussion forum thread on moving the location of a section view raised by Danny Bentley, BIM Structural Technician at SOM in California, since Danny very kindly created a video and GitHub repo to demonstrate and share the solution, which will certainly be of use to others as well.

Danny Bentley

By the way, Danny also writes Bentley's Revit Dynamo & API blog on his personal exploration of the Revit API and Dynamo.

Why does it have a ch domain, Danny?

Anyway, here is the issue moving the location of a section view:

Question: I saw a great post on the The Building Coder on how to create a section view to be aligned with a wall.

I'm working on a project in which the wall angle will change and I need to rotate an existing section to match it.

Is it possible to set a curve similar to a wall? I can't seem to find any curve or location point on the section view in RevitLookup.

  LocationCurve locationCurve = wall.WallCurve;

  Transaction t = new Transaction( doc );
  t.Start( "Move Wall" );
  locationCurve.Curve = LinkedProfile;

Answer: Thank you for your query and appreciation.

First of all, out of habit, I repeat:

For your own comfort and security, all use of transactions should be encapsulated in a using statement.

The Building Coder defines an entire topic group on handling transactions and transaction groups.

I think you can indeed change the wall location curve in a manner similar to what you show.

However, the code you list above is guaranteed not to work.

Beginning of misunderstanding


In this line, you make a copy of the wall location curve:

  LocationCurve locationCurve = wall.WallCurve;

Then, you change something in the copy:

  locationCurve.Curve = LinkedProfile;

And then you expect the wall to change?

Good luck with that.

You might have better luck with

  wall.WallCurve = LinkedProfile;

You might also want to take a look at the ADN Xtra labs sample command Lab2_5_SelectAndMoveWallAndAddColumns.

It moves a wall using

  wall.Location.Move( v )

by a given vector v.

End of misunderstanding

Oh, no, re-reading your query, I see you are trying to modify the section view, not the wall location line.

No, the section view does not have a location line.

It is controlled differently. The Revit SDK sample DynamicModelUpdate shows how to dynamically update a section view to follow a window placed in the model. You can adapt that to follow a wall in a similar fashion.

Here is a quick rundown of the places to look in that sample step by step:

FamilyInstance window = doc.GetElement( m_windowId ) as FamilyInstance;

ViewSection section = doc.GetElement( m_sectionId ) as ViewSection;

RejustSectionView( doc, window, section );
internal void RejustSectionView( Document doc,
  Element elem, ViewSection section )

ElementTransformUtils.RotateElement(doc, m_sectionElement.Id,
  axis, rotateAngle);

ElementTransformUtils.MoveElement(doc, m_sectionElement.Id,

Response: Perfect! I forget the many awesome examples in the SDK. I really need to look through them instead of always using Google.

Answer: I think you need to use both SDK and Internet searches, and more besides, as described in how to research to find a Revit API solution.

Response: I just wanted to add my solution in case anyone else is looking to align section views and create aligned sections.

Here is a 30-second video on YouTube showing my add-in in action:

The source code is provided on GitHub, in dannysbentley Sections repo.

It sports four external commands:

It also creates a neat little external application presenting a custom ribbon panel to drive them.

Many thanks to Danny for sharing this solution!