Export NWC with multiple View Template - Python code Error


#1

Hi all,

Got an error while trying to NWC export a view after applying multiple view template.
I got python Script which exports NWC. I added some codes to it to set view template before exporting every time.
It is setting the 1st view template, but shows error at line 41

Graph & Python script below…

import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import*

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

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager

import System
from System.Collections.Generic import *

#doc = DocumentManager.Instance.CurrentDBDocument

folder=IN[0]
name=IN[1]
Element=IN[2]
Parameter=IN[3]
Paravalue=IN[4]
#exportoptionbldr=IN[2]
options = NavisworksExportOptions()
options.ExportScope = NavisworksExportScope.View
options.ExportLinks = True
options.ExportRoomGeometry = False

#uiapp = DocumentManager.Instance.CurrentUIApplication
#app = uiapp.Application
#uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
#TransactionManager.Instance.EnsureInTransaction(doc)

if type(Paravalue) is list:
	Result=[]
	ind = 1
	for i in Paravalue:
		Result.append(Element.SetParameterByName(Parameter,i))
		c=doc.Export(folder,"Export-" + str(ind) + ".nwc", options)
		ind = ind + 1
else:
	Result.append(Element.SetParameterByName(Parameter,Paravalue))
	c=doc.Export(folder,"Export-" + name + ".nwc", options)


#TransactionManager.Instance.TransactionTaskDone()

OUT = Result

Sample project & dyn
(Get All View node form Archi-lab)

Please help.

Thanks in advance…


#2

Error snapshot below

Error-1


#3

I have a similar script.
Just before the line “doc.export…” I have a line that says
’options.ViewId = view.id

I don’t see where you are setting this in your code.
This is necessary when ExportScope is set to View.
http://www.revitapidocs.com/2016/afec98fb-dba1-2413-baa4-6889550d8087.htm


#4

Thanks ChainSmoker…

I added the view.id…but now the script exits silent…no error…But not exporting…Only setting the view template to view.

Changes done is adding the following…

view = UnwrapElement(IN[2])

options.ViewId = view.Id

import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import*

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

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager

import System
from System.Collections.Generic import *

#doc = DocumentManager.Instance.CurrentDBDocument

folder=IN[0]
name=IN[1]
Element=IN[2]
Parameter=IN[3]
Paravalue=IN[4]
view = UnwrapElement(IN[2])

#exportoptionbldr=IN[2]
options = NavisworksExportOptions()
options.ExportScope = NavisworksExportScope.View
options.ExportLinks = True
options.ExportRoomGeometry = False


#uiapp = DocumentManager.Instance.CurrentUIApplication
#app = uiapp.Application
#uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)

if type(Paravalue) is list:
	Result=[]
	ind = 1
	
	for i in Paravalue:
		Result.append(Element.SetParameterByName(Parameter,i))
		options.ViewId = view.Id
		c=doc.Export(folder,"Export-" + str(ind) + ".nwc", options)
		ind = ind + 1
else:
	Result.append(Element.SetParameterByName(Parameter,Paravalue))
	options.ViewId = view.Id
	c=doc.Export(folder,"Export-" + name + ".nwc", options)


TransactionManager.Instance.TransactionTaskDone()

OUT = Result

Exiting without no error warning is not nice…:grinning::grinning:

Any hints…?


#5

I suspect it’s because the variable ‘view’ that you created is an array even though you are only passing one view into it and you need some way to iterate through that array when obtaining the view id. I dunno, maybe I’m wrong.

for i in Paravalue:
Result.append(Element.SetParameterByName(Parameter,i))
for v in view:
options.ViewId = v.Id
c=doc.Export(folder,“Export-” + str(ind) + “.nwc”, options)
ind = ind + 1

To be honest I’m fairly new to the python side of dynamo.


#6

I am very new to Dynamo itself. Its only the 4th script. I thought this will be easy.

view was not a list at all. Interestingly the issue wasn’t with export side, it was with setting view template to 3D views.

So I did a different approach, after doing a lot of googling…But still result is same…Dynamo runs without error, but no export

But this time its bit more exceptions using this script … Multiple views => Apply multiple view templates => Export to NWC

New script…

    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

    viewtempname = IN[1]
    prefix = IN[2]
    folder = IN[3]
    views = []
    index = 1

    for i in IN[0]:
    	views.append(UnwrapElement(i))

    # Start Transaction
    TransactionManager.Instance.EnsureInTransaction(doc)

    collector = FilteredElementCollector(doc).OfClass(View3D)#change to View3D
   
for i in collector:
    	if i.IsTemplate == True:
    		for v in viewtempname:
    			if i.Name == v:
    				viewtemp = i
    				for c in views:
    					c.ViewTemplateId = viewtemp.Id
    					vname = prefix + c.Name + str(index)
    					nop = NavisworksExportOptions()
    					nop.ExportScope = NavisworksExportScope.View
    					nop.ViewId = c.Id
    					doc.Export(folder,vname,nop)
    					index = index + 1			
    	
    #for c, v in zip(viewelements,viewtemp):
    	#c.SetParameterByName(param, v)
    #for c, v in zip(views,viewtemp):
    #	c.ViewTemplateId = v.Id
    #	vname = prefix + c.Name + str(index)
    #	nop = NavisworksExportOptions()
    #	nop.ExportScope = NavisworksExportScope.View
    #	nop.ViewId = c.Id
    #	doc.Export(folder,vname,nop)
    #	index = index + 1
    	
    # End Transaction
    TransactionManager.Instance.TransactionTaskDone()

    OUT = views

Change View Template_6.dyn (31.7 KB)

Sample file is in the thread above.

No idea what the issue is…:exploding_head::exploding_head: