ZBrushCentral

Integer RGB values

I’m trying to convert RGB values into an int (and back again), using the example from here. and as mentioned in this question.

However, the error I get is : Specified item within List is em…
zb
Which is truncated - so I’m at a double loss as how to continue.

I’ve written a version in Python fine, I’m just having trouble with the Zscript version.

Also whilst I’m here, it it possible to write full errors to a text file (or some other workaround)??

Well if you remembered to add your code it would help!

I’ve got a bad feeling that color is a reserved word and there were complications therein.

This works fine:

    [IButton, "R G B", "Get RGB value",

	[VarDef, col, 0]
	[VarDef, Red, 0]
	[VarDef, Green, 0]
	[VarDef, Blue, 0]
	[VarDef, msg,  ""]

	[VarSet, msg,  ""]
	[VarSet, col,[IGet,Color:Main Color]*65536] // 16777215
	[VarSet, Red,((col & 0xFF0000) >> 16)]
	[VarSet, Green,((col & 0x00FF00) >> 8)]
	[VarSet, Blue,(col & 0x0000FF)]
	[VarSet, msg, [StrMerge, msg, col, " - RGB: ", Red, ", ", Green, ", ", Blue]]
	[Note, msg, 2]

]/*End of ZScript*/

Can you post the code that doesn’t work?

That error generally means that you have used a global variable without using [VarDef] to declare it. That means you may have set the variable value in one place but it won’t carry over to another place (such as if you have two buttons, one which sets “Red” and another which uses the value of “Red”).

This what I had, when it didn’t work.

// rgb.txt

[IButton, "R G B error", "Get RGB value",

	[VarDef, color, 0]
	[Var, Red] // throws error
	[Var, Green]
	[Var, Blue]
	[VarDef, RGBint, 0]
	[VarDef, msg,  ""]

	// Int to RGB
	[VarSet, msg,  ""]
	[VarSet, color,[IGet,Color:Main Color]*65536] // 16777215
	[VarSet, Red,((color & 0xFF0000) >> 16)]
	[VarSet, Green,((color & 0x00FF00) >> 8)]
	[VarSet, Blue,(color & 0x0000FF)]
	[VarSet, msg, [StrMerge, msg, color, " - RGB: ", Red, ", ", Green, ", ", Blue]]
	[Note, msg, 2]


]/*End of ZScript*/

Which re-produces the error above,

but I was getting confused and had this code at one point:

[IButton, "R G B error", "Get RGB value",

	[VarDef, colour, 0]
	[VarDef, Red, 0] 
	//[Var, Green]
	//[Var, Blue]
	[VarDef, RGBint, 0]
	[VarDef, msg,  ""]

	// Int to RGB
	[VarSet, msg,  ""]
	[VarSet, colour,[IGet,Color:Main Color]*65536] // 16777215
	[VarSet, Red,((color & 0xFF0000) >> 16)]
	//[VarSet, Green,((color & 0x00FF00) >> 8)]
	//[VarSet, Blue,(color & 0x0000FF)]
	//[VarSet, msg, [StrMerge, msg, color, " - RGB: ", Red, ", ", Green, ", ", Blue]]
	//[Note, msg, 2]


]/*End of ZScript*/

Yes, [Var,Red] means “the value of the variable called ‘Red’”. As, at that point in your script the variable called Red hasn’t been defined, ZBrush throws an error. (The full text of the message is something like “ZScript Note: Specified item within the List is empty”.)

Thank for your help.

I was confused, :confounded: but I tried Var as I got an error saying that a variable was ambiguous. So, naturally I tried Var instead of VarSet.

1 Like