- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)
- Old code is under message 2 of 13 of the below link.
- 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;
}
}
}
- I have compiled and copied the dll file to the installation folder.
C:\Program Files\Autodesk\Navisworks Manage 2022\Plugins
- Any sample RVM file which got some elements is good to test.
- 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
- While executing the above code, it opens the Navisworks Manage but then we get an error message as “The Plugin was not found”
Solved! Go to Solution.