I'm testing a "static" method to assign a scope box to an
existing 3D view via a Python node in Dynamo.
I want the SectionBox to start right at a Level and stop at the Level above.
The problem I encounter is that in order to get the Min/Max of the Box at the Level.Elevation, I need
subtract from that a value of 14.5.
Not sure where the issue is.
Below the code I generated and the test Revit file.
Thanks for your help.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI', 'RevitAPIUI', 'System', 'ProtoGeometry', 'RevitServices', 'RevitNodes')
import Revit
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import Family
import Autodesk
from Autodesk.Revit.UI import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, ElementId, ScheduleDefinition
from System.Collections.Generic import List
clr.ImportExtensions(Revit.Elements)
import System
from System.Collections.Generic import *
from System import Guid
# DEFINE CURRENT/ACTIVE DOCUMENT
doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
#get ViewFamilyType for a 3D View
VIEW_3D_FAMILY_TYPE = [i for i in FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements() if i.ViewFamily == ViewFamily.ThreeDimensional][0]
LEVELS = [i for i in FilteredElementCollector(doc).OfClass(Level).ToElements()]
# SELECT MY ISOMETRIC VIEW
MY_3D_VIEW_1 = [i for i in FilteredElementCollector(doc).OfClass(View3D).ToElements() if i.IsTemplate is False and i.IsPerspective is False and i.Name == 'MY_3D_1'][0]
# SELECT LEVELS
LEVEL_1 = [i for i in FilteredElementCollector(doc).OfClass(Level).ToElements() if i.Name == 'Level 1'][0]
LEVEL_2 = [i for i in FilteredElementCollector(doc).OfClass(Level).ToElements() if i.Name == 'Level 2'][0]
# START TRANSACTION TO SET SECTION BOX
t2 = Transaction(doc, 'SET SECTION BOX FOR 3D VIEW')
t2.Start()
sectionBox = app.Create.NewBoundingBoxXYZ()
MY_3D_VIEW_1.IsSectionBoxActive = True
sectionBox = MY_3D_VIEW_1.GetSectionBox()
sectionBox.Min = XYZ(-100, -100, LEVEL_1.Elevation-14.5)
sectionBox.Max = XYZ(100, 100, LEVEL_2.Elevation-14.5)
MY_3D_VIEW_1.SetSectionBox(sectionBox)
bx = MY_3D_VIEW_1.GetSectionBox()
doc.Regenerate()
t2.Commit()
OUT = bx
Solved! Go to Solution.
Solved by zhong_wu. Go to Solution.
In short, the problem of magic number 14.5 is the Z axis offset of the SectionBox from origin in the 3D View.
The SectionBox you got from View3D has an offset which you can check from View3D.GetSectionBox().Transform.Origin, when you change the Min & Max value of Z axis to level.Elevation, you have to subtract the offset. I am not so familiar with Dynamo, so I tried in .NET plugin, here is the main code to fix the problem for your reference, the code should be pretty straightforward to self-explain:
View3D view = doc.ActiveView as View3D; BoundingBoxXYZ box = view.GetSectionBox(); XYZ bbOffset = box.Transform.Origin; box.Min = new XYZ(box.Min.X, box.Min.Y, level1.Elevation-bbOffset.Z); box.Max = new XYZ(box.Max.X, box.Max.Y, level2.Elevation-bbOffset.Z); view.SetSectionBox(box);
And I got the right result as I expected:
Glad it helps.
Btw, to make the code be accurate. I suggest you to use the Level.ProjectElevation instead of Level.Elevation, because Level.ProjectElevation is relative to project origin, the value should be correct, while Level.Elevation may not. Please check the details at http://www.revitapidocs.com/2018.1/b5d48a18-4aa9-7457-7a6a-6d4966eaf77f.htm
Can't find what you're looking for? Ask the community or share your knowledge.