Crop Region by curve

OK, try this file then: roomViews.dyn (4.5 KB)

(I think I have fixed the codeblock aswell)

1 Like

Yeah thx man it work :slight_smile:
can i controle the offset of boudary with this code

Try to set expandVal to something else than 0 or maybe
expandVal = IN[1] and add another port to the python node

Hi @Einar_Raknes

I am trying to modify this script to work with multiple views and multiple curves. I’ve spotted your comment that if this was wrapped in a custom node, this would be possible. I’ve been learning a bit of Python (mostly on a high level) not really dynamo specific. - but hopefully not too far off.

I’ve had a stab at modifying the python script to place everything within a for loop, but I can’t get it quite worked out. Could you give me a bit of advice, or if it would be easier wrapped in a custom node, what that would entail.

My fumblings are shown 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])
curves = IN[1]
curvelist =[]
viewlist = []

#Create curveloop
TransactionManager.Instance.EnsureInTransaction(doc)

for curve,view in curves, views:
	loop = CurveLoop()
	for c in curves:
		loop.Append(c)

#Set cropregion in Transaction

	view.CropBoxActive = True
	view.GetCropRegionShapeManager().SetCropRegionShape(loop)
	viewlist.append(view)
	TransactionManager.Instance.TransactionTaskDone()

OUT = view

I’m getting the error as shown …

this came out of the discussion Find Bounding Boxes of Multiple Scope Boxes

Cheers

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?