10-17-2023
02:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-17-2023
02:47 PM
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