By Xiaodong Liang The current .NET API does not provide the related objects. But you can take advantage of COM API by COM interop. The chapter 10 of apinetdocumentation NET Developers Guide.pdf to know more about COM interop. The following code snippet is based on the sample apinetexamplesPlugInsAPICallsCOMPlugin. private void addProperty() { ComApi.InwOpState10 state; state = ComApiBridge.ComApiBridge.State; // get current selection ModelItemCollection modelItemCollectionIn = new ModelItemCollection( Autodesk.Navisworks.Api.Application.ActiveDocument. CurrentSelection.SelectedItems); // get the selection in COM ComApi.InwOpSelection comSelectionOut = ComApiBridge.ComApiBridge.ToInwOpSelection(modelItemCollectionIn); // get paths within the selection ComApi.InwSelectionPathsColl oPaths = comSelectionOut.Paths(); ComApi.InwOaPath3 oPath = (ComApi.InwOaPath3)oPaths.Last(); // get properties collection of the path ComApi.InwGUIPropertyNode2 propn = (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(oPath, true); // create new property category // (new tab in the properties dialog) ComApi.InwOaPropertyVec newPvec = (ComApi.InwOaPropertyVec)state.ObjectFactory( ComApi.nwEObjectType.eObjectType_nwOaPropertyVec, null, null); // create new property ComApi.InwOaProperty newP = (ComApi.InwOaProperty)state.ObjectFactory( ComApi.nwEObjectType.eObjectType_nwOaProperty, null, null); // set the name, username and value of the new property newP.name = "demo_Property_Name"; newP.UserName = "demo_Property_UserName"; newP.value = "demo_Property_Value"; 
0; // add the new property to the new property category newPvec.Properties().Add(newP); // add the new property category to the path propn.SetUserDefined(0, "demo_PropertyTab_Name", "demo_PropertyTab_InteralName", newPvec); }
Create Attributes and properties for model objects using .NET API
Comments
7 responses to “Create Attributes and properties for model objects using .NET API”
-
I am trying to replicate what happens at the Find Items Interface where by clicking on the Category List, all the unique categories in the entire model get listed; and by clicking on the Property List, all the unique properties in the entire model under the selected category get listed. I have looked in .Net API and .COM API with no success.
In .Net, I accessed the PropertyCategoryCollection class for every ModelItem in the entire model and ran If Statement to find a unique PropertyCategory and PropertyData. However, this takes forever in a large model.
In COM, I used GetGUIPropertyNode and GUIAttributes methods to accessed InwGUIAttributesColl class for every InwOaPath in the entire model and ran If Statement to find a unique InwOaPropertyAttribute and InwOaProperty. Same thing, the process would take a long time.
Is there any way to make this process faster similar to the Find Items interface -
I have replied in this link:
http://forums.autodesk.com/t5/Autodesk-Navisworks-API/List-all-of-the-Categories-in-the-Model/td-p/3620658 -
梁老师,您好!
我想通过COM API 对 几何实体的 特性“InwOaProperty”条目进行删除操作。使用如下代码,却提示错误:
获取几何实体,路径中的最后一个节点
ComApi.InwOaNode oNode = oPath.Nodes()[oPath.Nodes().Count]
获取几何实体的InwGUIPropertyNode2
NavisworksIntegratedAPI10.InwGUIPropertyNode2 oNodeAtts = state.GetGUIPropertyNode(oPath, true) as NavisworksIntegratedAPI10.InwGUIPropertyNode2
获取几何实体的InwGUIAttributesColl
NavisworksIntegratedAPI10.InwGUIAttributesColl oNodeAttsColl = oNodeAtts.GUIAttributes()
获取几何实体的InwGUIAttribute2
NavisworksIntegratedAPI10.InwGUIAttribute2 oNodeAtt = oNodeAttsColl[1]
获取几何实体的InwOaPropertyColl
NavisworksIntegratedAPI10.InwOaPropertyColl oNodeAttProps = oNodeAtt.Properties()
对几何实体的oNodeAtt下面的某一行属性进行删除操作
oNodeAttProps.Remove(0)
经过调试只有最后一个语句执行出现问题,捕捉错误代码:
Message “>”
不太明白到底是哪出现问题,特向您请教,谢谢! -
经过调试只有最后一个语句执行出现问题,捕捉错误代码:
Message ” NavisWorks Error – Not implemented ”你好,
不清楚typepad是否有问题,我无法发布comments。
从原CAD文件来的属性只读,不可编辑删除。只有自定义属性可编辑删除,参见此博客文章:
http://adndevblog.typepad.com/aec/2012/08/addmodifyremove-custom-attribute-using-com-api.html
Regards,
Xiaodong -
梁老师,您好!
我想通过遍历属性,读取timeliner中的值,通过下面代码读不到,不知为何?
Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;
foreach (ModelItem oItem in oDoc.CurrentSelection.SelectedItems)
{
foreach (PropertyCategory oPC in oItem.PropertyCategories)
特向您请教,谢谢! -
Sir,
This post was a very long time back. But if you are around in this blog can you please share the code for this piece
“In COM, I used GetGUIPropertyNode and GUIAttributes methods to accessed InwGUIAttributesColl class for every InwOaPath in the entire model and ran If Statement to find a unique InwOaPropertyAttribute and InwOaProperty.”
I am trying to code in COM still -
Hi. I know this one is old but it would help me enormously. Is there an updated way to attach properties to objects and if not is there a reason that when I call propn.SetUserDefined(0,”demo_PropertyTab_Name”,”demo_PropertyTab_InteralName”, newPvec); it takes on average 100ms? Is there a way to speed it up as this would become slow where the property count is high.

Leave a Reply to RAMESH P KCancel reply