ZBrushCentral

Question: Can I launch ZBrush and have it run a script on startup from a C# app?

Are there any command line arguments I can pass to zbrush.exe that will allow me to run an arbitrary script at startup?

I’m able to launch ZBrush from the following simple C# application, but I’m unable to have my script run on startup. I’m trying to deploy this C# application and zscript (myscript.zsc) to other people on my team, and I don’t want to have to change everyone’s “startup script” on their local install of ZBrush. I’d like to launch Zbrush and have it execute the script I specify on startup.

In the following code, scriptPath is used as an argument for System.Diagnostics.Process.Start().

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;


namespace CreateHeadAssets
{
    class Program
    {
        static void Main(string[] args)
        {
            string zbrushFolder = @"C:\Program Files (x86)\Pixologic\ZBrush 4R4";
            string zbrushExe = "zbrush.exe";
            string scriptPath = @"C:\Users\dauclair\Desktop\myscript.zsc";


            FileInfo script = new FileInfo(scriptPath);
            if (!script.Exists)
            {
                System.Console.Out.WriteLine(string.Format("{0} does not exist
", scriptPath));
            }
            Process.Start(zbrushFolder + @"\" + zbrushExe, scriptPath);
        }
    } 
}

I’ve seen some ShellExecute examples from some other posts, but I really need to deploy this as a C# application, as it will be integrated into a much larger C# application that does a bunch of other things in our pipeline.

Example ShellExecute command from another post:

#include <windows.h>


static const char *zbrushFolder = "C:\\Program Files (x86)\\Pixologic\\ZBrush 4R3";
static const char *zbrushExe = "zbrush.exe";
static const char *scriptPath = "C:\\Users\\Mark\\Desktop\\TestZScript.zsc";//if just a file name then ZBrush will look in the default location 'ZScripts'




int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  ShellExecute(NULL, "open", zbrushExe, scriptPath, zbrushFolder, SW_SHOWNORMAL);
  return 0;
}

Any help would be most appreciated!

So, it appears that my above code works when loading a ZSC file but it doesn’t automatically execute. Is there a way to have a zscript auto execute when it’s loaded and not click the button in the UI to execute it?

This does actually work, it just doesn’t kick off the script. You have to press the button in the Tutorial View. Does anyone know how to run a script on-load without having to click the button?

You just need to make sure the script will run without a button. The simplest way to do this is to wrap your code in an [If] statement that is always true:

[If, 1,
//code here
]//end of if statement

Depending on what you are trying to do, you may need to make sure the script only runs once. You can do this by creating a memory block and then testing for it, so the script only runs when the block doesn’t exist.

Awesome, this worked perfectly. Thanks!