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: 

Unable to add custom properties to all desired modelitems

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
jvisser.autodesk
1922 Views, 8 Replies

Unable to add custom properties to all desired modelitems

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 🙂 ).

 

Model_ShowingRequiremets.PNG

 

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. 

 

Model_WhereIAlsoWantRequirements.PNG

 

 

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

8 REPLIES 8
Message 2 of 9

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);
            }

 

Message 3 of 9

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

Message 4 of 9

Hi, Jeroen,

 

you made it much elegant!  Glad to know it  solved your question. Thank you sharing the updated code 🙂

Message 5 of 9
ngombault
in reply to: xiaodong_liang

Hi guys,

 

Can you show the code where you create the newPvec object?

 

thanks,

Message 6 of 9
xiaodong_liang
in reply to: ngombault
Message 7 of 9

In Navisworks 2015 we are able to do it through .net API?

Message 8 of 9

Hi,

Sorry, Navisworks 2015 still needs COM interop to manipulate properties.
Message 9 of 9

There is it on development list?

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

Post to forums  

Rail Community


Autodesk Design & Make Report