Let drafting views through View.SetCropBoxCurves, python help

Hi, anyone know how to adjust this code to let drafting views through the node even though they don’t have a crop region? Would be super helpful in my sheet duplicate with view script. Otherwise I need to extract the drafting views and feed them back into the list in the correct place around this node somehow.

Code from MEpover @T_Pover

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

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

import clr
clr.AddReference("RevitNodes")
import Revit

clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

#The inputs to this node will be stored as a list in the IN variables.
if isinstance(IN[0], list):
	views = UnwrapElement(IN[0])
else:
	views = [UnwrapElement(IN[0])]
if isinstance(IN[1], list):
	if IN[1][0].GetType() == PolyCurve:
		curves = [PolyCurve.Curves(x) for x in IN[1]]
	elif IN[1][0].GetType() == Curve or IN[1][0].GetType() == Line:
		curves = List.OfRepeatedItem(IN[1],len(views))
	else:
		curves = IN[1]
else:
	if IN[1].GetType() == PolyCurve:
		curves = [PolyCurve.Curves(IN[1])]
	else:
		curves = [IN[1]]
	
listout = []
for view,curve in zip(views,curves):
	regionMan = view.GetCropRegionShapeManager()
	revit_curve = [c.ToRevitType() for c in curve]
	curveloop = Autodesk.Revit.DB.CurveLoop()
	for c in revit_curve:
		curveloop.Append(c)
	TransactionManager.Instance.EnsureInTransaction(doc)
	if view.CropBoxActive == False:
		view.CropBoxActive = True
		view.CropBoxVisible = True
	regionMan.SetCropShape(curveloop)
	TransactionManager.Instance.TransactionTaskDone()
	listout.append(view)


#Assign your output to the OUT variable.
OUT = listout

This ought to do it:

for view,curve in zip(views,curves):
if view.GetType() == Autodesk.Revit.DB.ViewDrafting:
	listout.append(view)
	continue
regionMan = view.GetCropRegionShapeManager()

Awesome, thanks man. I’ve tried a few times but unfortunately I don’t know where to put it in the code haha. Could you assist please? I thought this may have been it

listout = []
for view,curve in zip(views,curves):
if view.GetType() == Autodesk.Revit.DB.ViewDrafting:
	listout.append(view)
	continue
regionMan = view.GetCropRegionShapeManager()
	revit_curve = [c.ToRevitType() for c in curve]
	curveloop = Autodesk.Revit.DB.CurveLoop()
	for c in revit_curve:

Not sure if the list structure and the new code might throw it out

image

or should it be Draftingview not viewDrafting? I’m not really sure but wana help haha

Looks like you haven’t got the indentation right. Here’s the complete code:

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

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

import clr
clr.AddReference("RevitNodes")
import Revit

clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

#The inputs to this node will be stored as a list in the IN variables.
if isinstance(IN[0], list):
	views = UnwrapElement(IN[0])
else:
	views = [UnwrapElement(IN[0])]
if isinstance(IN[1], list):
	if IN[1][0].GetType() == PolyCurve:
		curves = [PolyCurve.Curves(x) for x in IN[1]]
	elif IN[1][0].GetType() == Curve or IN[1][0].GetType() == Line:
		curves = List.OfRepeatedItem(IN[1],len(views))
	else:
		curves = IN[1]
else:
	if IN[1].GetType() == PolyCurve:
		curves = [PolyCurve.Curves(IN[1])]
	else:
		curves = [IN[1]]
	
listout = []
for view,curve in zip(views,curves):
	if view.GetType() == Autodesk.Revit.DB.ViewDrafting:
		listout.append(view)
		continue
	regionMan = view.GetCropRegionShapeManager()
	revit_curve = [c.ToRevitType() for c in curve]
	curveloop = Autodesk.Revit.DB.CurveLoop()
	for c in revit_curve:
		curveloop.Append(c)
	TransactionManager.Instance.EnsureInTransaction(doc)
	if view.CropBoxActive == False:
		view.CropBoxActive = True
		view.CropBoxVisible = True
	regionMan.SetCropShape(curveloop)
	TransactionManager.Instance.TransactionTaskDone()
	listout.append(view)


#Assign your output to the OUT variable.
OUT = listout

Thanks man. I thought indentation was purely for the users structure to follow. Good to know.

Gave it a test but unfortunately it didn’t pass it through. I might be missing something.

Hmm, might have something to do with how the custom nodes handles it. Have you tried it with a simple flat list? That seems to work for me when using a python node.

I can, but I really need the list structure for sheet placement down the track