ZBrushCentral

Setting up a macro to run on startup

Sorry, just replied to your other post.

Marcus,

I just started a new class today, and my lesson plan was the various ways to customize Zbrush, and I finished up with Creating a startup Macro. Nothing radical, changing startup material, brush settings and the like. SO I recorded the macro, save it, test it, all normal and working. I showed them how to open the macro in the text editor, isolated the section where the 3D object was created, deleted it, saved it…Then the weird part. I re ran the edited macro, and the creation of the primative, conversion to polymesh, drawing to canvas and entering edit mode were still running in the macro. Odd. So I opened it in the text editor again, and that portion was deleted. So I reloaded all macros, re ran it, and it was still running in the macro. So, I quit Zbrush and relaunched, ran the macro, and the 3D object was redrawn and put in edit mode. So I deleted the macro, and recorded a new one, same steps, same results. Thoughts?

Oh yeah, the workstation is a Mac running mountain lion. Zbrush4R5.

Did you delete the .zsc file? The software ran the macro from zsc rather than the text file you edited.

(Slapping my own forehead) Doh! Yeah, that was it. Thanks Doug!

Yes, as Doug says (thanks Doug :slight_smile: ), sometimes the ZSC will not update so it’s a good idea to delete it and restart ZBrush.

Sorry for digging this out again, but I need help again, please. My current version is ZB 4R6.

I have disabled the auto-launch of the lightbox at startup.
When I start ZB without my startup macro everything is fine, but when I’m using my startup macro the lightbox always pops up.

This is what I have in my startup macro:

//ZBRUSH MACRO - Recorded in ZBrush version 4.6
[IButton,???,ā€œPress to run this macro. Macros can be aborted by pressing the Ć«escĆ­ key.ā€,
[IShowActions,0]
[IConfig,4.6]
[IPress,Document:New Document]
[IPress,Tool:PolyMesh3D]
[CanvasStroke,(ZObjStrokeV02n145=H2DEV217H2DEV216H2DEV215H2CFV205H2CCV202H2C9V1FFH2C5V1FCH2C2V1F8H2BEV1F5H2BAV1F2H2B5V1EEH2B0V1EBH2ACV1E6H2A6V1E2H2A0V1DEH29AV1DAH293V1D5H28DV1D0H285V1CCH27FV1C7H278V1C2H271V1BDH26BV1B9H265V1B5H25DV1B1H257V1ACH24FV1A8H248V1A3H23FV19DH236V198H22EV193H225V18DH21EV188H218V184H212V180H20CV17CH207V178H201V173H1FBV16FH1F4V16AH1EDV166H1E6V161H1DFV15DH1D8V159H1D2V155H1CDV151H1C8V14EH1C4V14AH1BFV146H1BAV142H1B6V13EH1B0V13BH1ABV137H1A5V133H19FV130H19AV12CH193V128H18FV125H18AV121H185V11EH180V11BH17AV116H172V113H16BV10FH165V10CH160V109H15AV106H154V103H14EV100H147VFEH140VFAH138VF7H12FVF4H125VEFH11BVEBH112VE6H109VE3H100VE0HF9VDDHF1VDAHE8VD7HDFVD5HD6VD1HCCVCFHC2VCDHB8VCAHB0VC8HA8VC5HA2VC4H9BVC3H95VC2H90VC1H8AVC0H85VC0H81VBFH7DVBEH7BVBEH7AVBEH79VBEH76VBCH74VBBH73VB9H70VB7H6EVB6H6CVB4H69VB3H66VB1
H62VAFH5EVADH5AVABH57VAAH54VA8H53VA7H51VA7H51VA6H50VA5H4FVA5H4EVA4H4EVA3H4DVA3H4CVA2H4CVA1H4BVA1H4AVA0H48V9FH47V9EH43V9DH40V9CH3DV9BH3BV9AH39V9AH37V98H35V98H33V98H31V97H2FV97H2DV96H2BV95H29V95H27V95H25V94H24V94H24V93H23V93H23V93)]
[IPress,Material:MatCap Red Wax]
[IPress,Material:MatCap White Cavity]
[IPress,Transform: Edit]
]

How can I make the lightbox stay hidden?

Hello, and sorry for digging the thread up.

It is not exactly at startup, but is there a way to launch a script when an object is sent back from Maya with GoZ, as soon as it is updated in ZBrush ?

Not that I’m aware of; But, you could just click a button to run your script.

No, that’s not possible. You’d have to do as Doug suggests and press the macro button, or assign a hotkey.

