ZBrushCentral

Solution: Renaming Subtools / Layers on OS X

This is a Dynamic Library solution to renaming subtools and layers on Mac OS X, while also allowing the zscript to continue without user interaction.

Problem: In a ZScript where Tool > Subtool > Rename or Tool > Layer > Rename is pressed, the ZScript loses focus and the user is expected to complete the task. The ZScript cannot continue until the user enters a new name and presses enter or cancels the rename dialog window.

Solution: Our ZScript makes a call to a Dynamic Library where we use a NSTimer object to delay our call to functions that will simulate keypresses after our Dynamic Library has returned control to ZBrush. Back in ZScript we immediately press Tool > Layer > Rename and wait for the NSTimer to do it’s thing.

Issues: During select circumstances ZBrush might take longer to actually press and display the rename layer dialog, thus passing the point where NSTimer calls the keypress function. I had it happen once during low memory and high cpu usage on my meagre 2012 MacBook Air. During normal usage and on newer cpus it should be fine.

How to use: Unzip the Xcode project and open it. Go into the advanced section of File > Project Settings and change the build location to fit your ZScripts location. From your ZScript you would call the Dynamic Library and then press the rename button:

[FileExecute, “zDLL.lib”, “KeyPress”, “MyNewName For SubTool”]
[IPress, “Tool:Subtool:Rename”]

By default the KeyPress function calls [MOKeyPresser simulateKeypressesOf: (char*)inputString withDelay: (NSTimeInterval)0.1]; which simulates the keypress of each character in inputString after the delay. You can also use [MOKeyPresser simulatePasteOperationOf: (char*)inputString withDelay: (NSTimeInterval)0.1]; which copies inputString into the clipboard and simulates a Command + V key press after the delay. The first method is probably preferable as the paste command shortcut may vary depending on the OS localization.

You should also be aware that simulateKeypressesOf: withDelay: converts all characters to lower case and only supports the english alphabet and some special characters.

I hope somebody finds this useful and maybe extends it a bit.

Note: It is currently only a 32 bit library, ZBrush 4R5 on Mac fails to load the library when I compile it as a 32 and 64 bit library.

It should be noted that changing the name of subtools on both Mac and Windows can be accomplished using zscript alone, as Marcus shows > here <. Changing layer names is the tricky part and where the above becomes useful.

Hi Mark,

Thank you so much for taking the time to share this with the community. I’m very much looking forward to trying it out!

Cheers,

Your welcome Marcus, I just hope you can use it for something cool.

I noticed that ZBrush does not allow you to rename a layer or subtool with the same name. So any ZScript should probably test against the current subtool/layer name before committing to changing it or else the ZScript execution will pause.

I noticed that after entering a new subtool or layer name ZBrush converts the first character to uppercase, but when comparing the current name to the about to be entered name ZBrush does not convert the first character of the new name. Therefore there is no need to do a zscript check if the subtool or layer name matches the name you are about to enter using the Dynamic Library. At least not currently as simulateKeypressesOf: withDelay: only supports lowercase english language characters.

If the first character of the new subtool or layer name cannot be uppercased ( such as: - / # ) you will have to do a name comparison before changing the name. Likewise if you use simulatePasteOperationOf: withDelay:.

Hi Mark,

This works very nicely, albeit with the various restrictions. Worked fine with 4R7 64bit (with a combined 32/64 bit library). I’ve not looked at the code yet but will do so when I have a moment. Thanks again for posting!

Hi Mark

I took a closer look at this and have implemented it for Windows (and a revised version for MacOSX). I’ve added the function to the ZFileUtils. I used a slightly different approach in that neither platform has any delay.In my tests it didn’t seem to be necessary and worked fine on my ancient MacBook. That’s not to say that the function won’t fail under some circumstances (it feels too much like a hack) but it hasn’t broken for me. :slight_smile:

Both versions will cope with upper/lower case and some special characters (though these are best avoided as they’ll certainly fail with some keyboards).

The code can be downloaded herefor anyone interested.