How to create a View without the Navisworks UI open (using the Command Line)

How to create a View without the Navisworks UI open (using the Command Line)

Tobias-san
Participant Participant
573 Views
5 Replies
Message 1 of 6

How to create a View without the Navisworks UI open (using the Command Line)

Tobias-san
Participant
Participant

Hi!

 

I am having an issue running my plugin through a command lineSpecifically, I cannot find a way to create a View object without the Navisworks GUI open.

 

Here's a brief summary of what I'm trying to do:

  • I have written a plugin that allows me to generate and save a list of viewpoints for a series of items all around the model. Each viewpoint zooms into the items and uses Box Sectioning to only show the relevant area.
  • For sectioning, I modify the ClippingPanes property of the document.ActiveView then I convert that View into a Viewport using view.CreateViewpointCopy() 

  • The plugin works perfectly when I run it from the Add-Ins tab in Navisworks.

  • My goal is to run this plugin through the command line so I can automate the process for many models.

 

Here's the actual problem:

 

  • When running the plugin through the command line using a .bat file, I get an issue when trying to section the viewpoint's View. Specifically: document.ActiveView is null (System.NullReferenceException). Evidently it's because the Navisworks GUI is not open during execution therefore there is no ActiveView. 

  • I cannot find a way to obtain or create a View object (not a Viewpoint object) without using document.ActiveView using the .NET API

 

Maybe there is a solution using the COM API? Or perhaps there is a way to obtain a View without using document.ActiveView? Or to apply Box Sectioning for a Viewpoint without using a View object? 

 

Any help is appreciated! Let me know if you need me to clarify anything.

Thanks in advance.

0 Likes
574 Views
5 Replies
Replies (5)
Message 2 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Tobias-san ,

 

The behavior you are experiencing is expected. If no UI is open, document.ActiveView will be null.

Here is my suggestion:

  1. Create viewpoints for each object by zooming into the items and using Box Sectioning to display only the relevant area, then add them to the saved viewpoints.
  2. Access each saved viewpoint.
  3. Use doc.Views instead of doc.ActiveView.
  4. Retrieve the view from doc.Views.
  5. Apply each viewpoint to the corresponding view.
  6. I accessed the clipping planes and exported the data as a .txt file.

    Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument;
    SavedViewpoint savedViewpoint = doc.SavedViewpoints.Value.Where(savedItem => !savedItem.IsGroup && savedItem.DisplayName.Contains("MyViewPointName")).First() as SavedViewpoint;               
    if(savedViewpoint!=null)
    {                   
        View myView = doc.Views[0];
        myView.CopyViewpointFrom(savedViewpoint.Viewpoint,ViewChange.Navigation);
        string output=myView.GetClippingPlanes();
        using(StreamWriter writer=new StreamWriter(@"C:\Users\FileName.txt"))
        {
            writer.WriteLine(output);
            writer.Close();
        } 
    }​

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 6

Tobias-san
Participant
Participant

Hi @naveen.kumar.t ,

 

Thanks for your answer! 

 

Unfortunately, doc.Views[0] will not work either.

The list is empty when running it through the command line. Therefore using doc.Views[0] gives me an Index out of Range exception.

 

(As a side note, I am aware that I could run the command using -ShowGui switch to open Navisworks during execution but I would like to avoid that if possible)

0 Likes
Message 4 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Tobias-san ,

Could you please share a simple, non-confidential sample file so I can analyze the issue on my end?

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 6

Tobias-san
Participant
Participant

Hi @naveen.kumar.t,

 

Here's a simplified example of what my code does. The two functions that I use are SetClippingPlanes() and CreateViewpointCopy(). Both require me to have a valid View object first. 

try {
    Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument;
    Autodesk.Navisworks.Api.View view;

    //Choose one here.
    view = doc.ActiveView;
    view = doc.Views[0];

    //Here I would modify the sectionning of the view using SetClippingPlanes()

    //Convert the view back to a viewpoint so I can save it.
    Viewpoint vp = view.CreateViewpointCopy();
    MessageBox.Show("Success!");
catch (Exception ex){
    MessageBox.Show(ex.ToString());
}

 

I build this function using an AddInPlugin. Then I use the following .bat file to execute it:

 

set navispath=(Your roamer.exe path here)
set inputfile=(Your input file here)
set outputfile=(Your output file here)

call %navispath% -ExecuteAddInPlugin "PluginName.PluginCode" -nwd %outputfile% %inputfile%

 

Let me know if you need anything else

0 Likes
Message 6 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Tobias-san ,

 

I escalated your issue to the Navisworks Engineering team for their input.

According to them, accessing Views without a GUI is unlikely, as Views are not explicitly created.

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes