Navisworks API

Navisworks API

Reply
New Member
jvisser.autodesk
Posts: 2
Registered: ‎02-15-2013
Message 1 of 6 (501 Views)
Accepted Solution

Unable to add custom properties to all desired modelitems

501 Views, 5 Replies
02-15-2013 05:45 AM

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

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

ADN Support Specialist
xiaodong.liang
Posts: 1,299
Registered: ‎06-12-2011
Message 2 of 6 (480 Views)

Re: Unable to add custom properties to all desired modelitems

02-19-2013 06:55 PM in reply to: jvisser.autodesk

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

 



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

New Member
jvisser.autodesk
Posts: 2
Registered: ‎02-15-2013
Message 3 of 6 (447 Views)

Re: Unable to add custom properties to all desired modelitems

03-01-2013 06:16 AM in reply to: xiaodong.liang

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

ADN Support Specialist
xiaodong.liang
Posts: 1,299
Registered: ‎06-12-2011
Message 4 of 6 (426 Views)

Re: Unable to add custom properties to all desired modelitems

03-04-2013 06:36 PM in reply to: jvisser.autodesk

Hi, Jeroen,

 

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



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Active Contributor
ngombault
Posts: 45
Registered: ‎11-14-2012
Message 5 of 6 (357 Views)

Re: Unable to add custom properties to all desired modelitems

04-01-2013 05:39 PM in reply to: xiaodong.liang

Hi guys,

 

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

 

thanks,

ADN Support Specialist
xiaodong.liang
Posts: 1,299
Registered: ‎06-12-2011
Message 6 of 6 (349 Views)

Re: Unable to add custom properties to all desired modelitems

04-02-2013 08:26 PM in reply to: ngombault

please refer to this post:

http://adndevblog.typepad.com/aec/2012/05/create-attributes-and-properties-for-model-objects-using-n...



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.