hi Navis API gurus,
I'm wrinting code to maintain nwf files. I'm appending and removing files in the nwf files. When I append files they always appear last in the selection tree even if they start with the letter a. In the GUI interface it is possible to do a sort manually but I havn't been able to do a "in place" sort of activedocument from code. I see that there are internal methods that might be useful like InternalInsert(int index, Model item); but I guess they are internal only. I also tryed Autodesk.Navisworks.Api.Application.ActiveDocument.Models.OrderBy but that seems to create a new sorted list ( it is not a in place sort).
Any suggestions. I'm currently coding towards the 2012 api.
Ulrik
Solved! Go to Solution.
Solved by xiaodong_liang. Go to Solution.
Hi,
It looks to me the collection of Models in .NET API is read-only. The following is a workaround. It deletes all files and append them again with the new order. I know you would hate such way, but this may be the way we have to go currently.
Hi Xiaodong Liang,
I'm already done with the code. I ended up with a solution where I first detect if the change only involves removal - in that case I don't need sorting (the objects are normally already sorted). In case I need to append files I need to remove all objects (as you also found out) expect index 0 (in order to not get an exception error) and then I append all the objects I need and after this I can delete index 0. The code looks really awful and I wanted to avoid this mess.
bg
Ulrik
Hi Ulrik,
Yes, this is not elegant and removing&appending models will cause performance issue.
One more workaround, if it is fine to you, is to build you own selection tree, thus you can manage them easily. For the built-in tree, the way is what we have found..
a custom selection tree might be a good idea. Are there any draw backs when creating/using a custom selection trees?
I haven't looked into custom selection trees and I haven't found any sample code on how to work with a them perhaps you could direct me to some code samples.
Ulrik
Hi,
To build the custom tree, you just need to iterate the model items, children, decendents, and create the tree node one by one in the Tree View control of Windows Form.
If you work with WPF, the Tree View control can bind the hierarchy of Navisworks model items. Please refer to the blog below.
hi Xiaodong Liang,
Interesting blog post, I'll look more into it, but using wpf and having to work around issues with the render tread just to do a simple sort seems like overkill and I'm not sure it will work in nogui mode. I can always hope that someday they will add a (file level) in-place sort capability to the API
Ulrik
Hi Ulrik,
I logged a wish #44723: in-place sort capability (file level). But I cannot guarantee anything until it is implemented in the future release(s).
Dear all,
can anyone say which is status of the wish #44723: in-place sort capability (file level) ?
I come from my post here and I'm facing similar issue
One possible idea for me also is to have a workaorund coming from a little API program sorting the model tree (1st level only) whereas a built-in solution to enhance the scene-->sort function would be nice at all.
Regards,
danko
Hi XiaoDong,
I've tried to use your code to remove exsiting models and Navisworks crashes at the line
ComBridge.State.DeleteSelectedFiles();
I'm currently using Navisworks 2018; has there been any changes ?
Thanks.
hi,
perhaps you get this error because you try to delete the last remaining model - Navisworks doesn't allow you to have 0 models in a loaded nwf - so you need to have a check in your code to prevent this from happening (if count = 1 do not delete). If you want to unload all models from Navisworks like a "file new" you need to use Autodesk.Navisworks.Api.Application.MainDocument.Clear();
edit: forgot to mention the delete statement works perfectly fine in 2018 - we run it on our rather massiv nwd production line.
br
Ulrik