How to create assembly schedule

Hello!
I’m trying to create script which would create sheet, views and schedule for an assembly.
As a start I picked Tool.AssemblyViews from SteamNodes and successfully managed to add view template and view name functionality. Currently I’m trying to add part of code where I can create schedule (via CreateSingleCategorySchedule Method (Document, ElementId, ElementId, ElementId, Boolean)). I know that my schedule will always be “structural rebar” category, but I have no idea how to feed it to parameter. I was trying to feed it from input but I don’t think this is a good way (and doesn’t work for me). Also can I put a function in a parameter (viewTemplateRebarSchedule.Id)? Thanks in advance for all help. As you can see I’m a beginer at Python in Dynamo.

#python nodes in dynamo 1.0
#proposed by Julien Benoit @jbenoit44 
#http://aecuandme.wordpress.com/
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

elt = []
for i in IN[0]:
	elt.append(UnwrapElement(i).Id)
	
tb=UnwrapElement(IN[4]).Id
	
catid=doc.GetElement(elt[0]).Category.Id

viewTemplateHorizontalDetail = [t for t in FilteredElementCollector(doc).OfClass(View).ToElements() if t.IsTemplate and t.Name == "EPO_PAL_DETAL_1-10"][0]
viewTemplateDetailSectionA = [t for t in FilteredElementCollector(doc).OfClass(View).ToElements() if t.IsTemplate and t.Name == "EPO_PAL_DETAL_1-50"][0]
viewTemplateRebarSchedule = [t for t in FilteredElementCollector(doc).OfClass(View).ToElements() if t.IsTemplate and t.Name == "EPO_PAL_ZESTAWIENIE_ZBR"][0]
	
collection=List[ElementId](elt)
viewlist=[]
schedlist=[]
sheetlist=[]
view_ports=[]
# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for a in elt:
	views=[]
	if IN[1] == 1:	
		ds2=AssemblyViewUtils.CreateDetailSection(doc,a,AssemblyDetailViewOrientation.HorizontalDetail)
		ds2.ViewTemplateId = viewTemplateHorizontalDetail.Id
		ds2.Name = "Przekrój A-A"
		views.append(ds2)
	if IN[2] == 1:	
		ds10=AssemblyViewUtils.CreateDetailSection(doc,a,AssemblyDetailViewOrientation.DetailSectionA)
		ds10.ViewTemplateId = viewTemplateDetailSectionA.Id
		ds10.Name = "Widok"
		views.append(ds10)
	if IN[5] == 1:
		ds11=AssemblyViewUtils.CreateSingleCategorySchedule(doc,a,IN[5],viewTemplateRebarSchedule.Id,True)
		views.append(ds11)
	viewlist.append(views)
	if IN[3] == 1:
		sh=AssemblyViewUtils.CreateSheet(doc,a,tb)
		for v in views:
			if Viewport.CanAddViewToSheet(doc,sh.Id,v.Id) == 1:
				viewport = Viewport.Create(doc,sh.Id,v.Id,XYZ(0,0,0))
				view_ports.append(viewport)
			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,view_ports
1 Like

Do you have any updates on this topic?

Hey! You can find something usefull in this code (which is mainly based on SteamNodes). I made some changes to fit in my script.

#based on Tool.AssemblyViews z paczki SteamNodes
#changes made by Tomasz Gruszkowski 09.2022
#python nodes in dynamo 1.0
#proposed by Julien Benoit @jbenoit44 
#http://aecuandme.wordpress.com/
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import Point as PGPoint
# 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

elt = []
for i in IN[0]:
	elt.append(UnwrapElement(i).Id)
	
tb=UnwrapElement(IN[4]).Id
	
catid=doc.GetElement(elt[0]).Category.Id

viewTemplateHorizontalDetail = [t for t in FilteredElementCollector(doc).OfClass(View).ToElements() if t.IsTemplate and t.Name == "PAL_DETAL_1-10"][0]
viewTemplateDetailSectionA = [t for t in FilteredElementCollector(doc).OfClass(View).ToElements() if t.IsTemplate and t.Name == "PAL_DETAL_1-50"][0]
viewTemplateRebarSchedule = [t for t in FilteredElementCollector(doc).OfClass(View).ToElements() if t.IsTemplate and t.Name == "PAL_ZESTAWIENIE_ZBR"][0]
viewTemplateRebarSummary = [t for t in FilteredElementCollector(doc).OfClass(View).ToElements() if t.IsTemplate and t.Name == "PAL_PODSUMOWANIE_ZBR"][0]
	
collection=List[ElementId](elt)
viewlist=[]
schedlist=[]
sheetlist=[]
view_ports=[]
schedule_sheet_instance=[]
# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for a in elt:
	views=[]
	if IN[1] == 1:	
		ds1=AssemblyViewUtils.CreateDetailSection(doc,a,AssemblyDetailViewOrientation.HorizontalDetail)
		ds1.ViewTemplateId = viewTemplateHorizontalDetail.Id
		ds1.Name = "Przekrój A-A"
		views.append(ds1)
	if IN[2] == 1:	
		ds2=AssemblyViewUtils.CreateDetailSection(doc,a,AssemblyDetailViewOrientation.DetailSectionA)
		ds2.ViewTemplateId = viewTemplateDetailSectionA.Id
		ds2.Name = "Zbrojenie pala wierconego " + IN[6]
		views.append(ds2)
	if IN[5] == 1:
		ds3=AssemblyViewUtils.CreateSingleCategorySchedule(doc,a,ElementId(BuiltInCategory.OST_Rebar),viewTemplateRebarSchedule.Id,True)
		ds3.Name = "Zestawienie zbrojenia dla jednego pala"
		views.append(ds3)
		ds4=AssemblyViewUtils.CreateSingleCategorySchedule(doc,a,ElementId(BuiltInCategory.OST_Rebar),viewTemplateRebarSummary.Id,True)
		ds4.Name = "Podsumowanie zbrojenia"
		views.append(ds4)
		
	viewlist.append(views)
	if IN[3] == 1:
		sh=AssemblyViewUtils.CreateSheet(doc,a,tb)
		sh.Name = "Zbrojenie pala " + IN[6]
		#point1 = PGPoint.ByCoordinates(35,100,0)
		viewport1 = Viewport.Create(doc,sh.Id,views[0].Id,XYZ(0,0,0))
		view_ports.append(viewport1)
		viewport2 = Viewport.Create(doc,sh.Id,views[1].Id,XYZ(0,0,0))
		view_ports.append(viewport2)
		schedule1 = ScheduleSheetInstance.Create(doc,sh.Id,views[2].Id,XYZ(0,0,0))
		schedule_sheet_instance.append(schedule1)
		schedule2 = ScheduleSheetInstance.Create(doc,sh.Id,views[3].Id,XYZ(0,0,0))
		schedule_sheet_instance.append(schedule2)
		sheetlist.append(sh)
doc.Regenerate()
# End Transaction
TransactionManager.Instance.TransactionTaskDone()

OUT=viewlist,sheetlist,view_ports,schedule_sheet_instance
1 Like