Navisworks API

Reply
Member
Posts: 4
Registered: ‎09-20-2012
Message 1 of 6 (186 Views)

Problem Removing Custom Attributes

186 Views, 5 Replies
09-20-2012 07:03 AM

Hi all,

 

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.HasCategoryByDisplayName("MyAttribute"))

                Dim items As ModelItemCollection = Search.FindAll(Application.ActiveDocument, True)

                Application.ActiveDocument.CurrentSelection.CopyFrom(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

 

Many thanks,

 

Mike

ADN Support Specialist
xiaodong.liang
Posts: 1,190
Registered: ‎06-12-2011
Message 2 of 6 (178 Views)

Re: Problem Removing Custom Attributes

09-24-2012 09:08 PM in reply to: railrover

Hi,

 

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?



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Member
Posts: 4
Registered: ‎09-20-2012
Message 3 of 6 (175 Views)

Re: Problem Removing Custom Attributes

09-24-2012 09:39 PM in reply to: xiaodong.liang

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.

 

Cheers

 

Mike

ADN Support Specialist
xiaodong.liang
Posts: 1,190
Registered: ‎06-12-2011
Message 4 of 6 (170 Views)

Re: Problem Removing Custom Attributes

09-24-2012 10:33 PM in reply to: railrover

Hi,

 

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.CopyFrom(items), then iterate CurrentSelection. It would also cost time to set the current selection.

 



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Member
Posts: 4
Registered: ‎09-20-2012
Message 5 of 6 (165 Views)

Re: Problem Removing Custom Attributes

09-24-2012 10:49 PM in reply to: xiaodong.liang

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.

 

Cheers

 

Mike

ADN Support Specialist
xiaodong.liang
Posts: 1,190
Registered: ‎06-12-2011
Message 6 of 6 (153 Views)

Re: Problem Removing Custom Attributes

09-27-2012 03:36 AM in reply to: railrover

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\PluginPropertyDatabaseExample. The sample self-explains.



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community