ZBrushCentral

How to check if file was imported or not

I have created a simple script to automate applying a texture map like so

[ISubpalette, Zscript:CustomScripts]
[IButton,Zscript:CustomScripts:LoadImage,"Press to run this cool macro. Macros can be aborted by pressing the esc key.",

[IPress,Texture:Import]
[ISet,Texture:Item Info,[IGetMax,Texture:Item Info]]

[VarDef, finalName, ""]
[VarSet,finalName,[IGetTitle,Texture:Item Info]]
[VarSet,finalName,[StrExtract,finalName,0,[StrLength,finalName]-2]]

[ISet,Texture:Item Info,[IGetMax,Texture:Item Info]]
[IPress,Texture:Flpv]
[IPress,Tool:Texture Map:TextureMap]
[IClick,[StrMerge,“PopUp:”,finalName]]

]

But the problem is after the import texture dialog box opens up in zbrush, if I press cancel and not import any texture the macro still runs and it’ll flip the already applied texture. So my question is, is there anyway to check if a texture file was imported or not?
I am hoping there is someway to detect if I press CANCEL in the import dialog box

Something like this -
If (FileImported == yes)
then Run the macro
Else
dont do anything

Please Help!

Welcome to ZBC! :slight_smile:

Just get the Max value of the Texture:Item Info slider before you do the Texture:Import. That way you can check to see if a texture has been added as the new Max will be one more than before. If it’s the same you’ll know that the user cancelled and you can exit your script.

Thank you so much Marcus! It was just what I was looking for and that fixed it and made the script complete :smile:

1 Like

Just in case anyone needs it, here is the final code
You might have to modify how you want to place it in zbrush though

//zscript to import a texture, flip it and apply to selected subtool
[ISubpalette, Zscript:CustomScripts]
[IButton,Zscript:CustomScripts:LoadImage,"Press to run this cool macro. Macros can be aborted by pressing the esc key.",

[VarDef, initialValue, 0]
[VarDef, changedValue, 0]

[VarSet, initialValue , [IGetMax, Texture: Item Info]]

[IPress,Texture:Import]

[VarSet, changedValue , [IGetMax, Texture: Item Info]]

[If,  initialValue == changedValue ,
	[Exit]
	
	, //else

	[ISet,Texture:Item Info,[IGetMax,Texture:Item Info]]

	[VarDef, finalName, ""]
	[VarSet,finalName,[IGetTitle,Texture:Item Info]]
	[VarSet,finalName,[StrExtract,finalName,0,[StrLength,finalName]-2]]

	[ISet,Texture:Item Info,[IGetMax,Texture:Item Info]]
	[IPress,Texture:Flpv]
	[IPress,Tool:Texture Map:TextureMap]
	[IClick,[StrMerge,“PopUp:”,finalName]]
	]

]

That’s great, and thanks for sharing your code! :+1: