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 code below seems to work fine with an assembly file.

 

Sub Main()

Dim oApp As Inventor.Application
oApp = ThisApplication

If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
	MessageBox.Show("ERROR - Active Document is not an assembly document!","iLogic Error")
	Exit Sub
End If

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
MessageBox.Show("ASSEMBLY DOCUMENT!","iLogic Debug")

Dim strMaterialNameToChange As String
strMaterialNameToChange = "Aluminium"

Dim strNewMaterialName As String
strNewMaterialName = "Steel"

Dim oOcc As ComponentOccurrence
For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences
   If oOcc.Definition.Material.Name = strMaterialNameToChange And oOcc.Definition.IsContentMember = False Then
         oOcc.Definition.Material = oDoc.Materials.Item(strNewMaterialName)
   End If
Next

End Sub