View Full Version : Python and Zbrush

04 April 2010, 10:17 PM
Has anyone gotten python to interact with zBrush successfully? I've seen an example out there using AppActivate and sending key commands but I was not able to get it to work. I was just wondering if anyone else has given it a shot and has been successful?

05 May 2010, 06:08 PM
This is based off a post from zbrushcentral, there was a post about sending key commands from python to zbrush. The code posted there didnt quite work. I needed to get the name of the active window and for some reason "Zbrush" is not the correct name. So I have python get the active window name, save it as a variable and in a loop I send a key command. Saving the z app name to a variable lets me error check in case some other application is active. You would not want this script sending key commands while you're writing an email This can be used to create an auto-saving script for zBrush. Well as long as you can assign a zscript to a hot key.

my apologies about the formatting:

# Import Modules
import win32com.client
import win32api
import win32gui
import os

# Main
timer_on = 1 #set the inf loop variable
#create shell script
shell = win32com.client.Dispatch("WScript.Shell")
#create command to fire up Z
command = "C:/Program Files (x86)/Pixologic/ZBrush3/ZBrush3.exe"
#os.startfile(command) #fire up Zgg
win32api.Sleep(5000) #pause for z to load
#get title window of z
winName = win32gui.GetWindowText(win32gui.GetForegroundWindow())
#save title window of z
zWin = winName
#pause for z to be active
#make sure z is active app
while(timer_on > 0):
#sleep for 5 minutes before sending key command
shell.AppActivate("zWin") #making Z active app
win32api.Sleep(1000) #pause before saving
if (zWin == winName): #make sure its Z
shell.SendKeys("w") #initiate move command in Z
print "Sending Z Command" #print statement for error check

CGTalk Moderation
05 May 2010, 06:08 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.