Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get RGB color from active appearance to color Excel cell

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
tom89Y38
183 Views, 2 Replies

Get RGB color from active appearance to color Excel cell

Hi,

 

I wrote an iLogic rule to collect data from an assembly that's very useful to my colleagues on the shop floor.

One of the functions of the rule is to create an overview like this, it checks all the appearances, and overrides, sums the surface area's and weights, etc..

 

Example assembly (contains sub assembly, 1 weld assembly with color override, 1 weld assembly without color override, 1 part)

tom89Y38_1-1718717595611.png

tom89Y38_2-1718717630980.png

 

The problem i'm facing: when a weld assembly has a color override, the thumbnail does not have the correct color. (This is normal because the color is given at a higher level).

Therefore I was thinking to have a work around and get the RGB value of the active appearance of that color override and color the corresponding Excel cell.

I just can't figure out how to get the RGB color values of the active appearance on a correct way.

 

In my code I'm already looping through all component occurrences like this

Sub ProcessWeldAssembliesWithOverrides(oAssembly As AssemblyDocument) 'subprogramma
		' Loop door de alle componenten in de assembly
		For Each oComp As ComponentOccurrence In oAssembly.ComponentDefinition.Occurrences

So it would be great if I could get the RGB values of oComp in that same loop.

 

Any ideas to help me out?

 

Thanks!

2 REPLIES 2
Message 2 of 3
J-Camper
in reply to: tom89Y38

@tom89Y38,

 

ComponentOccurrence Objects have an Appearance Property which should give you the asset at assembly level instead of part level. Then once you have that asset, you can use something like this to extract the color:

Dim CurrentAppearance As Asset = ThisDoc.Document.ActiveAppearance

For Each value As AssetValue In CurrentAppearance
	If value.ValueType <> AssetValueTypeEnum.kAssetValueTypeColor Then Continue For
	Dim MessageTitle As String = CurrentAppearance.DisplayName & ": " & value.DisplayName
	Dim ColorVlaue As ColorAssetValue = value
	Dim messageText As String = ""
	If ColorVlaue.HasMultipleValues
		For Each c As Color In ColorVlaue.Values
			
			If messageText <> "" Then messageText = messageText & vbCrLf
			messageText = messageText & String.Format("Red: {0} | Green: {1} | Blue: {2} | Opacity: {3}", c.Red, c.Green, c.Blue, c.Opacity).ToString
		Next
	Else
		messageText = String.Format("Red: {0} | Green: {1} | Blue: {2} | Opacity: {3}", ColorVlaue.Value.Red, ColorVlaue.Value.Green, ColorVlaue.Value.Blue, ColorVlaue.Value.Opacity).ToString
	End If
	MessageBox.Show(messageText, MessageTitle)
Next

 

Example code above is to be run in a part file, but CurrentAsset can be set to oComp.Appearance.

Message 3 of 3
_dscholtes_
in reply to: tom89Y38

In addition to @J-Camper

The above code will probably show you that there are two ColorAssetValues per Asset. You're looking for the one with .DisplayName  'color' (opposed to the one displaynamed 'Tint').

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report