Calling Navisworks with command line switches

Calling Navisworks with command line switches

JFN_KSH
Advocate Advocate
4,443 Views
14 Replies
Message 1 of 15

Calling Navisworks with command line switches

JFN_KSH
Advocate
Advocate

Hi, I would like to call the Navisworks software with command line switches. Basically, I would like to write a .NET "Windows service" to update the Navisworks model & apply a paint file. The command line switches are as per below.  I've tried with the .NET Process & ProcessstartInfo, but it seems to be unresponsive. Maybe I could call the command line switches using the Navisworks API? Any suggestion is appreciated, thanks.  

 

Roamer.exe -OpenFile <input.nwf> -ExecuteAddInPlugin AutoAppearanceLoader.Navisworks <appearance.dat> -SaveFile <out.nwd> -Exit

 

0 Likes
4,444 Views
14 Replies
Replies (14)
Message 2 of 15

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @JFN_KSH ,

 

Which version of NW are you using?

NW development team says AutoAppearanceLoader is 2023 onwards


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 15

JFN_KSH
Advocate
Advocate

Were using the 2023 version. Don't get me wrong, it works perfectly using the typical shortcut command line switch (& CMD). I'm trying to use the same command line switches from a .NET program. So far it doesn't work... Was hoping to get some feedback from this forum...

        Dim NavisPath As String = "C:\Program Files\Autodesk\Navisworks Manage 2023\Roamer.exe"
        Dim myStrBuilder As StringBuilder = New StringBuilder
        myStrBuilder.AppendFormat("{0} -OpenFile {1} -ExecuteAddInPlugin AutoAppearanceLoader.Navisworks {2} -ShowGui -SaveFile {3} -log {4} -Exit", NavisPath, myNwf, myDatFile, MyOutPutFileName, MylogFile)
        Dim ExitCode As Integer

        If File.Exists(NavisPath) = True Then
            'start the LSmon executable
            Dim proc = New Process With {
            .StartInfo = New ProcessStartInfo With {
                .FileName = NavisPath,
                .Arguments = myStrBuilder.ToString,
                .UseShellExecute = False,
                .RedirectStandardOutput = True,
                .CreateNoWindow = True
            }
            }
            proc.Start()
            proc.WaitForExit()
            ExitCode = proc.ExitCode

 

0 Likes
Message 4 of 15

JFN_KSH
Advocate
Advocate

Basically, Instead of my program calling the CMD.EXE, & then calling the Roamer.exe, I would like to call the "-ExecuteAddInPlugin AutoAppearanceLoader.Navisworks" command from an API call... If that's possible...?

0 Likes
Message 5 of 15

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @JFN_KSH ,

 

I am not able to understand your issue fully.

I need some more explanation.

I have a suggestion from the information you shared in your posts.From my understanding, You can try using Navisworks Automation API.

Did you take a look at Navisworks Automation API?

https://apidocs.co/apps/navisworks/2018/87317537-2911-4c08-b492-6496c82b3ed7.htm 

https://apidocs.co/apps/navisworks/2018/87317537-2911-4c08-b492-6496c82b3ee0.htm 

https://forums.autodesk.com/t5/navisworks-api/navisworks-manage-starting-automation-and-selecting/td... 

Using Navisworks Automation API, you can execute your addin plugin without any user interaction(even without opening Navisworks-I think NW runs in the Background)

1)Create a plugin. (let's call it plugin NWPlugin)
2)Create a console project.An .exe file will be created. (Let's call it example.exe)
3)Here is the sample code of the console project I used

class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            String runtimeName = Resolver.TryBindToRuntime(RuntimeNames.NavisworksManage);
            if (String.IsNullOrEmpty(runtimeName))
            {
                throw new Exception("Failed to bind to Navisworks runtime");
            }
            XMain();
        }

        private static void XMain()
        {
            NavisworksApplication navisapp = new NavisworksApplication();
            navisapp.AppendFile(@"...\inputFile.nwd");
            //Navisworks plugin you already created
            // [PluginAttribute("Navis2023", "ADSK", ToolTip = "Run 2023 code", DisplayName = "Navis 2023")]
            navisapp.ExecuteAddInPlugin("Navis2023.ADSK");            
            Console.WriteLine("Plugin Executed");
            navisapp.SaveFile(@"...\outputFile.nwd");
            navisapp.Dispose();
            Console.ReadKey();
        }
    }


