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)
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;
}
}
}
C:\Program Files\Autodesk\Navisworks Manage 2022\Plugins
& '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
Solved! Go to Solution.
Solved by naveen.kumar.t. Go to Solution.
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
Hi, I tried your new command but it also gave the same error, "The PLugin was not found".
So tried this,
Could you please send me a non-confidential sample RVM file for testing?
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
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.
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:
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
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
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);
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/
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.
Can't find what you're looking for? Ask the community or share your knowledge.
