Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
in reply to: Anonymous

The iLogic code seems to work w/o issues.

 

http://adndevblog.typepad.com/manufacturing/2013/07/inventor-2014-api-set-part-material.html

 

Sub Main()

Dim i As Integer
Dim oApp As Inventor.Application
oApp = ThisApplication

If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("Active document is NOT an assembly document!","DEBUG ME")
    Exit Sub
End If

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim strMaterialNameToChange As String
strMaterialNameToChange = "Aluminum 6061"

Dim strNewMaterialName As String
strNewMaterialName =  "Steel, Galvanized" '"Aluminum 6061"

Dim oMat As Asset

' MessageBox.Show("ASSEMBLY DOCUMENT!","iLogic Debug")

Dim oOcc As ComponentOccurrence
Dim oPartDoc As PartDocument
Dim newMat As Asset

For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
    oPartDoc = oOcc.Definition.Document
    
   For i = 1 To oPartDoc.Assets.Count
       If oPartDoc.Assets.Item(i).DisplayName = strNewMaterialName Then
           oMat = oPartDoc.Assets.Item(i)
           bMatFound = True
           ' MessageBox.Show("MATERIAL FOUND!","iLogic Debug")
           Exit For
       End If
   Next i
    
    If oPartDoc.ActiveMaterial.DisplayName = strMaterialNameToChange And oOcc.Definition.IsContentMember = False Then
        ' MessageBox.Show("IN if/then","iLogic Debug")
        oPartDoc.ActiveMaterial = oMat
    End If
    
Next

Call oDoc.BrowserPanes.ActivePane.TopNode.DoSelect
 
End Sub