Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Modifying or deleting user defined properties

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
2508 Views, 3 Replies

Modifying or deleting user defined properties

Dear Support,

 

I m developing a Navisworks plugin whose purpose is to easily configure and automatically generate Augemented Reality (AR) experiences from a Navisworks project.

 

 DC4NW1.jpg

 

Some of the features requires to programatically define custom user defined properties attached to some modelitems, so that we can save our specific AR parameters within the Navisworks project (*.nwf). In our case, these custom user defined properties are gathered in a property tab Diota as illustrated in the following picture.

 

DC4NW2.jpg

 

These properties have been generated thanks to the following code (note that DiotaProperties is a custom class designed for a better management of custom attributes) :

 

public static void AddDiotaProperties(ComApi.InwOaPath3 iPath, DiotaProperties iDiotaProperties)
        {
            ComApi.InwOpState10 state;
            state = ComApiBridge.ComApiBridge.State;

            ComApi.InwGUIPropertyNode2 propn =
                        (ComApi.InwGUIPropertyNode2) state.GetGUIPropertyNode(iPath, true);

            // create new property category
            // (new tab in the properties dialog)
            ComApi.InwOaPropertyVec newPvec = iDiotaProperties.getInwOaPropertyVec();

            // add the new property category to the path
            propn.SetUserDefined(0, "Diota",
                            "Diota", newPvec);
        }

Then we want to offer to our users the capability to modify these custom properties. So we tried the following code :

 

public static void SetDiotaProperties(ComApi.InwOaPath3 iPath, DiotaProperties iDiotaProperties)
        {
            ComApi.InwOpState10 state;
            state = ComApiBridge.ComApiBridge.State;

            ComApi.InwGUIPropertyNode2 propn = (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(iPath, true);
            int index = 0;
            foreach (ComApi.InwGUIAttribute2 attribute in propn.GUIAttributes())
            {
                if (attribute.UserDefined)
                {
                    if (attribute.ClassUserName.Equals("Diota"))
                    {
                        propn.SetUserDefined(index, "Diota", "Diota", iDiotaProperties.getInwOaPropertyVec());
                    }
                    index++;
                }
            }
        }

Our first issue is that such a method duplicates the properties instead of modifying the existing ones, as we expected.

DC4NW3.jpg

 

 

So what is the proper way to update existing user defined properties ?

 

Then we found a workaround by first deleting the former user defined user properties and then adding the new one.

 

 public static void SetDiotaProperties(ComApi.InwOaPath3 iPath, DiotaProperties iDiotaProperties)
        {
            ComApi.InwOpState10 state;
            state = ComApiBridge.ComApiBridge.State;

            ComApi.InwGUIPropertyNode2 propn = (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(iPath, true);
            int index = 0;
            foreach (ComApi.InwGUIAttribute2 attribute in propn.GUIAttributes())
            {
                if (attribute.UserDefined)
                {
                    if (attribute.ClassUserName.Equals("Diota"))
                    {
                        //propn.SetUserDefined(index, "Diota", "Diota", iDiotaProperties.getInwOaPropertyVec());
                        propn.RemoveUserDefined(index);
                        propn.SetUserDefined(index, "Diota", "Diota", iDiotaProperties.getInwOaPropertyVec());
                    }
                    index++;
                }
            }
        }

Such an implementation makes it possible to avoid duplicating our custom user properties each time we want to update their values. But unfortunately we noticed that it also delete all other user defined properties, event them with a different classusername ( != Diota), which is also a big issue.

 

Thank you in advance for your anwser,

 

Christophe Montandon.

 

3 REPLIES 3
Message 2 of 4
xiaodong_liang
in reply to: Anonymous

Hi @Anonymous,

 

I think this blog has illustrated the questions you are concerned. 

http://adndevblog.typepad.com/aec/2012/08/addmodifyremove-custom-attribute-using-com-api.html

could you check if it helps?

Message 3 of 4
Anonymous
in reply to: xiaodong_liang

Dear @xiaodong_liang,

 

The link you shared (Add/Modify/Remove custom attribute using COM API) makes me understand that, when using ComApi.InwGUIPropertyNode2.SetUserDefined(int ndx, string user_name, string internal_name, InwOaPropertyVec props) or ComApi.InwGUIPropertyNode2.RemoveUserDefined(int ndx) methods, the index value matching with the first user defined attribute is 1 and not 0, as one can expect if compared to object collections accessors and modifiers (array, list, etc.).

 

So I could definitely fix my issue by simply setting the initial value of my index to 1 and no longer to 0, as described in the following code :

 

public static void SetDiotaProperties(ComApi.InwOaPath3 iPath, DiotaProperties iDiotaProperties)
        {
            ComApi.InwOpState10 state;
            state = ComApiBridge.ComApiBridge.State;

            ComApi.InwGUIPropertyNode2 propn = (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(iPath, true);
            int index = 1;
            foreach (ComApi.InwGUIAttribute2 attribute in propn.GUIAttributes())
            {
                if (attribute.UserDefined)
                {
                    if (attribute.ClassUserName.Equals("Diota"))
                    {
                        propn.SetUserDefined(index, "Diota", "Diota", iDiotaProperties.getInwOaPropertyVec());
                    }
                    index++;
                }
            }
        }

 So thanks again for your support, which is very much appreciated 😉

 

Christophe.

Message 4 of 4
jmontesh
in reply to: Anonymous

That solved my issue. Don't know why but in many samples instead of iterating and giving an index they show jut a 1 as it it allways had to be the first...

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report