Get RGB color from active appearance to color Excel cell

tom89Y38
Enthusiast

Get RGB color from active appearance to color Excel cell

tom89Y38
Enthusiast
Enthusiast

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!

0 Likes
Reply
Accepted solutions (1)
269 Views
2 Replies
Replies (2)

J-Camper
Advisor
Advisor
Accepted solution

@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.

0 Likes

_dscholtes_
Advocate
Advocate

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').

0 Likes