Erf, that’s too bad… I have a lot of files to process (395), I didn’t want to have to click to relaunch my script each time the object was sent back from Maya. Thanks anyway, I’ll try to find another solution !

a new button called StartupMacro ? where can i find it? Tks

If you followed the instructions at the start of the thread and saved the macro to the ZStartup\Macros\Misc folder and called the file StartupMacro.txt then it will be in the Macro palette.

Hey Marcus, I noticed you or whoever wrote the docs for this page used the same method:

https://support.pixologic.com/Knowledgebase/Article/View/257/69/custom-ui-doesnt-save-max-threads

I’d like to point out a couple issues though.

The script on that page is written incorrectly, it has an extra comma after the ISet line, causing it to not compile properly. So the ā€œHomeā€ menu does not actually popup on start. Now if you fix it by removing that comma, there’s another issue, the code will be re-executed if you open up the ZScript view at the bottom of ZBrush, and will continue to try executing. This can be solved by removing the code in the True return of the MemGetSize, but then, you can no longer press the ā€œDefaultZScriptā€ button up top to execute that startup code whenever you want, as that button’s description says it’s meant for.

I believe the correct methodology that should be suggested is to be using VarDef and VarSet, instead of MVars, that way when you press the DefaultZScript button, that function can return false again and redo the code, but won’t keep executing if the script window is opened, making it safe for production.


[VarDef, defaultStartMem, 0] [If, defaultStartMem,, [VarSet, defaultStartMem, 1] //Execute your startup code ][pd]

that works for me :
If,1,[IFreeze,
//Your Startup Options

[IPress,Material:BasicMaterial]

[IPress,Tool:PolyMesh3D]

[CanvasStroke,(ZObjStrokeV02n11=H3B6V14BH3B6V14CH3B6V14DH3B6V14EH3B6V150H3B6V151YH3B6V151K1XH3B6V152H3B6V152H3B6V153H3B6V153)]

[TransformSet, (Document:Width*.5), (Document:Height*.5), 0, 100, 100, 100, 0, 0, 0]

[IPress,Transform:Edit]

[IUnPress,Preferences:Lightbox:Open At Launch]

]
]

be careful with the Zstartup master plugin which make the DefaultZscript button on top of Zbrush ui to do nothing.

Hi Invertex,

Thanks for pointing that out, I’ll get it corrected.

The point of using MVarDef is that the memory block persists, so that you can have code only run once per ZBrush session. Your code will run any time the script is reloaded, such as after another script or plugin has been run. (Your code is fine - this may be what you want.)

The new DefaultZScript file I’ve written is:

//startup

[If,[MemGetSize,startup_mem],
[IPress,ā€œZplugin:Misc Utilities:Home Pageā€]
,
[IShowActions,0]
[IConfig,2018]
[MVarDef,startup_mem,1,0]
[ISet,Preferences:Performance:MaxThreads,4]
[IPress,ā€œZplugin:Misc Utilities:Home Pageā€]
]

(I’ve left out the [pd] at the end because no code will run after the Home page button is pressed - control passes to the Home Page launcher script.)

