Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add PropertyCategory and DataProperty with .NET using COM API

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
danielkazado
3749 Views, 4 Replies

Add PropertyCategory and DataProperty with .NET using COM API

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.
4 REPLIES 4
Message 2 of 5

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.
Message 3 of 5

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.
Message 4 of 5
Evgueny
in reply to: danielkazado

Hello All! Please tell me сan I do this using the API c#
Message 5 of 5
Evgueny
in reply to: Evgueny

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report