Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sort Navisworks Model Tree through CommandLine

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
KRISHNAN_SESHADRI7V4SS
1181 Views, 17 Replies

Sort Navisworks Model Tree through CommandLine

Sort Navisworks Model Tree through CommandLine

 

We export RVM files from other software and want to merge all those rvm files together and then SORT them alphabetically and publish them as nwd format for Navisworks Freedom.

Sorting works fine from the menus Scene->Sort, whereas we like to do in a batch script using the commandline functions.

 

Found an API on Navisworks Community and made few changes to the suit latest .net Framework.(4.7)

 

  1. Old code is under message 2 of 13 of the below link.

https://forums.autodesk.com/t5/navisworks-api/autodesk-navisworks-api-application-activedocument-mod...

 

  1. My .NET code is

using System;

using System.Collections.Generic;

using System.Linq;

using ComBridge = Autodesk.Navisworks.Api.ComApi.ComApiBridge;

using Autodesk.Navisworks.Api.Plugins;

using Autodesk.Navisworks.Api;

 

namespace NavisSortTreeMembers

{

    [PluginAttribute("NavisSortTreeMembers", "TEST", DisplayName = "NavisSortTreeMembers")]

    public class Class1:AddInPlugin

    {

        public override int Execute(params string[] parameters)

        {

            Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

 

            try

            {

                //sorting the names of the models            

                IEnumerable<Model> oNewSortedModels = oDoc.Models.OrderBy(per => per.RootItem.DisplayName);

                List<string> fileArray = new List<string>();

                foreach (Model oEachModel in oNewSortedModels)

                {

                    fileArray.Add(oEachModel.FileName);

                }

 

                //delete all files.

 

                foreach (Model oEachModel in oDoc.Models)

                {

                    // State.DeleteSelectedFiles failed to delete

                    // all files at one time.

                    // so have to delete them one by one.

                    ModelItemCollection oMC = new ModelItemCollection();

                    oMC.Add(oEachModel.RootItem);

                    oDoc.CurrentSelection.CopyFrom(oMC);

                    ComBridge.State.DeleteSelectedFiles();

                }

 

                //append them again with the new order

                oDoc.AppendFiles(fileArray);

            }

            catch (Exception ex)

            {

 

            }

 

            return 0;

        }

    }

 

}

 

 

  1. I have compiled and copied the dll file to the installation folder.

C:\Program Files\Autodesk\Navisworks Manage 2022\Plugins

 

 

  1. Any sample RVM file which got some elements is good to test.

 

  1. My command in powershell is

& 'C:\Program Files\Autodesk\Navisworks Manage 2022\Roamer.exe' -log "C:\MyData\temp\NW_log.txt" -OpenFile "C:\MyData\temp\a.rvm" -ExecuteAddInPlugin ("NavisSortTreeMembers.TEST")  -NoGui -Exit

 

  1. While executing the above code, it opens the Navisworks Manage but then we get an error message as “The Plugin was not found”

 

 

17 REPLIES 17
Message 2 of 18

Hi @KRISHNAN_SESHADRI7V4SS ,

 

The "The Plugin was not found" error occurs when parentheses are erroneously used with the "-ExecuteAddInPlugin" command. To resolve this issue, refrain from including "(" and ")" when utilizing the command. 

 

Old : 'C:\Program Files\Autodesk\Navisworks Manage 2022\Roamer.exe' -log "C:\MyData\temp\NW_log.txt" -OpenFile "C:\MyData\temp\a.rvm" -ExecuteAddInPlugin ("NavisSortTreeMembers.TEST")  -NoGui -Exit

 

New : 'C:\Program Files\Autodesk\Navisworks Manage 2022\Roamer.exe' -log "C:\MyData\temp\NW_log.txt" -OpenFile "C:\MyData\temp\a.rvm" -ExecuteAddInPlugin "NavisSortTreeMembers.TEST"  -NoGui -Exit


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 18

Hi, I tried your new command but it also gave the same error, "The PLugin was not found".

So tried this, 

& 'C:\Program Files\Autodesk\Navisworks Manage 2022\Roamer.exe' -log "C:\MyData\temp\NW_log.txt" -OpenFile "C:\MyData\temp\a.rvm" -AddPluginAssembly "C:\Program Files\Autodesk\Navisworks Manage 2022\Plugins\NavisSortTreeMembers.dll" -ExecuteAddInPlugin "NavisSortTreeMembers.KRIS"  -NoGui -Exit
 
