Export NWC By Python

dears;
i am trying to export nwc from Revit by below Script, i have problem that the Navisworks export Dialogue just popup without any export progress.


Please post an actual code. I doubt anyone wants to re-type your code just so they can debug it for you.

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 *

import System

import math

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

coll = FilteredElementCollector(doc).OfClass(ProjectLocation)

output = []
path = IN[0]
name = IN[1]

TransactionManager.Instance.EnsureInTransaction(doc)
activeView = uidoc.ActiveView.Id 
scope = Autodesk.Revit.DB.NavisworksExportScope().View
Options = Autodesk.Revit.DB.NavisworksExportOptions()



doc.Export(path,name,Options)

TransactionManager.Instance.TransactionTaskDone()

doc.Regenerate()
OptionalFunctionalityUtils.IsNavisworksExporterAvailable()
#OUT = dir(Autodesk.Revit.DB.NavisworksExportOptions.ExportScope)
OUT = Autodesk.Revit.DB.NavisworksExportOptions().ViewId

i figure it out:

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 *

import System

import math

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

coll = FilteredElementCollector(doc).OfClass(ProjectLocation)

output = []
path = IN[0]
name = IN[1]
#path = Autodesk.Revit.DB.FilePath(pathName)
Options = Autodesk.Revit.DB.NavisworksExportOptions()
Options.ExportScope = NavisworksExportScope.View
Options.ViewId = uidoc.ActiveView.Id
doc.Export(path,name , Options)
TransactionManager.Instance.EnsureInTransaction(doc)



TransactionManager.Instance.TransactionTaskDone()
doc.Regenerate()
#OUT = dir(Autodesk.Revit.DB.NavisworksExportOptions.ExportScope)
OUT = 0
1 Like

Hey guys,

I hope I’m not reviving an old post with something unrelated. I think it should be very related, in case you think it’s not I’ll open a new thread.

I’m trying to modify the script above in order to be able to export not just the Active View, but a list of views I input.
This is one of my very first attempts with Python so I’m not really sure of where the mistake is.

This is the Dynamo graph:

And this is the script I’m using (modified from the script above)
> 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 *

> import System

> import math

> doc = DocumentManager.Instance.CurrentDBDocument
> uiapp = DocumentManager.Instance.CurrentUIApplication
> app = uiapp.Application
> uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

> coll = FilteredElementCollector(doc).OfClass(ProjectLocation)

> output = []
> #views = [UnwrapElement(IN[0])]
> views = (UnwrapElement(IN[0]))
> path = IN[1]
> name = IN[2]
> #path = Autodesk.Revit.DB.FilePath(pathName)
> OUT = views
> for i in views:
> 	Options = Autodesk.Revit.DB.NavisworksExportOptions()
> 	Options.ExportScope = NavisworksExportScope.View
> 	Options.ViewId = i.Id
> 	#Expects ElementId (above)
> 	Options.ExportLinks = True
> 	doc.Export(path, name + i.Name , Options)
> 	TransactionManager.Instance.EnsureInTransaction(doc)



> TransactionManager.Instance.TransactionTaskDone()
> doc.Regenerate()
> #OUT = dir(Autodesk.Revit.DB.NavisworksExportOptions.ExportScope)
> #OUT = 0

I think now the script is getting the list on views in the input but I’m still creating one file, now called “try1+the name of the view”

How do I make it create 1 file for each view in the input?

Thanks a lot!

Hello just making you aware that NWC exports are or should use 3D views…i will post code later but is this your intention? Also its best to create a new topic and link this topic coz this was already tagged solved by the OP.

Did you ever figure this code out? Im looking to be able to Input a certain view name and export it. Can you help?

Try this as an alternative…

Just follow and try…

I tried that and its not quite what im looking for. I have a script that will create a section box at each level and create a new 3d view. I just want to be able to choose certain views to export without having to rename them.

Ok no probs i will create one with selected views input tomorrow and will post on the above topic and NOT to this one coz this is already mark as solved by the OP.

I started a form on it. Sorry if this was done and is repetitive.

Ok will reply to both topic then…unless others beat me to it til tomorrow…

1 Like

By the way…i am not trying to change the way you do things…but in future having “navis” or “navisworks” on your view name will be recommended (the ones you want to export to nwc) Also if you have made so far creating views with their names via dynamo adding “navis” on the name is not going to be hard? Or does it?

Til tomorrow

1 Like

Your right it wouldn’t be hard but i get alot of files with pre-made viewpoints from coworkers and if i could just select the view instead of renaming it and then running the script that would be ideal.

1 Like

Hi everyone! I Want to know if someone knows how can I solve this problem that appears every time that I try to export a 3D from revit to a nwc file.

1 Like