# Navisworks Export through Python

**URL:** <https://forum.dynamobim.com/t/navisworks-export-through-python/14894>\
**Category:** Developers\
**Created:** [September 18, 2017, 4:37pm UTC](https://forum.dynamobim.com/t/navisworks-export-through-python/14894 "2017-09-18T16:37:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre\_Roberson](https://avatars.discourse-cdn.com/v4/letter/p/e36b37/32.png) [@Pierre\_Roberson](https://forum.dynamobim.com/u/Pierre_Roberson)\
**Post date:** [September 18, 2017, 4:37pm UTC](https://forum.dynamobim.com/t/navisworks-export-through-python/14894/1 "2017-09-18T16:37:22Z")

</div>

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](https://forum.dynamobim.com/uploads/short-url/k5Lphh7iCmB5nNbOsWAj8EMBy01.dyn) (14.5 KB)  
[DirectShape Python.rvt](https://forum.dynamobim.com/uploads/short-url/tfgCYiE5In76PAKJ5jTmXfVBm0H.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
```

---

<div class="post-metadata">

**Author:** ![Pierre\_Roberson](https://avatars.discourse-cdn.com/v4/letter/p/e36b37/32.png) [@Pierre\_Roberson](https://forum.dynamobim.com/u/Pierre_Roberson)\
**Post date:** [September 18, 2017, 9:40pm UTC](https://forum.dynamobim.com/t/navisworks-export-through-python/14894/2 "2017-09-18T21:40:58Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![koclukasz](https://avatars.discourse-cdn.com/v4/letter/k/dbc845/32.png) [@koclukasz](https://forum.dynamobim.com/u/koclukasz)\
**Post date:** [September 7, 2023, 12:19pm UTC](https://forum.dynamobim.com/t/navisworks-export-through-python/14894/3 "2023-09-07T12:19:27Z")

</div>

Do you know any way to export NWC from Multiple Sites existing in revit?  
I change this in a loop and then try to export NWC, sites changes but no export file is done.

> import clr  
> clr.AddReference(‘RevitNodes’)  
> import Revit  
> clr.ImportExtensions(Revit.Elements)  
> clr.ImportExtensions(Revit.GeometryConversion)
> 
> clr.AddReference(‘ProtoGeometry’)  
> from Autodesk.DesignScript.Geometry import \*
> 
> clr.AddReference(“RevitAPI”)  
> import Autodesk.Revit.DB as db
> 
> clr.AddReference(“RevitServices”)  
> from RevitServices.Transactions import TransactionManager  
> from RevitServices.Persistence import DocumentManager
> 
> doc = DocumentManager.Instance.CurrentDBDocument  
> allLoc = doc.ProjectLocations
> 
> allLocNumber = allLoc.Size  
> enum = allLoc.GetEnumerator()  
> enum.MoveNext()  
> sol = enum.Current  
> folderpath = IN[0]
> 
> viewEx = UnwrapElement(IN[1])
> 
> def ProcessParallelLists(\_func, \*lists):  
> return map( lambda \*xs: ProcessParallelLists(\_func, \*xs) if all(type(x) is list for x in xs) else \_func(\*xs), \*lists )
> 
> allLocations = [sol]
> 
> for loc in range(allLocNumber)[:10]:  
> enum.MoveNext()  
> sol = enum.Current  
> allLocations.append(sol)
> 
> options = db.NavisworksExportOptions()  
> options.ViewId=viewEx.Id  
> #All,Elements, or None  
> #options.NavisworksParameters = Enumeration  
> options.ExportScope = db.NavisworksExportScope.View  
> options.ExportLinks=False  
> options.Coordinates= db.NavisworksCoordinates.Shared  
> options.ExportParts = False  
> options.ExportElementIds = True  
> options.ConvertElementProperties = True  
> options.ExportRoomAsAttribute = True  
> options.ExportRoomGeometry = False  
> options.ExportUrls = True  
> options.DivideFileIntoLevels = False  
> options.FindMissingMaterials = True
> 
> def moveAndExport(loc):  
> TransactionManager.Instance.EnsureInTransaction(doc)  
> fileName = doc.Title + “\_” + loc.Name  
> doc.ActiveProjectLocation = loc  
> doc.Regenerate()  
> TransactionManager.Instance.TransactionTaskDone()  
> result = doc.Export(folderpath, fileName, options)  
> return fileName
> 
> ProcessParallelLists(moveAndExport, allLocations)  
> OUT = [x.Name for x in allLocations]