The issue you were seeing with the code running every time you opened the ZScript Window is I think because some commands were outside the [If, statement.

This code will always return true, so if you expand the ZScript menu at the bottom of ZBrush, you’ll notice your script will execute again. This is not behavior most would want, especially if being used in a production setting. (though given the info below, in this particular case it won’t because Lightbox ends up taking control)

Hi Marcus, there was no code outside of the conditional. There seems to be a deeper issue here with how the DefaultZScript file is being handled. Your code works if calling that Home Page button, which you mention is taking control after, so that is shining light on the issue here. I guess by default, ZBrush is not passing control off after the DefaultZScript runs, and thus it will continue to be there to execute when certain interface features are interacted with.

If I swap out the Home Page IPress in your example with a simple material change:

[If,[MemGetSize,startup_mem],
[IPress,ā€œMaterial:NormalRGBMatā€]
,
[IShowActions,0]
[IConfig,2018]
[MVarDef,startup_mem,1,0]
[ISet,Preferences:Performance:MaxThreads,4]
[IPress,ā€œMaterial:NormalRGBMatā€]
]

Then the script will result in the behaviour I mentioned, executing whenever the ZScript console is opened, which I assume now is because control is no longer passed to anything else? This is unexpected behavior that isn’t really explained. And I’m not aware of any commands that can tell ZBrush to ā€œunloadā€ the current script, as far as I know you’d have to set next file name to some blank script and call a load on that instead. Is there something we can call to pass control that the user wouldn’t actually see, nor change any settings?

when I tried to download the file from support website, it was impossible to download it, it works now, I can finally see what you expected.
But anyway, I don’t get the point with your not good for production argument.
sorry but what kind of second behavior you want the defaultZscript button to have after the if you click on it after the session has started ?

  1. at session start, the script setup some option for you .
  2. click again after the session start, if you want to reset the zbrush environment even if this do not erase tools which are stacked in the tool panel like it would if you press init zbrush.
    the only thing is that you want to have the homepage script to popup at startup but not if you press the default script button.
    IF yes then my method is not correct, but I safe for production as the code don’t retry endlessly to execute it. it will always return True, and for that reason I prefer to use my method, as I just prevent Zbrush to create persistant mem block when I don’t need that.
    Also it better to have a naming convention for memblock naming, generic name can collide with other plugin which also create memblock at the startup process.

I think you are completely missing the point in my last post. I can already get the intended behavior I want by using a regular Var instead of MVar, I said this in the beginning, this is not the issue. I don’t want the Homepage menu either. The issue, like I explained in the previous post, is that if your startup script does not call something that forces a different script to load, such as Home Page does, then the Startup script never gets unloaded, and thus will be repeated any time the ZScript display is opened. I’m pointing out behaviour that goes against what you would expect the script to do, which is to run, and then unload itself, only reloading when you press the DefaultZScript button.

I believe you are not understanding the issue, because the issue exists even with your script. I will show you a video of what I mean and why I said it is not ā€œproduction safeā€ if your code can do things that might mess up a user’s work.

This is your script exactly. ZBrush launches and the star is there. But see what happens when I ā€œaccidentallyā€ click the ZScript console expansion at the bottom? Your script runs again and tool is set to Star again, even though I did not click the DefaultZScript Button. So surely you can see how, depending on what a team is doing in their startup scripts, this could easily lead to losses of work.

The key point here is that this does not happen in the documentation example, because in that example, calling the ā€œHome Pageā€ causes a different script to be loaded, preventing this issue from happening, but most people would not know that it works specifically because of that Home Page IPress. I’m saying that this behavior should be documented and now asking if there is some other, more clean method to ā€œunloadā€ our script after it runs without having to bring up the Home Page or load some other script file.

(also I do use my own memory names… But we’re discussing the example here, so I stuck with the generic names to avoid any confusions)

yeah I totally misunderstood the issue sorry.
if you want it to work with a varset then you can try out that

//startup
[VarSet, zbTime, [ZBrushInfo, 2]]
[If,( zbTime <= 15.000 ),//cmds
[Note, ā€œa New Zbrush Session startsā€¦ā€,.1]
,//else
[Note, ā€œdo nothingā€,.1]
]

here if it check the Ztime info from the top title bar, and if the returned value is less or equal to 15 seconds, then it mean the Zbrush startup a new session.
if the value is bigger, then I run the second part of the if condition.
my personal opinion about all that is that Zbrush should use two different scripts
one for the startup , one else for the script console.
there is no bug, or any issue its just normal behavior, but it make me confuse a lot as yesterday the example code wasn’t unavailable and my personal defaultscript.txt has that issue, that prevent to execute the second condition when pressing the Default script from the top menu.
:roll_eyes:

1 Like

Hi Invertex,

Many thanks, I get the behaviour you describe with your code. (I’m not sure why I didn’t see it before but I’m not going to spend time trying to find out…)

The behaviour is not restricted to the DefaultZScript. Moving the ZScript Window divider will reload the current zscript, whatever that happens to be. In the normal way this won’t affect the user; only if the current zscript runs code on loading. So, for example loading a zscript with:

[If,1,
[Note,ā€œHello Worldā€,1]
]

will display the note every time the divider is moved.

I think this behaviour is left over from early versions of ZBrush when there were no plugins and zscript was used mostly for tutorials. If I ever knew about the behaviour I’d certainly forgotten.

There’s no way to simply unload a zscript, that I know of. So, apart from loading a second zscript, the best way I can think of is to specify behaviour for only when the DefaultZScript button is pressed, so that moving the divider does nothing:

[If,[MemGetSize,startup_mem],
[If,[IGetID,DefaultZScript]==[IGet,Preferences:Utilities:View Window Id],
//code to run when DefaultZScript button is pressed
]
,
[MVarDef,startup_mem,1,0]
//code to run once at startup
]

[PD]

HTH,