Ilogic - Error setting occurence Appearance ( color )

Ilogic - Error setting occurence Appearance ( color )

Curtis_Waguespack
Consultant Consultant
647 Views
2 Replies
Message 1 of 3

Ilogic - Error setting occurence Appearance ( color )

Curtis_Waguespack
Consultant
Consultant

Can anyone help me figure out why this doesn't work?  It's based off of the following API example:

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2018/ENU/Inventor-API/files/Se...

 

I get an error with this line:

oOccurrence.Appearance = localAsset	

 

Here's the full rule:

 

' Get the active document.  Assumes a part document is active.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oDoc.ComponentDefinition


oColor = Parameter("Color_List")
oRun = Parameter("Component_List")

Dim localAsset As Asset

Try 
	localAsset = oDoc.Assets.Item(oColor)
Catch

	Dim assetLib As AssetLibrary
	assetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
	
	Dim libAsset As Asset
	libAsset = assetLib.AppearanceAssets.Item(oColor)
	
	' Copy the asset locally.
	localAsset = libAsset.CopyTo(ThisApplication.ActiveDocument)
	
End Try


For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef)  	
	If oOccurrence.Name = oRun Then	
		MessageBox.Show("Component Name: " & oOccurrence.Name _
		& vbLf & "Color: " & localAsset.DisplayName , "iLogic")
		oOccurrence.Appearance = localAsset					
	End If
Next

 

And attached is an example file set, with the rule in place.

 

Thanks in advance!

Curtis

EESignature

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

sajith_subramanian
Autodesk Support
Autodesk Support
Accepted solution

Hi Curtis,

 

Just declaring the occurrence as its respective type, that is as a ComponentOccurence seems to make it work for me.

 

That is

 

For Each oOccurrence  As ComponentOccurrence  In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef)  	

 

Could you try it out and let me know if it works.

 

Regards,

Sajith


Sajith Subramanian
Autodesk Developer Network
Message 3 of 3

Curtis_Waguespack
Consultant
Consultant

Hi sajith.subramanian,

 

Thanks! That is what I was missing. Smiley Embarassed

 

Thanks again,
Curtis

EESignature

0 Likes