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

Your help is much appreciated.

I've modified the code a bit, namely removing this line entirely, as it was conflicting with some the code above it:

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument

 

I've also remedied library setting issue by removing the second line:

 

					Dim assetLib As AssetLibrary  = ThisApplication.AssetLibraries.Item(oLib)

 

Now I'm just left with one error, and it is generated whenever the rule runs this line of code:

If I edit out this line, the code runs but doesn't set the material of the Frame Generator components.

 

oDoc.ActiveMaterial = oDoc.MaterialAssets.Item(MaterialName)

 

 

Screenshot 2023-08-09 103510 Member Not Found.jpg

I've been looking around online to see if I can find some documentation on how to clear this Member not found error, but I've not come across much.

 

This is what my block looks like now:

 

Option Explicit On

Sub Main()
	Dim oADOC As Inventor.Document = ThisDoc.ModelDocument
	If oADOC.DocumentType <> kAssemblyDocumentObject Then
	MessageBox.Show("This rule cannot be executed in this file type.", "iLogic")
	Exit Sub
	End If

	Dim oAsm As AssemblyDocument = ThisDoc.Document
	Dim oTransaction As Transaction = ThisApplication.TransactionManager.StartTransaction(oAsm, "FG Member Material Changer") 'Make this a single transaction

	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 oDoc As Document In oAsm.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 oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc).Count > 0 'Exists in assembly (not derived base component)

					Dim MaterialName As String = oLibAssetSel
				
					Try
					Dim localMaterial As MaterialAsset = oDoc.MaterialAssets.Item(MaterialName)
					Catch
					Dim libMaterial As MaterialAsset = oLib.MaterialAssets.Item(MaterialName)
					libMaterial.CopyTo(oDoc)
					End Try
					
					oDoc.ActiveMaterial = oDoc.MaterialAssets.Item(MaterialName)

				iLogicVb.UpdateWhenDone = True
			
		End If
	Next
	oTransaction.End
End Sub