I’m attempting to write some Python code which modifies the crop region o f an elevation using the ViewCropRegionShapeManager Class.
I’ve set up Dynamo using the Select View node which passes the result to a Python script:
The script extracts the CropRegion (note its runs in Revit 2017), and returns a list of the 4 lines making up the crop:
# Dynamo import clr clr.AddReference('RevitAPI') clr.AddReference('RevitAPIUI') from Autodesk.Revit.DB import * from Autodesk.Revit.UI import * clr.AddReference('RevitAPI') import Autodesk from Autodesk.Revit.DB import * clr.AddReference('RevitAPIUI') from Autodesk.Revit.UI.Selection import * clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager from System.Collections.Generic import * doc = DocumentManager.Instance.CurrentDBDocument uiapp = DocumentManager.Instance.CurrentUIApplication app = uiapp.Application uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument #The inputs to this node will be stored as a list in the IN variables. dataEnteringNode = IN elefound = UnwrapElement(IN) # An element - should be an elevation #Get CropRegionShapeManager from elevation elecrsm = elefound.GetCropRegionShapeManager() #Get Crop Region shape crshape = elecrsm.GetCropShape() #Assign your output to the OUT variable. OUT = [crshape]
This gives the view boundary lines (in a list for some reason):
The problem I have is that I now want to extract the start and endpoint of the lines, but when I try to take one of the lines from the list I get an indexing error:
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 40, in
TypeError: ‘CurveLoop’ object is unsubscriptable
Am I missing something? I think the problem is that the list is an Ilist, not a list, but I see no reason why I cannot extract items from it?