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.
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.
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.
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.
Solved! Go to Solution.
Solved by xiaodong_liang. Go to Solution.
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?
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.
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...