Dear all,
Could you please help me with the following. I wrote a Navisworks Manage 2013 Plug-in which takes a model and adds requirements to it from an external source. All fine on that part. Somewhere in the routine I loop through the selectionsets I created.
The trick now is, I want to assign to each modelitem of that selectionset the requirements as a custom property. I am able to do so using the ComApi/ComApiBridge (code given below).
// get the selection in COM ComApi.InwOpSelection comSelectionOut = ComApiBridge.ComApiBridge.ToInwOpSelection(aSelSet.ExplicitModelItems ); foreach ( ComApi.InwOaPath3 oPath in comSelectionOut.Paths() ) { // get properties collection of the path ComApi.InwGUIPropertyNode2 propn = (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(oPath, true); // add the new property category to the path propn.SetUserDefined(0, "Eisen", "Eisen", newPvec);
}
The result is that when I select an object in the model it perfectly shows the Requirements tab called "Eisen". See the picture below (ps. dont worry that there are two tabs showing "Eisen", thats correct (for now 🙂 ).
I now want to have the Requirements showing in the 'Child' of those ModelItems as well, that is in the case of the example given above, the 'Solid' (see picture below). I have been trying to do so with all sorts of methods from the ComApi, but I just am not able to succeed.
I tried things like the code snippet below, but just cant get it to work.
ComApi.InwGUIPropertyNode2 propn2 = (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(oPath.Nodes().Last, true);
Could you please point me in the right direction on how to get the Requirement (i.e. "Eisen") also at the ModelItem "Solid" (and others).
Thanks in advance!
All the best,
Jeroen
Solved! Go to Solution.
Solved by xiaodong_liang. Go to Solution.
Hi,
probably the following workflow could help.
ModelItemCollection oMC = Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems; // add property to additional paths foreach (ModelItem oEachItem in oMC) { // check if oEachItem.Children is empty //check if each child node is within the current selection //or check the geometry node directly // convert the child node to a path e.g. //ComApi.InwOaPath oAdditionalPath = ComApiBridge.ComApiBridge.ToInwOaPath(oEachItem); // get properties collection of the path //ComApi.InwGUIPropertyNode2 propn = // (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(oAdditionalPath, true); // add the new property category to the path //propn.SetUserDefined(0, "Eisen", // "Eisen", newPvec); } // continue to add property to the selected paths. foreach (ComApi.InwOaPath3 oPath in comSelectionOut.Paths()) { // get properties collection of the path ComApi.InwGUIPropertyNode2 propn = (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(oPath, true); // add the new property category to the path propn.SetUserDefined(0, "Eisen", "Eisen", newPvec); }
Dear Xiaodong,
Your solution is (again 🙂 ) spot on. I modified it a little so I can have the two in one go. Final routine looks like this:
// add property to paths foreach (ModelItem oEachItem in oMC) { ComApi.InwOaPath oPath = ComApiBridge.ComApiBridge.ToInwOaPath(oEachItem); // get properties collection of the path ComApi.InwGUIPropertyNode2 propn = (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(oPath, true); // add the new property category to the path propn.SetUserDefined(0, "Eisen", "Eisen", newPvec); // I want to add the Eisen to the 'geometry' level as well. // check if oEachItem.Children is empty if (oEachItem.Children.First != null) { //check if each child node is within the current selection //or check the geometry node directly // convert the child node to a path e.g. ComApi.InwOaPath oAdditionalPath = ComApiBridge.ComApiBridge.ToInwOaPath(oEachItem.Children.First); // get properties collection of the path ComApi.InwGUIPropertyNode2 propn2 = (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(oAdditionalPath, true); // add the new property category to the path propn2.SetUserDefined(0, "Eisen", "Eisen", newPvec); } }
Thank you very much for the solution. I will close this thread with 'solution accepted'.
Best regards,
Jeroen
Hi, Jeroen,
you made it much elegant! Glad to know it solved your question. Thank you sharing the updated code 🙂
Hi guys,
Can you show the code where you create the newPvec object?
thanks,
please refer to this post:
Can't find what you're looking for? Ask the community or share your knowledge.