I am trying to remove all custom attributes from a document.
With a fairly small document (with about 700 instances of the custom attribute), my code works fine, but with larger models (say about 9000 instances, Navisworks becomes unresponsive. Looking at the task manager, the code is still running, but it never exits.
ANy ideas? The code is below:
Dim nwstate As ComApi.InwOpState10 nwstate = ComApiBridge.ComApiBridge.State Dim Search As New Search Search.Selection.SelectAll() Search.SearchConditions.Add(SearchCondition.HasCat
egoryByDisplayName("MyAttribute")) Dim items As ModelItemCollection = Search.FindAll(Application.ActiveDocument, True) Application.ActiveDocument.CurrentSelection.CopyFr om(items) Dim index As Integer
For Each nwpath As ComApi.InwOaPath In nwstate.CurrentSelection.Paths index = 0 Dim nwNode As ComApi.InwGUIPropertyNode2 = nwstate.GetGUIPropertyNode(nwpath, True) For Each nwAtt As ComApi.InwGUIAttribute2 In nwNode.GUIAttributes() If Not nwAtt.UserDefined Then Continue For index += 1 nwNode.RemoveUserDefined(index) Exit For Next GC.KeepAlive(nwNode) GC.KeepAlive(nwpath) Next GC.KeepAlive(nwstate) End If
It is a bit hard to diagnose without such large sample. I would like to check if you could debug to see
1) if the code is still running within the loop? Is it possible a dead loop occured?
2) are these objects in a good status? any strange detail?
3) if this problem occured from a specific instance?
4) RemoveUserDefined always works without failure?
Thanks for your repy...
The code DID finally finish running, but it took far too long to be useable.
Is there a better way to globally remove a custom attribute?
My problem is that I need to distribute two different NWD's; one of which only contains a sub-set of the custom attributes of the other. I want to import all the attributes, create the first NWD, then remove the ones I dont want, and create the second NWD.
As I will have about 15 NWD's of each type, automating this process will be huge n terms of time svaings.
The iteration is the only way currently. It is true it would be slow with more instances. And it looks you have used plug-in which runs in process that has better performance. And I believe you have made Navisworks invisible to run your plug-in. So I have not a good idea at this moment.
I did not test, however, I am curious if it is also slow when you adding these attribute. If it is faster, probably you could call RemoveUserDefined (ndx=0) to remove all (I guess remove all may be faster), and add the attribute you need again?
In addition, ComApiBridge.ToInwOpSelection can translate from ModelItemCollection to InwOpSelection. Makes a copy of the underlying selection. So you do not need to call Application.ActiveDocument.CurrentSelection.CopyFr
We use iConstruct to import the data, which seems to run very quickly.
I presume they must be using a different method to create custom attributes, rather then interation.
I am fairly new to developing with the Navisworks API, and have not yet looked at how you can use the API to import data from external sources and create custom attributes using the imported data.
from our engineers: Not sure how iConstruct works; It could be that they are using a custom property plugin (as opposed to creating a whole load of custom attributes), in which case there is no iteration over the model. I don’t know of any faster way to remove user-defined properties other than just iterating over all the items in the model and removing the attribute.
You can find the sample custom property plugin at \api\COM\examples\Plugin\PluginPropertyDatabase