Navisworks API

Navisworks API

Reply
Contributor
ctci20299
Posts: 11
Registered: ‎10-18-2009
Message 1 of 3 (171 Views)

How to get category Index to update category to model item

171 Views, 2 Replies
06-13-2012 06:24 PM

Hi, Everyone,

     In my in-house NW Plug-in, I need add user defined properties to a specify category,

             After first time, I need get category index to update it (code as below), If somebody can

             help , I am very appreciated.

 

Lee, Wenhan

 

Code as below :

 

            Navisworks.ModelItemCollection mic = new Navisworks.ModelItemCollection();
            mic.Add(model);

 

            ComApi.InwOpSelection comSels = ComApiBridge.ComApiBridge.ToInwOpSelection(mic);

            ComApi.InwSelectionPathsColl oPaths = comSels.Paths();

            ComApi.InwOaPath3 oPath = oPaths.Last() as ComApi.InwOaPath3;

            ComApi.InwGUIPropertyNode2 pNode = (ComApi.InwGUIPropertyNode2)state.

                    GetGUIPropertyNode(oPath, true);

            

            ComApi.InwOaPropertyVec newPvec = state.ObjectFactory

                    (ComApi.nwEObjectType.eObjectType_nwOaPropertyVec, null, null) as ComApi.InwOaPropertyVec;

            

            ComApi.InwOaProperty newP;

 

            foreach (DataRow dr in prps)
            {
                        newP = state.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwOaProperty, null, null)

                                as ComApi.InwOaProperty;


                        newP.name = dr["PName"] as string;
                        newP.UserName = dr["PName"] as string;
                        newP.value = dr["PValue"] as string;
                        newPvec.Properties().Add(newP);
                        //MessageBox.Show(dr["PName"] + " " + dr["PValue"], strModel);
            }

 

            int idx = getIndexCategory(model, catName);
                    
            pNode.SetUserDefined(idx, catName, catName, newPvec); // idx 0: Append, othesr is replace

Contributor
ctci20299
Posts: 11
Registered: ‎10-18-2009
Message 2 of 3 (165 Views)

Re: How to get category Index to update category to model item

06-13-2012 08:35 PM in reply to: ctci20299

 

 

        int idx = getIndexCategory(pNode, catName);

 

        private int getIndexCategory(ComApi.InwGUIPropertyNode2 pNode, string catName)
        {
            int idx = 0, rst = 0;

            foreach (ComApi.InwGUIAttribute2 attribute in pNode.GUIAttributes())
            {
                if (attribute.UserDefined)
                {
                    idx++;

                    if (attribute.ClassUserName == catName)
                    {
                        rst = idx;
                        break;
                    }
                }
            }           
           
            return rst;
        }

ADN Support Specialist
xiaodong.liang
Posts: 1,311
Registered: ‎06-12-2011
Message 3 of 3 (136 Views)

Re: How to get category Index to update category to model item

08-01-2012 01:25 AM in reply to: ctci20299

Hi ctci20299 ,

 

yes, what you are doing is the only way. The API does not provide the index for the catergory or property. You will need to iterate the collection and calculate the index. I would suggest storing the information.thus you can re-use them next time.



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!