08-09-2023
12:08 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-09-2023
12:08 PM
Patched up a different block by borrowing some code from Andrii's post here to try and do the same thing, but I'm running into the same Member not found error, unfortunately. The error is originating from line 51 of the new block.
Option Explicit On
Sub Main()
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oOccurrence As ComponentOccurrence
' Get the material name to apply to all components
Dim materialName As String = "Stainless Steel"
Dim oAsset As Asset
Dim oAL_List As New ArrayList
Dim lib_List As New ArrayList
For Each oAL As AssetLibrary In ThisApplication.AssetLibraries
If InStr(oAL.DisplayName , "Material") <> 0 Then
oAL_List.Add(oAL.DisplayName)
End If
Next
Dim oALSelect As String = InputListBox("Select Asset Library", oAL_List, oAL_List(0), "Change Part Material", "Available Selections")
If oALSelect Is Nothing Then Exit Sub
Dim oLib As AssetLibrary =ThisApplication.AssetLibraries(oALSelect)
For Each libAsset In oLib.MaterialAssets
lib_List.Add(libAsset.DisplayName)
Next
lib_List.Sort
Dim oLibAssetSel As String = InputListBox("Select Material", lib_List, lib_List(0), "Change Part Material", "Available Selections")
If oLibAssetSel Is Nothing Then Exit Sub
For Each oAssetlib In ThisApplication.AssetLibraries
For i As Integer = 1 To oAssetlib.MaterialAssets.Count
If oAssetlib.MaterialAssets.Item(i).DisplayName = materialName Then
oAsset = oAssetlib.MaterialAssets.Item(i)
GoTo NextStep
End If
Next
Next
NextStep :
If oAsset Is nothing Then Exit Sub
' Iterate through each component occurrence in the assembly
For Each oDoc As Document In oAsmDoc.AllReferencedDocuments 'Traverse all referenced documents
If oDoc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") _ 'Frame generator component
AndAlso oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject _'Part
AndAlso oDoc.IsModifiable _ 'Modifiable (not reference skeleton)
AndAlso oAsmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc).Count > 0 'Exists in assembly (not derived base component)
Dim currentMaterialName As String = oDoc.ActiveMaterial.DisplayName
If Not String.IsNullOrEmpty(currentMaterialName) Then
If currentMaterialName <> oAsset.DisplayName Then
' Set the material for the component occurrence
oDoc.ActiveMaterial = oAsset
End If
End If
End If
Next
' Save the changes
oAsmDoc.Update()
oAsmDoc.Save()
End Sub