Startup script and Navisworks

Startup script and Navisworks

l_malyshev
Explorer Explorer
353 Views
1 Reply
Message 1 of 2

Startup script and Navisworks

l_malyshev
Explorer
Explorer

Hello, I have a problem with Revit Python Shell.

When I open Revit 2024, run StartupScript, it contains a script that exports the model to NWC.
Using Export method.

In the process of StartupScript I get the following error.

picture.png

But if I open Revit 2024 first, and without StartupScript I run the same script through RevitPythonShell, then everything works fine.
If I run StartupScript example, with Revit 2021, I do not observe such an error.

The version of Navisworks Exporter that I use: is Autodesk_Navisworks_Exporters_2024_Win_64bit_dlm_R1
Revit version: 2024.2
Revit Python Shell version: 2.0.2

 

InitScript:
init.txt 
Paths for startup.py and init.py:

2024-01-31_22-32-28.png

c:\Users\%USERNAME%\AppData\Roaming\Autodesk\Revit\Addins\2024\RevitPythonShell\

 

startup.py:

# -*- coding: utf-8 -*-
# region -----------------------Library----------------------
import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit import DB
from Autodesk.Revit.DB import Document, NavisworksExportOptions, FilteredElementCollector, View3D, \
    NavisworksExportScope, NavisworksCoordinates
from Autodesk.Revit.DB import FilteredElementCollector as FEC

import os


uiapp = __revit__  # noqa
app = __revit__.Application  # noqa


def export(current_doc, navis_view, path_to, name):
    nw_ex_opt = NavisworksExportOptions()
    nw_ex_opt.ExportScope = NavisworksExportScope.View
    nw_ex_opt.ViewId = navis_view.Id
    nw_ex_opt.ExportRoomGeometry = False
    nw_ex_opt.Coordinates = NavisworksCoordinates.Shared
    nw_ex_opt.ExportLinks = False
    nw_ex_opt.ExportParts = True
    current_doc.Export(path_to, name, nw_ex_opt)
    current_doc.Close(False)
    return True


ws_config = DB.WorksetConfiguration(DB.WorksetConfigurationOption.OpenAllWorksets)
navis_options = DB.OpenOptions()
navis_options.Audit = True
navis_options.SetOpenWorksetsConfiguration(ws_config)

full_path = "D:/Revit 2024_Temp/Model.rvt"
new_location_path = DB.ModelPathUtils.ConvertUserVisiblePathToModelPath(full_path)

path_to = "D:/Revit 2024_Temp/NWC/Model"
ws_config = DB.WorksetConfiguration(DB.WorksetConfigurationOption.OpenAllWorksets)
navis_options = DB.OpenOptions()
navis_options.SetOpenWorksetsConfiguration(ws_config)

doc = app.OpenDocumentFile(new_location_path, navis_options)
views3d = [v for v in FilteredElementCollector(doc).OfClass(View3D) if not v.IsTemplate]
view_3d_navisworks = next((view for view in views3d if "Navisworks" == view.Name), None)
export(doc, view_3d_navisworks, path_to, "Model")

0 Likes
354 Views
1 Reply
Reply (1)
Message 2 of 2

studio-a-int
Advocate
Advocate

The error you get is because one of your views does not contain visible

3D Geometry (= suitable geometry) for Navisworks exporter.

 

You can create a method to filter for visible elements with suitable geometry

for each view you are exporting, and pass that while exporting.

If no suitable geometry, view will not be exported.

 

Or you can use a try/except condition, and catch all the views that

cannot be exported, write the list and then identify which views are empty.

Then open those views and make at least one object with geometry, visible.

Re-export, and you will not get the error.

 

In Python:

 

listEmptyViews = []

for view in view_3d_navisworks:

    try:

        # export view to Navis

    except Exception:

        listEmptyViews.append(view.Name)

        pass

 

And to write your views:

 

import os

fileLocation = r'C:\...'

fileName = 'EmptyViews'

with open(os.path.join(fileLocation, fileName) + '.txt', 'w') as f:

    for i in listEmptyViews:

        f.write(i + "\n")

f.close()

 

0 Likes