Hi all,
I have been attempting to export objects to Navisworks using python. The script runs without errors, but I am not seeing an exported .nwc at the specified location.
Files attached
Direct Shape Python test.dyn (14.5 KB)
DirectShape Python.rvt (388 KB)
Python 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
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('System')
from System.Collections.Generic import List
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
doc = DocumentManager.Instance.CurrentDBDocument
solid = IN[0]
category = UnwrapElement(IN[1])
solidList = []
solidIds = []
catId = category.Id
TransactionManager.Instance.EnsureInTransaction(doc)
for i in range(len(solid)):
ds = DirectShape.CreateElement(doc, catId)
ds.SetShape(solid[i].ToRevitType())
ds.Name = "This is the Name"
solidList.append(ds)
solidIds.append(ds.Id)
TransactionManager.Instance.ForceCloseTransaction()
fileLoc = "C:\Users\proberson\Desktop\dyn test"
fileName = "Test"
TransactionManager.Instance.EnsureInTransaction(doc)
navOp = NavisworksExportOptions()
col1 = List[ElementId](solidIds)
navOp.SetSelectedElementIds(col1)
navOp.ExportScope = navOp.ExportScope.SelectedElements
navOp.ExportRoomGeometry = False
doc.Export(fileLoc, fileName, navOp)
TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable.
OUT = solidIds
I figured this one out. I just moved the TransactionManager.Instance.EnsureInTransaction(doc) line to below the doc.Export line. I am not sure why this changed the outcome…any thoughts on that would be helpful. Hope this helps someone in the future.
There are a few additional lines in the code that are disassociated with solving this issue.
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
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('System')
from System.Collections.Generic import List
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
doc = DocumentManager.Instance.CurrentDBDocument
solid = IN[0]
category = UnwrapElement(IN[1])
names = IN[2]
catId = category.Id
dsId = []
TransactionManager.Instance.EnsureInTransaction(doc)
for i in range(len(solid)):
ds = DirectShape.CreateElement(doc, catId)
ds.SetShape(solid[i].ToRevitType())
ds.Name = names[i]
dsId.append(UnwrapElement(ds.Id))
TransactionManager.Instance.ForceCloseTransaction()
fileLoc = IN[3]
fileName = IN[4]
navOp = NavisworksExportOptions()
col1 = List[ElementId](dsId)
navOp.SetSelectedElementIds(col1)
navOp.ExportScope = navOp.ExportScope.SelectedElements
navOp.ExportRoomGeometry = False
doc.Export(fileLoc, fileName, navOp)
TransactionManager.Instance.EnsureInTransaction(doc)
TransactionManager.Instance.TransactionTaskDone()
doc.Regenerate()
TransactionManager.Instance.EnsureInTransaction(doc)
doc.Delete(col1)
TransactionManager.Instance.TransactionTaskDone()
doc.Regenerate()
#Assign your output to the OUT variable.
OUT = 0