Creating Assemblies - Not working, no Errors though

I am trying to create assemblies and views. I got this script working last week with just the panels. This morning I tried adding panels and mullions and it doesn’t seem to be working but I’m not getting any errors. Can someone help me figure this out?
Here is a screenshot of the assmembly node


Here is a copy of the file if anyone wants to look at it.
create assemblies.dyn (95.5 KB)

I was also planning on using the python script from this thread to create the views. I tried the Tools node but was having issues with it. Has anyone had success creating views?
LINK

It is possible that the package works with IronPython2.7. In that case you need to download Dynamo Ironpython 2.7 package.

I also suggest you try to copy paste the package script to the main project. Python Script can show what is wrong.

I have IronPython installed and like I said the script worked on Friday when I running it with just the curtain panels.

I opened the node and see this error with the Python script:

Here is a screenshot showing line 25:

Here is another screenshot showing the inputs:

Oh, I missed this part.

I think it is trying to iterate over a list but the variable is not a list. At first it gets the list( all items in the List.FirstItem), then it tries to go deeper assuming each item(Mullion or Panel) has a list.

As suggestions:

  1. You can try to use List.Chop with amount 1 to make every item a list after the List.FirstItem.
  2. You can also try to update Python node corresponding line. Instead of assuming every arr has a list, it might be better to check arr variable is a list first. If not make it a list.
 #Check if 'arr' is actually a list or tuple, if not, make it a list
    if not isinstance(arr, (list, tuple)):
        arr = [arr]
  1. You can remove the last iteration and go like this:
for arr in element_array:
	#create a Revit-compatible list of IDs
	ids = list()
	ids.append(arr.Id)	
	idlist = List[ElementId](ids)
	assembly_list.append(AssemblyInstance.Create(doc, idlist, arr[0].Category.Id))
  1. You can use List.Create after the List.FirstItem to make a second level in your list.
1 Like

Did I edit it correctly?


I got this error:

If not, I did try running it after creating a list and it worked as expected. I’m testing the other python script I’m using that creates the views

It is almost correct:

In the second for loop we are going inside of arr variable list. So it should be like for elem in arr: ids.append(elem.Id)

Here is a full code:

import clr
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

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

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
element_array = UnwrapElement(IN[0])
assembly_names = IN[1]
assembly_list = list()

# create assemblies
TransactionManager.Instance.EnsureInTransaction(doc)
for arr in element_array:
    if not isinstance(arr, (list, tuple)):
        arr = [arr]
	# create a Revit-compatible list of IDs
	ids = list()
	for elem in arr:
		ids.append(elem.Id)	
	idlist = List[ElementId](ids)
	assembly_list.append(AssemblyInstance.Create(doc, idlist, arr[0].Category.Id))
TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()
# rename assembly types
i = 0
TransactionManager.Instance.EnsureInTransaction(doc)
for assinst in assembly_list:
	assinst.AssemblyTypeName = assembly_names[i]
	i += 1
TransactionManager.Instance.TransactionTaskDone()

OUT = assembly_list

I couldnt test it but i hope it works.

So I am running into an issue when trying to run all the curtain walls. The list organization seems to be the same a when I ran a single item.
All the items in the lists are panels and mullions and there are no other assemblies made with these.

Here is the error:

I’ve been testing different things and I keep this getting this error.

The list of elements lists is 94 long and the string list is 94 long. The list levels seems the same as when it worked running on one element.
What could be the issue?

The code you have is for individual element and it’ll work in that case but now you are feeding it a list so you need to put it in a for loop and it’ll work perfectly.

Regards,
BM

1 Like

That is what I would have guessed and actually went to look for the lacing options but that isn’t an option for a python node.

I’m not well versed with Python, how would I revise the script to have a for loop?

Thanks

You can try to make a custom node out of Python node and use lacing operations.

Is there a sample Revit model to run your script and work on it?

I’ve just been testing it in my project. If it doesn’t work I undo and try again. No luck so far. I guess changing the code to a for loop sounds easy, but maybe it’s not. I’ve learned enough about python to know what it can do, I just don’t know it well enough yet to take something like this and edit it. I’ll probably just create all the assemblies manually tomorrow unless something comes up between now and then

A sample project is very helpful.

  • It helps you keep the execution times to a manageable value.
  • It prevents worksharing issues when developing.
  • It ensures your project dataset.
  • It provides a simple reusable dataset for testing and troubleshooting in the next release of Revit.
  • It helps others help you as you can share it readily.

I get not wanting to do things twice, but in my experience things work out better with them.

I can understand all those benefits. I initially was testing it on just 1 element to save on time and then when I got that to work I thought I was good but then kept just plowing through without thinking.

Here is a sample file with 1 wall and 3 curtain walls and the dynamo script.

Model LINK It’s on Google Drive since it was too large to upload

Script LINK
create assemblies.dyn (123.7 KB)

1 Like

I’ll look at this tomorrow morning and will let you know what I come up with. My the looks of it you’ll need a way to ensure that a list of elements Tania provided and then force a for loop. :slight_smile:

Alternatively you could pack the Python into a custom node - lacing and list levels would work from there.

1 Like

Hi,

In regards to the view creation, here is a bit of the “cleaned-up” code.

The issue that I saw being created is when you feed the titleblock Id it doesn’t work in newer versions of Revit so you need to feed the Family Symbol Id.

Please give this a try and let me know.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument


element = UnwrapElement(IN[0])
elementId = element.Id

tb = UnwrapElement(IN[1]).Symbol.Id

viewlist=[]
schedlist=[]
sheetlist=[]
# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
views=[]
if IN[2]:
	v=AssemblyViewUtils.Create3DOrthographic(doc,elementId)
	views.append(v)
if IN[3]:	
	ds2=AssemblyViewUtils.CreateDetailSection(doc,elementId,AssemblyDetailViewOrientation.HorizontalDetail)
	views.append(ds2)
if IN[4]:	
	ds3=AssemblyViewUtils.CreateDetailSection(doc,elementId,AssemblyDetailViewOrientation.ElevationTop)
	views.append(ds3)
if IN[5]:	
	ds4=AssemblyViewUtils.CreateDetailSection(doc,elementId,AssemblyDetailViewOrientation.ElevationBottom)
	views.append(ds4)
if IN[6]:	
	ds5=AssemblyViewUtils.CreateDetailSection(doc,elementId,AssemblyDetailViewOrientation.ElevationLeft)
	views.append(ds5)
if IN[7]:	
	ds6=AssemblyViewUtils.CreateDetailSection(doc,elementId,AssemblyDetailViewOrientation.ElevationRight)
	views.append(ds6)
if IN[8]:	
	ds7=AssemblyViewUtils.CreateDetailSection(doc,elementId,AssemblyDetailViewOrientation.ElevationFront)
	views.append(ds7)
if IN[9]:	
	ds8=AssemblyViewUtils.CreateDetailSection(doc,elementId,AssemblyDetailViewOrientation.ElevationBack)
	views.append(ds8)
if IN[10]:	
	ds9=AssemblyViewUtils.CreatePartList(doc,elementId)
	views.append(ds9)
if IN[11]:	
	ds10=AssemblyViewUtils.CreateDetailSection(doc,elementId,AssemblyDetailViewOrientation.DetailSectionA)
	views.append(ds10)
if IN[12]:	
	ds11=AssemblyViewUtils.CreateDetailSection(doc,elementId,AssemblyDetailViewOrientation.DetailSectionB)
	views.append(ds11)
	
viewlist.append(views)
if IN[13]:
	sh = AssemblyViewUtils.CreateSheet(doc,elementId,tb)
for v in views:
	if Viewport.CanAddViewToSheet(doc,sh.Id,v.Id):
		Viewport.Create(doc,sh.Id,v.Id,XYZ(0,0,0))
	else:
		ScheduleSheetInstance.Create(doc,sh.Id,v.Id,XYZ(0,0,0))
sheetlist.append(sh)
doc.Regenerate()
# End Transaction
TransactionManager.Instance.TransactionTaskDone()

OUT=viewlist,sheetlist

Hope it helps. :slightly_smiling_face:

2 Likes

Can’t access the model as it’s behind a log-in and I don’t have a spare google account for this type of work. Can you open that up?

Thanks for the feedback, once I get the first python script running then I can test this update.