RTV Tools

Wednesday, September 5, 2012

Matching a 3D view Section Box to a Scope Box

I had one of those slap-your-head moments when this finally came to me ... use Coins Auto Section Box!

Step by step:
  1. Close Revit
  2. Install Coins Auto Section Box
  3. Open Revit
  4. Open a project
  5. Draw a Scope Box
  6. Go to a 3D view where you want to match the Scope Box
  7. Select the Scope Box
  8. Go to Add-Ins > Auto Section Box
  9. Set Element extents, plus buffer: to 0
  10. Hit OK!
The 3D view now has a Section Box that matches the selected Scope Box.

I previously tried to implement some sample code from The Building Code, but couldn't make it work (see below the lines).  I'm sure this is due to my less-than-optimal API skills...

How to compile code SLN for Revit (using Building Coder as example:)
  1. Download the ZIP
  2. Unzip it
  3. Double click SetSectionBox.sln and open it in Visual C# Express (or use SharpDevelop, see below)
  4. Click on the Reference Paths side-tab
  5. Using the ... add your \Program Files\Autodesk\Revit 2013\Program directory
    it is looking for RevitAPI.dll and RevitAPIUI.dll
  6. Right-click on the SetSectionBox node and press build
  7. Find the setsectionbox\src\SetSectionBox\SetSectionBox\bin\Release folder, and copy the SetSectionBox.dll
  8. Paste it into %AppData%\Autodesk\Revit\Addins\2013
  9. If it isn't already there, paste SetSectionBox.addin into the same folder.
Revit 2013 ships with the open source IDE SharpDevelop.

If you want to use SharpDevelop:
"yourdrive:\Program Files\Autodesk\Revit 2013\Program\SDA\bin\SharpDevelop.exe"

Just drag and drop the solution file into the SharpDevelop window.

Running the command, I get a couple of different errors.  One is:
Revit encountered a Autodesk.Revit.Exceptions.ArgumentException: Box is
Parameter name: box
at Autodesk. Revit.DB.View3D.set_SectionBox(BoundingBoxXYZ section Box)
at SetSectionBox.Command.Execute(ExternaiCommandData
commandData, String& message, ElementSet elements)
at apiManagedExecuteCommand(AString* assemblyName, AString*
className, AString* vendorDescription, MFCApp* pMFCApp, DBView*
pDBView, AString* message,
Set< Elementld\std::less \tnallc< Elementld> > • ids,
Map \tnallc > * data, AString*
exceptionName, AString* exceptionMessage)

Here is SetSectionBox.zip containing the complete source code, Visual Studio solution, and add-in manifest of this command. 
The Building Coder: Set View Section Box to Match Scope Box


  1. great post Luke, works pretty well.

  2. How is this better than the built in ability to orient your 3d to any other view?

    1. I guess your idea works if there is a Scope Box applied to the source view. My post was about applying the extents of a Scope Box (the 3D box, usually green lines) to a Section Box (the cropping extents of a specific 3D view).

  3. I know this is an old post but I thought I'd mention that there was in fact a bug in the code presented in the original post on the building coder blog. It wasn't your 'less-than-optimal API skills' after all! I had trouble getting that solution to work too until I realized the mistake in it.

    Basically, the max bounds of the bounding box created from the scope box need to be specified in the coordinate space of the bounding box rather than in world coordinate space. Taking the length of each vector obtained from the dimensions of the scope box to form an XYZ value for the bounding box maximum yields the desired result.