Navisworks API

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

Add PropertyCategory and DataProperty with .NET using COM API

421 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.
ADN Support Specialist
xiaodong.liang
Posts: 1,251
Registered: ‎06-12-2011
Message 2 of 5 (398 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: 33
Registered: ‎10-07-2013
Message 3 of 5 (391 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 (243 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 (238 Views)

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

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community