Remove Scope Box from View

I am trying to grab the boundary of a view (not a viewport) in order to find the center of the view.

This Python Script works to find the Revit.DB.Lines of a view’s crop but balks at views with Scope Boxes. I thought I might set the View’s Scope Box to None and then change it back when the definition is done but I can’t seem to figure how to set it to None since it’s technically not a type and doesn’t seem to have an ID. I could also modify the script if I knew where the problem lay.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

views = UnwrapElement(IN[0])

TransactionManager.Instance.EnsureInTransaction(doc)

for item in views:
    cLines = item.GetCropRegionShapeManager().GetCropRegionShape()

TransactionManager.Instance.TransactionTaskDone()
	
OUT = cLines

Also, how do I turn the Revit.DB.Lines into Dynamo geometry so I can work with them. Right now I’m converting them to Detail Lines and then pulling the curves off these. I figured I’d delete them later but that there’s got to be something I’m missing… probably pretty easy.

Hello Greg,
this code changes scope box to None:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

views = UnwrapElement(IN[0])

TransactionManager.Instance.EnsureInTransaction(doc)

eleID = ElementId(-1)
for item in views:
	scopeBox = item.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).Set(eleID) 
TransactionManager.Instance.TransactionTaskDone()
	
OUT = 0
4 Likes

Thanks for that. I assume I can use this as a base to reassign the correct Scope Box at the end by replacing the ElementId with the correct one from the project?

Yep, that’s right

1 Like

just a little addition here:

def tolist(obj1):
	if hasattr(obj1,'__iter__') : return obj1
	else : return [obj1]

this code wont work on a single view if you dont do this- tolist(IN[0]