Assigning material to parts

Assigning material to parts

hvj1234
Participant Participant
589 Views
1 Reply
Message 1 of 2

Assigning material to parts

hvj1234
Participant
Participant

I need som code to assigning a material to a part in VBA.

 

can anyone help.

 

Dim oApp As Inventor.Application  

Set oApp = ThisApplication    

Dim oDoc As PartDocument  

Set oDoc = oApp.ActiveDocument    

Dim oPropsets As PropertySets  

Set oPropsets = oDoc.PropertySets

 Dim Mat As String    

Mat = oPropsets.Item("{32853F0F-3444-11d1-9E93-0060B03C1CA6}").ItemByPropId(kMaterialDesignTrackingProperties).Value    

Debug.Print Mat    

Mat = "Hastelloy"    

oPropsets.Item("{32853F0F-3444-11d1-9E93-0060B03C1CA6}").ItemByPropId(kMaterialDesignTrackingProperties).Value = Mat     Debug.Print oPropsets.Item("{32853F0F-3444-11d1-9E93-0060B03C1CA6}").ItemByPropId(kMaterialDesignTrackingProperties).Value

 

but the material is not changed .....

0 Likes
Accepted solutions (1)
590 Views
1 Reply
Reply (1)
Message 2 of 2

jdkriek
Advisor
Advisor
Accepted solution

PartDocument.ComponentDefinition.Material will change the material of the document:

 

Public Sub AssignMat()
    Dim oPart As PartDocument
    Set oPart = ThisApplication.ActiveDocument
    Dim oMat As Material
    'Name of material
    Set oMat = oPart.Materials.Item("Hastelloy")
    oPart.ComponentDefinition.Material = oMat
End Sub
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes