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

Had some issues with the code you guys had wrote, my brother does a lot of coding and helped me write this:

Works great!

 

Dim assetLib As AssetLibrary  = ThisApplication.AssetLibraries.Item("Inventor Material Library")
ThisApplication.ActiveMaterialLibrary = assetLib
mat = InputBox("Material", "Change Part Material")
userChoice = InputRadioBox("Defined the scope", "This Document", "All Open Documents", True, Title := "Defined the scope")
 If userChoice Then
 
iProperties.Material = mat
Else
 
For Each pDoc As PartDocument In ThisApplication.Documents.VisibleDocuments
 
If ThisApplication.ActiveDocumentType <> kPartDocumentObject Then
Call MsgBox("This VBA macro only works on Parts.", vbCritical, "Wrong Document Type")
Continue For
 
End If
 
Dim MaterialName As String
MaterialName = mat
 
Try
 
    Dim localMaterial As MaterialAsset = pDoc.MaterialAssets.Item(MaterialName)
 
Catch
 
    Dim libMaterial As MaterialAsset = assetLib.MaterialAssets.Item(MaterialName)
 
    libMaterial.CopyTo(pDoc)
 
End Try
 
Try
 
    pDoc.ActiveMaterial = pDoc.MaterialAssets.Item(MaterialName)
 
Catch ex As Exception
 
    Call MsgBox("Failed to set material, Error:" & ex.message, vbCritical, "Error")
 
End Try
 
Next
 
End If