Change appearance colour with iLogic

Change appearance colour with iLogic

gerrardhickson
Collaborator Collaborator
197 Views
2 Replies
Message 1 of 3

Change appearance colour with iLogic

gerrardhickson
Collaborator
Collaborator

Hi All,

I have a problem with the function below. The line `oAsset.Item("generic_diffuse").Value = assetColor` fails with the following error: "Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))" indicating that the .Value value is not available.

From what I can tell, it's doing the same thing all the other examples are doing, but it's just not working.

' Function to check and create appearance asset
Function GetOrCreateAppearanceAsset(ByVal assetName As String, ByVal assetColor As Color) As Asset
	Dim oAssetLib As AssetLibrary = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
	Dim oAssets As Assets = ThisApplication.ActiveDocument.Assets 'oAssetLib.AppearanceAssets

	' Check if asset already exists
	Dim oexistingasset As Asset
	For Each oexistingasset In oAssets
		If oexistingasset.DisplayName = assetName Then
			GetOrCreateAppearanceAsset = oexistingasset
			Exit Function
		End If
	Next

	' Create new appearance
	Dim oAsset As Asset = oAssets.Add(kAssetTypeAppearance, "Generic", _
	assetName, assetName)

	' Set color
	oAsset.Item("generic_diffuse").value = assetColor

	GetOrCreateAppearanceAsset = oAsset
End Function

 

Any suggestions?

 

 

0 Likes
Accepted solutions (1)
198 Views
2 Replies
Replies (2)
Message 2 of 3

Stakin
Collaborator
Collaborator
Accepted solution
Sub main
	Dim oColor As Color
		RGB1 = Math.Round(Rnd() * 255)
		RGB2 = Math.Round(Rnd() * 255)
		RGB3 = Math.Round(Rnd() * 255)		
	oColor = ThisApplication.TransientObjects.CreateColor(RGB1, RGB2, RGB3)
	Dim oName As String="SomeNew003"
	Dim oAss As Asset
	oAss = GetOrCreateAppearanceAsset(oName, oColor)
	MessageBox.Show(oAss.Name, "Title")
End Sub	
Function GetOrCreateAppearanceAsset(ByVal oName As String, ByVal oColor As Color) As Asset
	Dim oAssets As Assets = ThisApplication.ActiveDocument.Assets 
	Dim oAsset As Asset
	Try 
		oAsset= oAssets.Item(oName )
	Catch
		 oAsset = oAssets.Add(AssetTypeEnum.kAssetTypeAppearance, "Generic", , oName)
		Dim oApColor As ColorAssetValue = oAsset.Item("generic_diffuse")			
		oApColor.Value = oColor	
	End Try
	Return oAsset 
End Function
0 Likes
Message 3 of 3

gerrardhickson
Collaborator
Collaborator

Nice one - I see where I went wrong.

For anyone else reading - line 19 and 20 is the bit that matters.

0 Likes