ZBrushCentral

Texture toggle

I am trying to make a plugin that toggles between texture off and a texture i load as a reference on the objet i am working on(with flat shader). I managed to make it work as a script, but when i try to make it a plug-in it doesn’t work anymore. I need it as a plugin because i want to put a shortcut on it.

Here is the code if anybody has some time…

 [ISubPalette,Zplugin:ToggleTexture] 

 

//---------- Set the texture to use as a reference

[IButton,"Zplugin:ToggleTexture:Set Ref","Set reference texture",

[IConfig,2.0]

//[ISetHotkey,Zplugin:MorePlugs:Toggle Texture ,'1']



[VarDef,caleTextura,""]

[VarDef,numeTextura,""]

[VarSet, caleTextura,

[FileNameAsk,.psd,]

]

[FileNameSetNext,caleTextura]

[IPress,Texture:Import]

[MemCreate ,ctSetReferenceText ,64]

[If, [MemGetSize, ctSetReferenceText] != 64, // if memory block is not 64 bytes in size then report it.

[Note, "Memory block not created"]

]



[VarSet,numeTextura,

[FileNameExtract, caleTextura, 2]

]

[MemWriteString ,ctSetReferenceText ,numeTextura ,0 ]



//[NoteBar, numeTextura,]



[IShowActions,0]

,,76,]

//---------- Switch between texture off and the reference texture(with flat shader)

[ISwitch,"Zplugin:ToggleTexture:ToggleTexture",,

"Toggle Texture",

[IConfig,2.0]



[VarDef,numeTextura,""]

[MemReadString ,ctSetReferenceText ,numeTextura ,0]



[IPress,Texture:Txtr00]

[IPress,

[StrMerge,"Texture:",numeTextura]

]

[IPress,Material:FastShader]

[IPress,Material:Flat Color]

,

[IConfig,2.0]



[VarDef,numeTextura,""]

[MemReadString ,ctSetReferenceText ,numeTextura ,0]



[IPress,Material:Flat Color]

[IPress,Material:FastShader]

[IPress,

[StrMerge,"Texture:",numeTextura]

]

[IPress,Texture:Txtr00]

,,75

]


Claudiu

Hi Claudiu,

If I understand correctly, what you are trying to do can be done a bit more simply. This code just uses a button to load a texture, then when one is loaded will swap that with no texture. The hotkey can be set in the button code (I’ve indicated where) - I’ve used ‘1’. You’ll notice that I have used the keyboard code 49 : if you want to change the hotkey then you can get the codes by pressing the relevant key and looking at the Preferences:Utilities:ViewKeyboardStatus slider.

Switches don’t work correctly when they are used in plugins, which is why you were having problems.

A couple of points on scripting: declare your variables at the start of your code (and only once), using [VarSet to change their value later. And the best place to put the [IConfig is at the start too.

 

[IConfig,2.0]

//if there isn't a memory block, create one:
[If,[MemGetSize,ctSetRefNumber],,
[MVarDef,ctSetRefNumber,1,0]]//one variable needed
	
	
[ISubPalette,Zplugin:ToggleTexture] 

//---------- Set the texture to use as a reference

[IButton,"Zplugin:ToggleTexture:ToggleTxtr","Set reference texture and toggle ON/OFF",

[IShowActions,0]//temporarily switches off 'Show Actions'

[If,[MVarGet,ctSetRefNumber,0],//if the memory variable is >0
	//do nothing
,//else - memory variable is 0, so load texture:

[IPress,Texture:Import]//import a texture
[MVarSet,ctSetRefNumber,0,[IGet,"Texture:Item Info"]]//stores the number of just loaded texture
]//end if

[If,[IGet,"Texture:Item Info"],//if the texture is not '0' then do this:
	[ISet,"Texture:Item Info",0]// select no texture
	[ISet,"Material:Item Info",1]//selects the Fast Shader material slot
	[NoteBar,""]//clears NoteBar
	
,//else do this:
	
	[ISet,"Texture: Item Info",[MVarGet,ctSetRefNumber,0]]//sets loaded texture (number in memory)
	[ISet,"Material:Item Info",0]//selects Flat color material
	[NoteBar,[StrMerge,"\CFFFFFFTexture loaded : ",[IGetTitle,"Texture: Item Info"]]]//displays texture name in NoteBar
]//end if

,,76,49,,19]//49 is the hotkey code for number key '1'

HTH,

Thank you for your time Marcus. That’s exactly what i need. I started using it today and it helps a great deal.

This was my second zscript and i thought i was missing something with the ISwitch. Actually, the first attempt to make the plugin was using a button, but i discovered the switch and thought it’s better…

Thanks again,
Claudiu

Is this plugin still working in ZBrush3.1 ?
I’m at work at the moment and can’t test it :frowning:

if it is working, it would be awesome, because I’m searching for a plugin like this for a long time :slight_smile:

Use this version. I’ve made a couple of small changes:
There are two buttons:
ToggleTxtr - assign a hotkey to this using Ctrl+click on the button, then the following will work:

Press the button:
If no texture has been stored it will store the current texture if one is selected, otherwise it will ask for a file.

Press the hotkey:
the texture is toggled off or on. If no texture has been stored it will store the current texture if one is selected, otherwise it will ask for a file.

SetMat button:
This sets the material for when the texture is toggled OFF. If none is set it will use the default Red Wax.

Installation:
Unzip and put the .zsc file in your ZStartup\ZPlugs folder. The code is included if you’re interested.