ZBrushCentral

compare two strings / vars. ==

can anybody offer any hints on how this is done in zScript ?

i run a note on two vars and they ( as i have set ) return the same string. yet when i attempt to reference them in a conditional :

[IF, string0 == string1,

for example. i’m far from the expected behaviour

Assuming two string variables, str1 and str2, this is one way to do it:

[If,([StrLength,str1]==[StrLength,str2])&&([StrFind,str1,str2]>-1),
[Note,“The Strings are Equal”]
,
[Note,“The Strings are NOT Equal”]
]

HTH,

hey marcus. thanks heaps for your reply. that totally works so far as comparing the strings. problem is that specific block seems to be running as some kind of ’ command '. in that it runs automatically when the script is loaded. so i can’t use it within the context of any other macro ( any macro with that block in it doesn’t even appear in the macro palette. comment it out and the macro becomes available again ). any thoughts ?

Can you post the code that you have? I should then be able to see what’s happening. (My example above should be wrapped inside the button code for a macro or plugin. Any code that is outside a button will run when ZBrush starts up.)

//ZBRUSH MACRO - Recorded in ZBrush version 4.2
[IButton,???,"Press to run this macro. Macros can be aborted by pressing the ëescí key.",
[IShowActions,0]
[IConfig,4.2]
//
//define vars
 [VarDef, SubToolTitle_0,""]
 [VarDef, SubToolTitle_1,""]
//
//set var0 to current tool
 [VarSet,SubToolTitle_0,[IgetTitle, Tool:Current Tool]]
//
//do select. . . ( thanks marcus civis )
 [IPress,Preferences:Edit:Auto Select SubTool]
 [IKeyPress,1064,[CanvasClick,[MouseHPos],[MouseVPos]]]
 [IUnPress,Preferences:Edit:Auto Select SubTool]
//
//and then set var1 to that selection
 [VarSet,SubToolTitle_1,[IgetTitle, Tool:Current Tool]]
//[If,([StrLength,SubToolTitle_1]==[StrLength,SubToolTitle_0])&&([StrFind,SubToolTitle_1,SubToolTitle_0]>-1)
//,   
// [Note, SAME SAME"]
//,   
// [Note, "DIF DIF"]
//]
  
//
//hide var1
 [IModSet,[StrMerge,"Tool:SubTool:",SubToolTitle_1],1]
//
//switch back to var0
//THANKS BUNNIES ( http://www.funkybunnies3d.com/ )
 [IPress,Tool:SubTool:List All]
 [IPress,[StrMerge,"PopUp:",SubToolTitle_0]]
// 
//PIOW !!
]

that’s all related to the other thread i have in here. it all functions well enough to achieve what i wanted 'cept it understandably bugs out whenever it tries to run and there’s no switching ( selecting same / current tool. or null space ). so my intention is if in that case to run a macro from the subtool master to unhide all. this is where i was trying to compare the two vars ( i have no idea in this case if these are even stored as strings but this is the full context )

if i can get that all together under one macro’ed hotkey it’ll be a sweet workflow enhancement

You’ve missed the first quotation mark in the [Note, SAME SAME"]. This is probably causing the error.

I’ve used the method for my answer to your other question, and that works well for me.

oh man that is embarrassing. thanks for pointing that out marcus

well this little script seems good to go then. awesome. in checking what the show/hide subtools spits out i might as well just write a loop for unhiding ( though there might be a show all meta command silver bullet but. . . not by the looks )s

stay tuned for when i smork that up and come running for help

You could probably save a variable list of the previously clicked subtools and then restore them one by one if you hit the hotkey with the cursor off the model but you’d need to make allowance for the fact that variables assignments are lost if the zscript needs to be reloaded (which happens if another macro/plugin has been used).

Show/hide of all subtools is fairly straightforward. This code will toggle all on/off if the cursor is over the selected subtool (or the background):


         //do select. . . 
	 
         [IPress,Preferences:Edit:Auto Select SubTool]
	 [IKeyPress,1064,[CanvasClick,[MouseHPos],[MouseVPos]]]
	 [IUnPress,Preferences:Edit:Auto Select SubTool]
	 
	//
	//and then set var1 to that selection
	 [VarSet,hideSubT,[IGetTitle, Tool:Current Tool]]
	//hide var1
	[If,([StrLength,hideSubT]==[StrLength,activeSubT])&&([StrFind,hideSubT,activeSubT]>-1),
	//active subtool - toggle visibility for all subtools	
	[VarSet,wid,[IWidth,[StrMerge,"Tool:SubTool:",activeSubT]]]
	[IClick,[StrMerge,"Tool:SubTool:",activeSubT],wid-5,5] 		
	,//if it's not the active subtool
	 [IModSet,[StrMerge,"Tool:SubTool:",hideSubT],1]
	]

Note: for some reason I couldn’t work out, with this code addition the auto select will stop working if the press/unpress of Preferences:Edit:Auto Select SubTool is removed. If you want to reset the option to on then you can add a further line to press Preferences:Edit:Auto Select SubTool again.

HTH,

//ZBRUSH MACRO - Recorded in ZBrush version 4.2
[IButton,???,"Press to run this macro. Macros can be aborted by pressing the ëescí key.",
[IShowActions,0]
[IConfig,4.2]
//
//define vars
 [VarDef, SubToolTitle_0,""]
 [VarDef, SubToolTitle_1,""]
//set var0 to current tool
 [VarSet,SubToolTitle_0,[IgetTitle, Tool:Current Tool]]
//do select. . . ( thanks marcus civis )
 [IPress,Preferences:Edit:Auto Select SubTool]
 [IKeyPress,1064,[CanvasClick,[MouseHPos],[MouseVPos]]]
 [IUnPress,Preferences:Edit:Auto Select SubTool]
//and then set var1 to that selection
 [VarSet,SubToolTitle_1,[IgetTitle, Tool:Current Tool]]
//do check is same ( or ' null ' ). . . ( thanks marcus civis )
[If,([StrLength,SubToolTitle_1]==[StrLength,SubToolTitle_0])&&([StrFind,SubToolTitle_1,SubToolTitle_0]>-1)
,   
//if true > running that dirty emulation of ui clicks. lifted from another script. . . ( thanks marcus civis )
 [VarSet,btnWidth,[IWidth,[StrMerge,"Tool:SubTool:",SubToolTitle_0]]-10]//get the width of the button less 10 pixels
 [IClick,[StrMerge,"Tool:SubTool:",SubToolTitle_0],btnWidth,5]//click the subtool 'eye' < once
 [IClick,[StrMerge,"Tool:SubTool:",SubToolTitle_0],btnWidth,5]//click the subtool 'eye' < twice
,   
//if false > run hiding off code
//hide var1
 [IModSet,[StrMerge,"Tool:SubTool:",SubToolTitle_1],1]
//switch back to var0
//THANKS BUNNIES ( http://www.funkybunnies3d.com/ )
 [IPress,Tool:SubTool:List All]
 [IPress,[StrMerge,"PopUp:",SubToolTitle_0]]
//ends
]
//PIOW !!
]

damn. wish i’d noticed your post before i’d toiled away. in any case. that grubby hack above seems to work pretty well without any faults that i’ve found ( functionally ) thus far. i’ll look further at yours marcus and hopefully bring together a more elegant solution. but as is. this seems to brute force its way through

this will really speed things up in the ’ viewport '. sweet !

Works well, and your solution to re-selecting the active subtool is a lot simpler than mine. One issue I did encounter was that if all the subtools are invisible (and the selected subtool has its eye icon off) the toggle fails. I expect this is because you click the subtool twice. You could put a test in there to avoid that.

yep. broke it. i guess the ’ beauty ’ of this solution is i’ll so rarely ever need to visit the subtool palette now to create a situation where that subtool would have it’s eye turned off. but yeah. if that does happen at least i’ll know what the ( manual ) fix is

my first attempt at doing it that way was through trying to emulate what was happening when i recorded a macro of the process :

[IModSet,Tool:SubTool:currentSubToolName,1]
[IModSet,Tool:SubTool:currentSubToolName ,17]

and just replacing the hard written subtool name with the var ( StrMerge etc ). just flat out had no effect. even though the eye icon was changing

is there the equivalent of some kind of ’ type casting ’ needed to use variables in different contexts ? ( as in when it fails to compare the two vars in their simplest form when yet they’re returning exactly the same values in a Note )

Not really. You define the type in the declaration but if you declare a variable [VarDef,myString,""] and then assign a number to it [VarSet,myString,“123”] (note the quote marks), ZBrush will automatically cast it as a numeral when needed.

Sometimes using [Val,myVar] is necessary, for example when adding the Loop variable n to a string using StrMerge:

[Loop,10,
[VarSet,subToolPath,[StrMerge,"Tool:Sub Tool ",[Val,n]]]
,n]

But strings are not evaluated that way and will return 0, so you can’t use it to test for equality between strings.