Crop Region by curve

revit
#15

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

0 Likes

#16

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

0 Likes

#17

Maybe you can try to follow this example:

0 Likes

#18

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
0 Likes

#19

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 …

0 Likes

#20

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
0 Likes

Python Nodes Basics
#21

Thanks jup,

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

0 Likes

#22

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

Mutually beneficial it would appear :slight_smile:

0 Likes

#23

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 ?

0 Likes

#24

Maybe you have forgotten to define the list?

outputlist = []

0 Likes

#25

THANK YOU !
It works like a charm !

0 Likes

#26

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

0 Likes

#27

Hi,

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

0 Likes

#28

@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

0 Likes

#29

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

Thanks.

0 Likes

#30

@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:

0 Likes

#31

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?

0 Likes

#32

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:

0 Likes

#33

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:

0 Likes

#34

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,

0 Likes