4)In the sample code you will see I used NW application API. Append your file, execute your plugin(NWPlugin), and save your output file after executing the plugin.
5)You can execute example.exe directly from the command prompt.

If this doesn't help, I need some detailed explanation.

It will be helpful for me to check with the engineering team for you.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 6 of 15

JFN_KSH
Advocate
Advocate

Ok, That's very useful Naveen. I will take a closer look at the documentation... My question; Instead of creating a "Custom plugin" could I call the addInPlugin "AutoAppearanceLoader.Navisworks" ?

Something like this (The autoAppearance loader does exactly what we need (apply a paint file to the model, from a .DAT file))?

 

navisapp.ExecuteAddInPlugin("AutoAppearanceLoader.Navisworks");

  

0 Likes
Message 7 of 15

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @JFN_KSH ,

Sorry for the long delay in responding to your question.

Yes, it is possible to execute the "AppearanceLoader.Navisworks" command from an API call.

I did a quick test and it worked fine for me.

Here is the sample code I used

private static void XMain()
        {
            NavisworksApplication navisapp = new NavisworksApplication();
            navisapp.AppendFile(@"....\InputFile.nwc");
            navisapp.ExecuteAddInPlugin("AutoAppearanceLoader.Navisworks", @"...\DatFile.dat");
            navisapp.SaveFile(@".......\OutputFile.nwc");
            navisapp.Dispose();
            Console.ReadKey();
        }

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 8 of 15

JFN_KSH
Advocate
Advocate

I'm trying to load the automation .dll and test but I get a error:  System.IO.FileNotFoundException: 'Could not load file or assembly 'Autodesk.Navisworks.Automation, Version=20.0.1382.63. Any Idea?

0 Likes
Message 9 of 15

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @JFN_KSH ,

 

I am not able to recreate the problem on my end.

Did you load "Autodesk.Navisworks.Automation.dll" reference into your project?

It is difficult for us to understand what is causing the issue.

Could you please send me the non-confidential Visual Studio project file to test it at my end?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 10 of 15

JFN_KSH
Advocate
Advocate
Yes, I could send you my Visual Studio project (very basic)... How Should I proceed to send it to you?
0 Likes
Message 11 of 15

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @JFN_KSH ,

 

Please create a minimum non-confidential visual studio project to reproduce the issue and attach the files in your next response. (in your Next Navisworks API Forum post/response).

Don't send any information that to consider a trade secret to your company.

Just post the required sample files/sample codes in this forum post.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 12 of 15

JFN_KSH
Advocate
Advocate

OK, please find attach my Visual Studio project with the .NWF & .DAT file included. Thanks again for the help, much appreciated!

 Capture.JPG

0 Likes
Message 13 of 15

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @JFN_KSH ,

 

Hello,

I think I have figured out what the problem is in your code.
1)Open your project in Visual Studio
2)Go to solution explorer
3)Right click "Autodesk.Navisworks.Automation" and go to properties
4)Set copy local value as "true"
5)Right click "Autodesk.Navisworks.Resolver" and go to properties
6)Set copy local value as "false"

This should resolve the automation error message you are receiving.

Could you please try and let me know?

 

I am waiting for your response.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 14 of 15

silent_joe
Participant
Participant

I found the same problem. I did as  you said,but it still did not work.

0 Likes
Message 15 of 15

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @silent_joe ,

 

Could you please take a look at the below link?
https://adndevblog.typepad.com/aec/naveen-kumar/

We need a reproducible case to reproduce the problem at our end.
Without a reproducible case, it will be extremely difficult for us to understand what is happening on your end.

If you are doing this via Automation, I would suggest you first try using ExecuteAddInPlugin() method. If everything works fine as expected, then you try using Automation API.

To be honest, I checked with one of the senior Navisworks API experts from Autodesk. For both of us, the appearance profiler API works as expected.
if nothing helps, could you please create a short video explaining your issue and share it with us?
 Could you also please share a non-confidential visual studio sample project with us?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes