Hi,
I am using Navisworks Manage 2014 and try to load new PropertyCategory and DataProperty to the selected items. I try to do it with a Plugin and Button4 in the Form shall load new PropertyCategory and DataProperty to the selected items.
I get most of the information for the code from "http://adndevblog.typepad.com/aec/2012/08/addmodifyremove-custom-attribute-using-com-api.html"
Find below my code for the button below, when I try to use it in Navisworks it gives error and close. Any advice ?
Thanks
Private Sub Button4_Click(ByVal sender As Object, e As EventArgs) Handles Button4.Click
Dim nwState As Autodesk.Navisworks.Api.Interop.ComApi.InwOpState10
Dim nwPath As Autodesk.Navisworks.Api.Interop.ComApi.InwOaPath
Dim nwNode As Autodesk.Navisworks.Api.Interop.ComApi.InwGUIPropertyNode2 'PROPERTY CATEGORY
Dim nwProps As Autodesk.Navisworks.Api.Interop.ComApi.InwOaPropertyVec 'DATA PROPERTY LISTESI
Dim nwProps1 As Autodesk.Navisworks.Api.Interop.ComApi.InwOaProperty 'DATA PROPERTY
Dim nwDOC As Autodesk.Navisworks.Api.Document
nwDOC = Autodesk.Navisworks.Api.Application.ActiveDocument
Dim oItem As Autodesk.Navisworks.Api.ModelItem
For Each oItem In oDOC.CurrentSelection.SelectedItems
nwState = nwDOC.State
nwPath = nwState.CurrentSelection.Paths(1)
nwProps = nwState.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwOaPropertyVec)
nwProps1 = nwState.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwOaProperty)
nwNode = nwState.GetGUIPropertyNode(nwPath, True)
nwProps1.name = "Deneme_Name"
nwProps1.value = "Deneme_Value"
nwProps.Properties.Add(nwProps1)
nwNode.SetUserDefined(0, "User_Name", "Internal_Name", nwProps)
Next
End Sub
Solved! Go to Solution.
Solved by danielkazado. Go to Solution.
I managed to do it with the help of your blog and this forum help of some more search. I also added to the end to search for the same name of PropertyCategory not to dublicate. I copy the code below for later reference for forum members. Thanks for your blog.
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click 'COMAPI ile .net baglantisi Dim nwState As Autodesk.Navisworks.Api.Interop.ComApi.InwOpState10 nwState = Autodesk.Navisworks.Api.ComApi.ComApiBridge.State 'create new Property Category Vector Dim newPvec As Autodesk.Navisworks.Api.Interop.ComApi.InwOaPropertyVec newPvec = nwState.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwOaPropertyVec) 'create new property Dim newP As Autodesk.Navisworks.Api.Interop.ComApi.InwOaProperty newP = nwState.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwOaProperty) 'set name, username and value of the new property newP.name = "Property_Name" newP.UserName = "Property_UserName" newP.value = "ProCS" 'add the new property to the new Property Category newPvec.Properties().Add(newP) Dim oItem As Autodesk.Navisworks.Api.ModelItem Dim oDOC As Autodesk.Navisworks.Api.Document oDOC = Autodesk.Navisworks.Api.Application.ActiveDocument 'add property category to each item selected For Each oItem In oDOC.CurrentSelection.SelectedItems 'select path of the item Dim oItemPath As Autodesk.Navisworks.Api.Interop.ComApi.InwOaPath oItemPath = Autodesk.Navisworks.Api.ComApi.ComApiBridge.ToInwOaPath(oItem) 'select Property Category from path Dim PropCat As Autodesk.Navisworks.Api.Interop.ComApi.InwGUIPropertyNode2 PropCat = nwState.GetGUIPropertyNode(oItemPath, True) 'check each PropertyCategory Attribute to find same user_name Dim PropCatAtt As Autodesk.Navisworks.Api.Interop.ComApi.InwGUIAttribute2 Dim checkAtt As Boolean = False For Each PropCatAtt In PropCat.GUIAttributes() If PropCatAtt.ClassUserName = "ProCS" Then checkAtt = True Exit For End If Next 'if the PropertyCategory does not exist add it If Not checkAtt Then PropCat.SetUserDefined(0, "ProCS", "ProCS", newPvec) End If Next MsgBox("PROPERTIES LOADED UNDER ProCS TAB", MsgBoxStyle.OkOnly) End Sub
I find link for this blog
http://adndevblog.typepad.com/aec/2012/05/create-attributes-and-properties-for-model-objects-using-n...
in this topic
http://forums.autodesk.com/t5/Autodesk-Navisworks-API/Adding-User-DataProperty-using-VBNet-and-COM-A...
and solved my problem.
Thanks!!!
Thank you Xiadong Liang!
Can't find what you're looking for? Ask the community or share your knowledge.