Navisworks API

Navisworks API

Reply
Active Contributor
danielkazado
Posts: 38
Registered: ‎10-07-2013
Message 1 of 5 (573 Views)
Accepted Solution

Add PropertyCategory and DataProperty with .NET using COM API

573 Views, 4 Replies
12-09-2013 12:12 AM

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

 

Daniel Kazado

Please use Accept as Solution if your question is answered.
You may Give Kudos if the answer is helpful.

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

 

ADN Support Specialist
xiaodong.liang
Posts: 1,335
Registered: ‎06-12-2011
Message 2 of 5 (550 Views)

Re: Add PropertyCategory and DataProperty with .NET using COM API

12-11-2013 01:09 AM in reply to: danielkazado
Hi,

could you debug the code to see what the failure is? particularly, adding Try-Catch clause to see more information, instead of crashing Navisworks directly.


Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Active Contributor
danielkazado
Posts: 38
Registered: ‎10-07-2013
Message 3 of 5 (543 Views)

Re: Add PropertyCategory and DataProperty with .NET using COM API

12-11-2013 06:34 AM in reply to: xiaodong.liang

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

 

Daniel Kazado

Please use Accept as Solution if your question is answered.
You may Give Kudos if the answer is helpful.
Contributor
Evgueny
Posts: 23
Registered: ‎08-14-2013
Message 4 of 5 (395 Views)

Re: Add PropertyCategory and DataProperty with .NET using COM API

01-29-2014 08:38 PM in reply to: danielkazado
Hello All! Please tell me сan I do this using the API c#
Contributor
Evgueny
Posts: 23
Registered: ‎08-14-2013
Message 5 of 5 (390 Views)

Re: Add PropertyCategory and DataProperty with .NET using COM API

01-29-2014 10:04 PM in reply to: Evgueny
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.