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: MechMachineMan

I thought that would do it as well but I get this error

 

 

Error in rule: change, in document: Assembly1

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

 

I have put a message box to check/ debug that it is not the rest of the code. all that works fine up until the message box ( I have commented it out.

 

 

 

'define the assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument

'define the appearance library
Dim oLib As AssetLibrary
oLib = ThisApplication.AssetLibraries("Autodesk Appearance Library")

'make sure colors are in assembly doc
Dim libAsset As Asset
libAsset = oLib.AppearanceAssets.Item("Smooth - Red")
Try 
	localAsset = libAsset.CopyTo(oAssyDoc)
Catch
'catch error if it's already local
End Try

libAsset = oLib.AppearanceAssets.Item("Smooth - Black")
Try 
	localAsset = libAsset.CopyTo(oAssyDoc)
Catch

End Try

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAssyDoc.ComponentDefinition
 
Dim oOcc As ComponentOccurrence
Dim oAsset As Asset

Dim oSS As SelectSet
oSS = oAssyDoc.SelectSet

Dim oSelCollection As New Collection
For Each oItem In oSS
	oSelCollection.Add(oItem)
Next

'set color overrides of components at the assembly level
For Each oOcc In oAsmCompDef.Occurrences.AllLeafOccurrences
	Dim MatchFound As Boolean = False
	
	For Each oItem In oSelCollection
		If oOcc.Equals(oItem) Then
			MatchFound = True
		End If
	Next
	' this works fine till this point' MessageBox.Show("Message", "Title")

	If MatchFound = True Then
		oAsset = oAssyDoc.Assets.Item("Smooth - Red")


	End If
	oOcc.Appearance = oAsset
Next 

 

 

Kind Regards