Adding User DataProperty using VBNet and COM API

Adding User DataProperty using VBNet and COM API

ngombault
Enthusiast Enthusiast
2,467 Views
2 Replies
Message 1 of 3

Adding User DataProperty using VBNet and COM API

ngombault
Enthusiast
Enthusiast

Hi,

 

I am trying to add User Properties to an object, using VBNet and the COM API as it seems that the standard API doesn't provide any method for that.

 

After reading the few available samples of COM API on that forum and some of the documentation, I still can't figure it out and it all seems very confusing. Is there step by step sample or more detailed documentation somewhere about using the COM API with VB.Net?

 

I looked at this sample

 

but there are some structure that I don't know how to translate in VBNet (the (...)state part):

ComApi.InwGUIPropertyNode2 propn =
		(ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(oPath, true)

is that it?

Dim Propn As InwGUIPropertyNode2 = state.GetGUIPropertyNode(COMmi, True)

 

and some missing piece of code that I can't figure out, the one defining the new Property to add (newPvec) in the sample. I checked the documentation but I don't get it... (attached is a sample of things I don't get from the documentation)

 

Thanks

0 Likes
Accepted solutions (2)
2,468 Views
2 Replies
Replies (2)
Message 3 of 3

ngombault
Enthusiast
Enthusiast
Accepted solution

Much appreciated, as always.

 

for the record, the VBNet solution goes like that:

 

 

Imports Autodesk.Navisworks.Api
Imports Autodesk.Navisworks.Api.ComApi
Imports Autodesk.Navisworks.Api.Interop.ComApi


    Public Sub AddProperty()

        'Get the COM Bridge to manipulate Properties
        Dim state As Interop.ComApi.InwOpState10 = ComApiBridge.State

        'Create the New Category and Property
        Dim newPropertyCategory As InwOaPropertyVec = state.ObjectFactory(nwEObjectType.eObjectType_nwOaPropertyVec, Nothing, Nothing)
        Dim newProperty As InwOaProperty = state.ObjectFactory(nwEObjectType.eObjectType_nwOaProperty, Nothing, Nothing)
        newProperty.name = "Prop Name"
        newProperty.UserName = "Prop Display Name"
        newProperty.value = "Prop Value"

        'Add the new Property to the Category
        newPropertyCategory.Properties.Add(newProperty)

        'Get the selected model item, its COM path, and its list of PropertyCategories
        Dim mi As ModelItem = Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems(0)
        Dim miPath As InwOaPath = ComApiBridge.ToInwOaPath(mi)
        Dim PropertyCategories As InwGUIPropertyNode2 = state.GetGUIPropertyNode(miPath, True)

        'Add the new Category (PropertyVector) to the modelitem
        PropertyCategories.SetUserDefined(0, "Tab Display Name", "Tab Name", newPropertyCategory)

    End Sub

 

 

 

Cheers,

-Nic

0 Likes