I had one of those slap-your-head moments when this finally came to me … use Coins Auto Section Box!
Step by step:
- Close Revit
- Install Coins Auto Section Box
- Open Revit
- Open a project
- Draw a Scope Box
- Go to a 3D view where you want to match the Scope Box
- Select the Scope Box
- Go to Add-Ins > Auto Section Box
- Set Element extents, plus buffer: to 0
- 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:)
- Download the ZIP
- Unzip it
- Double click SetSectionBox.sln and open it in Visual C# Express (or use SharpDevelop, see below)
- Click on the Reference Paths side-tab
- Using the … add your Program FilesAutodeskRevit 2013Program directory
it is looking for RevitAPI.dll and RevitAPIUI.dll - Right-click on the SetSectionBox node and press build
- Find the setsectionboxsrcSetSectionBoxSetSectionBoxbinRelease folder, and copy the SetSectionBox.dll
- Paste it into %AppData%AutodeskRevitAddins2013
- 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 FilesAutodeskRevit 2013ProgramSDAbinSharpDevelop.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
empty
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< Elementldstd::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.
via
The Building Coder: Set View Section Box to Match Scope Box
great post Luke, works pretty well.
How is this better than the built in ability to orient your 3d to any other view?
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).
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… Read more »