Project location and Export to NWC

Hi All ,
So what I need to do is change the project location and export to Navisworks for 150 files.
I am taking this in two steps ,

  1. create a scrip that changes the Project location and exports the file to NWC.
  2. automate the script to run on 150 files in a folder.

Step 1
I have two scripts , One changes the Project location the other exports the model to NWC, both scripts work fine when run Separately, but when I combine the scripts (as seen in the image below) to change the project location and export to NWC it doesn’t export to NWC.
I’m not sure what I am doing wrong, any help is much appreciated.

The python Code in the Change Location is :

import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import*
clr.AddReference(‘RevitServices’)
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

pls = FilteredElementCollector(doc).OfClass(ProjectLocation).ToElements()
TransactionManager.Instance.EnsureInTransaction(doc)
for pl in pls:
if pl.Name == IN[0]:
doc.ActiveProjectLocation = pl
break
else:
continue
TransactionManager.Instance.TransactionTaskDone()

OUT = doc.ActiveProjectLocation

the python code to export is :
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]

collector = FilteredElementCollector(doc).OfClass(View)
options = NavisworksExportOptions()
options.ExportScope = NavisworksExportScope.View

for view in collector:
if (view.ViewType == ViewType.ThreeD and view.Name.Contains("Navisworks")):
options.ViewId = view.Id
doc.Export(folder, "Export-" + view.Name + ".nwc", options)

OUT = "Success"

1 Like

Try to add a code block between the directory path and the 3D view navisworks on name node which consists of the following (Dynamo 2.x format):

[DirectoryPath, OutFromSiteLocation][0];

Wire the directory path and output from the site location node into the codeblock as normal, and then wire the code block into the navisworks exporter.

Jacob,
Thanks for the responce,
Is the below what you mean ?
Ive tried the the below image and it is still not exporting the Navisworks view.

I cant upload the scrip because i’m a new user , the below is a we transfer link to the script
https://we.tl/t-U9eDcqCck7

I guess that Jacob’s strategy is that the view creation Waits for the change site location before executing.

If that’s not working, maybe try End Transaction, to force the issue a bit more strongly? (There is also a Start)

Hope that helps,

Mark

2 Likes

Thanks Guys ,

The Transaction End & Transaction Start worked perfectly.

Next step is to try get dynamo to open and run this script on 150 Revit files, any suggestions on where to start ?

Hi,

You can use the Export NWC in Document node of Genius Loci package designed for that purpose.

2 Likes