Change part Material in vb.net addin

Change part Material in vb.net addin

j.lindingerSNBEM
Observer Observer
781 Views
2 Replies
Message 1 of 3

Change part Material in vb.net addin

j.lindingerSNBEM
Observer
Observer

Dear all,

 

i am currently working on an Add-In to give the user an enhanced GUI to pick the material for an inventor part.

I had a similar solution working in VBA.

It is no problem to read the active material in a listview and attach the material asset object to the tag.

 

When doubleclicking an Item in the Listview i like to take the material object from tag and assign to my part document.

 

This is the code snippet to assign material from listview "lvMaterial":

        Dim oDoc As Inventor.PartDocument

        If g_inventorApplication.ActiveDocumentType = DocumentTypeEnum.kPartDocumentObject Then
            oDoc = g_inventorApplication.ActiveDocument
        Else
            MsgBox("Document type is not kPartDocumentObject")
            Exit Sub
        End If
      
        Dim oMaterial As Inventor.MaterialAsset
        oMaterial = lvMaterial.SelectedItems(0).Tag
        
        oDoc.ComponentDefinition.Material = oMaterial

 

When Executing the code i get an error in the compiler telling me "Interface not supported, HRESULT: 0x80004002 (E_NOINTERFACE)".

I assume the Problem is to assign a MaterialAsset Object to a Material Object.

 

I know in VBA there was the Option to define a variable of type Material, but in VB.Net I can only find MaterialAsset.

 

Do you have any hint for me how this could work? in the SDK Documentation there is nothing documented on how to assign a material. I can only find how to read out all the materials, but that was the easiest thing.

 

I hope for your support, thanks in advance

 

Julian

0 Likes
Accepted solutions (1)
782 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @j.lindingerSNBEM 

You could try using oDoc.ActiveMaterial which is of type MaterialAsset:

Dim oDoc As Inventor.PartDocument

If g_inventorApplication.ActiveDocumentType = DocumentTypeEnum.kPartDocumentObject Then
	oDoc = g_inventorApplication.ActiveDocument
Else
	MsgBox("Document type is not kPartDocumentObject")
	Exit Sub
End If

Dim oMaterial As Inventor.MaterialAsset
oMaterial = lvMaterial.SelectedItems(0).Tag

oDoc.ActiveMaterial = oMaterial

oDoc.ComponentDefinition.Material is of typr Inventor.Material and that object type seems to be exposed by the API but not documented...

0 Likes
Message 3 of 3

j.lindingerSNBEM
Observer
Observer

Hi Jhoel,

 

Thank you very much for your support, this solved my problem. I tried serveral things one the one hand with iteration of assets by numbering or asset in Listview.Tag and on the other hand with ActiveMaterial Property and ComponentDefinition.Material but I did not manage to use Object from Tag with ActiveMaterial.

Now with your suggested code it works!

 

Best regards,

 

Julian