Which did not throw any error, where as i do not see any sorting on the rvm file or the rvm file is untouched.
Could it be any errors on my API?
 
Please clarify and thanks in advance.
Please find the log file attached herewith and it shows some error.
 
LcUSysError::PostFixed: LcUMemory: "11936 arena bytes still allocated at LcUMemory::Terminate. Not terminating."
*** Component LcUSysError still initialised
*** Component LcUSysMemory still initialised
LcOwApplication::Terminate ErrorTerminate
Message 4 of 18

Hi @KRISHNAN_SESHADRI7V4SS ,

 

Could you please send me a non-confidential sample RVM file for testing?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 5 of 18

hi

 

Please find the sample. rvm zipped and attached herewith.

 

The Selection Tree hierarchy under /ZONE-PIPING-AREA03, is sorted in desending order which i am trying to sort using the API code. FYI

 

Message 6 of 18

Hi,

 

I attempted to utilize the code provided below.

namespace Navisworks_2024
{   
    [PluginAttribute("Navisworks2024","ADSK",ToolTip = "NW-2024",DisplayName = "My Plugin")]     
    public class Class1 : AddInPlugin
    {
        public override int Execute(params string[] parameters)
        {
            
            Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;
            try
            {
                string commandId = "RoamerGUI_EDIT_SORT";
                Autodesk.Navisworks.Api.Interop.LcUCIPExecutionContext av = Autodesk.Navisworks.Api.Interop.LcUCIPExecutionContext.eTOOLBAR;
                try
                {
                    Autodesk.Navisworks.Api.Interop.LcRmFrameworkInterface.ExecuteCommand(commandId, av);
                    Autodesk.Navisworks.Api.Interop.LcRmFrameworkInterface.ExecuteCommand(commandId, av);
                }
                catch
                {
                    System.Windows.Forms.MessageBox.Show("This tool does not appear to be supported");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return 0;           
        }
    }
}


I am executing the following command.

“C:\Program Files\Autodesk\Navisworks Manage 2024\Roamer.exe” -log "C:\Users\NW_log.txt" -OpenFile "C:\Users\Sample.rvm" -AddPluginAssembly “C:\Users\Navisworks 2024\bin\Debug\Navisworks 2024.dll” -ExecuteAddInPlugin "Navisworks2024.ADSK" 


Here is the result that I am receiving.

 

 

Result.png

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 7 of 18

Thanks a lot.

It works fine.

Message 8 of 18

hi,

I executed your command but how to save the file after sorting using the API with -NoGui option.

I need to say YES to save it seems.

 

Tried this:

 

“C:\Program Files\Autodesk\Navisworks Manage 2024\Roamer.exe” -log "C:\Users\NW_log.txt" -OpenFile "C:\Users\Sample.rvm" -AddPluginAssembly “C:\Users\Navisworks 2024\bin\Debug\Navisworks 2024.dll” -ExecuteAddInPlugin "Navisworks2024.ADSK" -SaveFile "C:\MyData\temp\Sample.nwd" -NoGui  -Exit
Message 9 of 18

Hi @KRISHNAN_SESHADRI7V4SS ,

 

Everything seems to be working fine at my end. I am able to save file without any issues.

 

“C:\Program Files\Autodesk\Navisworks Manage 2024\Roamer.exe” -log "C:\Users\NW_log.txt" -OpenFile "C:\Users\Sample.rvm" -AddPluginAssembly “C:\Users\Navisworks 2024\bin\Debug\Navisworks 2024.dll” -ExecuteAddInPlugin "Navisworks2024.ADSK" -SaveFile "C:\Users\Desktop\Output.nwd" -NoGui -Exit


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 10 of 18

Hi,

I copied your commandline syntax and only changed the manage 2024 to 2022.

 

When I give the command as below, the nwd file is not created

"C:\Program Files\Autodesk\Navisworks Manage 2022\Roamer.exe" -log "C:\MyData\temp\NeW_log.txt" -OpenFile "C:\MyData\temp\Sample.rvm" -AddPluginAssembly "C:\Program Files\Autodesk\Navisworks Manage 2022\Plugins\NavisSortTreeMembers.dll" -ExecuteAddInPlugin "Navisworks2024.ADSK" -SaveFile "C:\MyData\temp\Output.nwd" -NoGui -Exit

 

where as when I give the command as below,

"C:\Program Files\Autodesk\Navisworks Manage 2022\Roamer.exe" -log "C:\MyData\temp\NeW_log.txt" -OpenFile "C:\MyData\temp\Sample.rvm" -AddPluginAssembly "C:\Program Files\Autodesk\Navisworks Manage 2022\Plugins\NavisSortTreeMembers.dll" -ExecuteAddInPlugin "Navisworks2024.ADSK" -SaveFile "C:\MyData\temp\Output.nwd"

 

It opens navis manage and I get a warning message that

"You will not be able to undo this operation. Are you sure you want to sort the selection tree? " with options to click Yes or NO. If i say Yes, It sorts and saves a nwd file.

 

 

so i think running the commandline is waiting for an answer yesor no for sorting command.

 

Please clarify.

 

Regards

Krishnan

Message 11 of 18

hi, is there a list of all command line available ?

 

Could you explain those line splease ?

Autodesk.Navisworks.Api.Interop.LcUCIPExecutionContext av = Autodesk.Navisworks.Api.Interop.LcUCIPExecutionContext.eTOOLBAR;
Autodesk.Navisworks.Api.Interop.LcRmFrameworkInterface.ExecuteCommand(commandId, av);
Autodesk.Navisworks.Api.Interop.LcRmFrameworkInterface.ExecuteCommand(commandId, av);

Message 12 of 18

Hi @KRISHNAN_SESHADRI7V4SS ,

 

I checked with Navisworks Engineering team.

 

If you've set -NoGui, that dialog shouldn't pop up, So it looks like a bug. Unfortunately, there's no workaround for it. Regrettably, there's no method to suppress the  dialog via the command line.

 

Hi @lanneauolivier,

 

Please take a look at this below link

https://www.houseofbim.com/posts/naviworks-net-executecommand-method/ 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 13 of 18

Same interest here :winking_face:
Also calling twice maybe to invert the sort?
Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
Message 14 of 18

Hi,

The API given by naveen.kumar.t works and it sorts on normal mode but the problem is with NoGUI option while running on commandline.

 

When running like this,

C:\>"C:\Program Files\Autodesk\Navisworks Manage 2022\Roamer.exe" -log "C:\MyData\temp\NW_log.txt" -OpenFile "C:\MyData\temp\Sample.rvm" -AddPluginAssembly "C:\Program Files\Autodesk\Navisworks Manage 2022\Plugins\NavisSortTreeMembers.dll" -ExecuteAddInPlugin "Navisworks2024.ADSK"

 

It opens Navisworks and loads the Sample.rvm file and then a popup is shown(as per the attachment), if we are sure to Sort the selection tree. Choosing YES sorts the tree.

 

Where as, running with -NoGui option.

C:\>"C:\Program Files\Autodesk\Navisworks Manage 2022\Roamer.exe" -log "C:\MyData\temp\NW_log.txt" -OpenFile "C:\MyData\temp\Sample.rvm" -AddPluginAssembly "C:\Program Files\Autodesk\Navisworks Manage 2022\Plugins\NavisSortTreeMembers.dll" -ExecuteAddInPlugin "Navisworks2024.ADSK" -NoGUI

 

This does not do anything. May be its waiting for answer if it should Sort or not.

I tried to pass on Yes on command line after -NoGui as Y or "Y" or /Y and many other but it throws errors when given Yes in any formats.

 

So i have no solutions for now to run this Sort on script, which is my requirement.

 

 

 

Message 15 of 18

If you can run this in debugger mode with -NoGui, maybe try to hack the window creation using Win32 API?
Or if Naveen can tell us which internal Navisworks class they use to bring this dialog maybe hack this class just the time of these calls?
Crazy stuff I know...
Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
Message 16 of 18

Sending a "Enter" key hopping to clic "Yes" ? ...

Message 17 of 18

:winking_face: that would be a last resort option, yes :winking_face:
Would prefeably have to detect window creation, than send correct meesage.

Maybe something like done here:
https://www.codeproject.com/Articles/24066/Intercept-and-Manage-Windows-Originated-by-Third-p
Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
Message 18 of 18
alexisDVJML
in reply to: alexisDVJML

or here: https://badecho.com/index.php/2024/01/13/external-window-messages/
Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report