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: 

Adding User DataProperty using VBNet and COM API

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
ngombault
2108 Views, 2 Replies

Adding User DataProperty using VBNet and COM API

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

2 REPLIES 2
Message 3 of 3
ngombault
in reply to: xiaodong_liang

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

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report