Crop Region by curve

It all seems so simple when you read it, until you come write it!

Maybe you can try to follow this example:

CRACKED IT ! My first successfully working Python API node.

I have modified the code and it working! @Einar_Raknes

I was walking home and had a light bulb-esque moment.

I transposed the graph, to produce a combined list with both the view and curve per item, then iterated through the originl script per item.

I was thinking this method could apply to any definition which will work only once, but for which you want to iterate multiple times.

Anyway enough chat, hereā€™s the codeā€¦

import clr

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

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

#prepare input
combinedlist = IN[0]
outputlist = []

for i in combinedlist:
	view = UnwrapElement(i[0])
	curves = i[1]


	#Create curveloop
	loop = CurveLoop()
	for c in curves:
		loop.Append(c.ToRevitType())

	#Set cropregion in Transaction
	TransactionManager.Instance.EnsureInTransaction(doc)
	view.CropBoxActive = True
	view.GetCropRegionShapeManager().SetCropShape(loop)
outputlist.append(view)
TransactionManager.Instance.TransactionTaskDone()


OUT = outputlist

However it hasnā€™t solved the main problem. I am struggling to place views on sheets, i was trying to find n alternate way to crop the views to see if they would pack onto the sheets, but alas I have the same error.

I have noticed this has also been recently commented on in the following thread.

Previously i had the same error, it seemed the view was too large for the sheet. However now, even the numbers are smaller so iā€™m a bit confused ā€¦

Nice that you got it to work!

If you wanted to combine the lists in python you could have used zip()

for view,curves in zip(views,curvelist):

	#Create curveloop
	loop = CurveLoop()
	for c in curves:
		loop.Append(c.ToRevitType())

	#Set cropregion in Transaction
	TransactionManager.Instance.EnsureInTransaction(doc)
	view.CropBoxActive = True
	view.GetCropRegionShapeManager().SetCropShape(loop)
outputlist.append(view)
TransactionManager.Instance.TransactionTaskDone()


OUT = outputlist

Thanks jup,

Was looking for thisā€¦ just needed to TAB outputlist.append(view) into the loop

No worries - well I had parked this - been busy since. Iā€™ll check it out though.

Mutually beneficial it would appear :slight_smile:

Hi everyone,
Iā€™m jumping in the conversation about the combine list that I canā€™t figure it out how to make it work.

@jup : Iā€™m looking at your modification about combine list.
If Iā€™m getting this right, your python as only [0] as entry ?
I tried your python and get this error
" File ā€œā€, line 30, in
TypeError: iteration over non-sequence of type FloorPlanView"
(my input in [0] is my list of some dependant view)

@Einar_Raknes at first i used your python code from your dynamo definition and it works great but I still have to select the view one by one.
I tried the zip() - had to rename ā€œcurvelistā€ to ā€œcurvesā€ and ā€œviewsā€ to ā€œviewā€ and then I get the error :
" File ā€œā€, line 34, in
NameError: name ā€˜outputlistā€™ is not defined"
Line 34 is the ā€œoutputlist.append(view)ā€

What am I missing there ?

Maybe you have forgotten to define the list?

outputlist = []

THANK YOU !
It works like a charm !

Hey Einar
i try to use the node for multiples views , but i have an error message as shown in capture below

import clr

clr.AddReference(ā€˜RevitNodesā€™)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

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

#prepare input
views = UnwrapElement(IN[0])
curvelist = IN[1]
outputlist =

for view,curves in zip(views,curvelist):

#Create curveloop
loop = CurveLoop()
for c in curves:
	loop.Append(c.ToRevitType())

#Set cropregion in Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
view.CropBoxActive = True
view.GetCropRegionShapeManager().SetCropShape(loop)

outputlist.append(view)
TransactionManager.Instance.TransactionTaskDone()

OUT = outputlist

Hi,

If I want to make this script with Areas instead of rooms ā€¦ that will help me

@Mohamed.Elmasri can you try and see what happens if you replace OST_Rooms with OST_Areas in the code? And if you have any further questions, please start a new thread since this one is old and already solved

Dear Kukul,
I was looking for Script doing same work you sent as a flash. Could you please help.

Thanks.

@kvusal
Please read the forum guidelines to check if you introduced your request appropriately:

Please send also a screenshot of what you tried so far in your initial thread:

Thanks :slight_smile:

Thanx for sharing your knowledge and your script. I used your script but got a warning that the FloorPlanView object is unscriptable. Do I have to edit the script somehow or do I have to change the Input views?

There could be some first clues to be found through the search field:
https://forum.dynamobim.com/search?q=object%20is%20unsubscriptable
See also if the answers already given in this thread can not help, for instance:

Thought the creator of the script would like know the issues, and Yes I searched this thread. Because I did not found the answer, I posted the issue.
Actually I used the View.SetCropBoxCurver from the MEPover package:

hello Kulkul,

what is in the the phyton script you use?

I wood like to copy a crop view in Revit and it seems like You do the with this script in dynamo. And i am curious how You doing that?

kind regards,


i am trying to run the script but.its now working.
and got the error as shown in screenshot.

can any one suggest the change in script