• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Navisworks API

    Reply
    New Member
    Posts: 2
    Registered: ‎02-15-2013
    Accepted Solution

    Unable to add custom properties to all desired modelitems

    222 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

    Please use plain text.
    ADN Support Specialist
    xiaodong.liang
    Posts: 814
    Registered: ‎06-12-2011

    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

    Please use plain text.
    New Member
    Posts: 2
    Registered: ‎02-15-2013

    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

    Please use plain text.
    ADN Support Specialist
    xiaodong.liang
    Posts: 814
    Registered: ‎06-12-2011

    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

    Please use plain text.
    Active Contributor
    Posts: 32
    Registered: ‎11-14-2012

    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,

    Please use plain text.
    ADN Support Specialist
    xiaodong.liang
    Posts: 814
    Registered: ‎06-12-2011

    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

    Please use plain text.