ZBrushCentral

ZScript syntax highlighter for Sublime Text - beta

Hi all:

UPDATE: This plugin is now available officially on Package Control. You should be able to install it directly from within Sublime Text now. However, if you are intending to fork this plugin, please continue using the git repository as you see fit.

I’m getting into scripting with ZBrush for looking into doing tools for our artists here (I’ll be brutally honest; what a terrible scripting API along with crappier documentation, seriously. But that goes with my opinion of ZBrush anyway as far as the UI and architecture is concerned), and as part of my work, I made a syntax highlighter for ZScript for Sublime Text. You can clone the repository from the following URL:

https://bitbucket.org/sonictk/sublime_zscript

I plan on eventually submitting this to package control when I’m sure it’s bulletproof. Right now I only have indentation settings among other quality of life features to add, the autocompletion and syntax highlighting should be fine (I hope!)

If anyone here would like to test it out with their own scripts, I’d appreciate it :slight_smile: The autocompletion and syntax highlighting files were generated automatically from the HTML documentation available, so I’m not sure if there are ‘hidden’ commands that I might not know about or deprecated commands.

If you encounter issues, please report them via the issue tracker on the BitBucket itself. I don’t visit these forums very often.
https://bitbucket.org/sonictk/sublime_zscript/issues?status=new&status=open

Preview:

http://i.imgur.com/VKUFPPs.png

Hope this helps out fellow artists here!

That is great sonictk, I will give it a try and let you know how it goes. Thanks a lot :+1:

I made my own by modifying one of the stock Sublime Text syntaxes but somehow broke the line / block comment when using the shortcut key.

If installing your syntax on Mac OS X you can press Sublime Text > Preferences > Browse Packages which will show the Packages folder where syntaxes can be put. Syntaxes should be put in their own folder so create one if needed.

Hi again,

I had a chance to try out your syntax highlighting and code completions. Thanks again for sharing. I wil try to make my reply short and to the point :smiley:

I should probably note I am running the latest Sublime Text 3 beta on OS X 10.11 and have not had a chance to test on Windows, but Sublime Text is pretty rock solid across Windows, Mac and Linux, so we should not be seeing any discrepancies.

First of all thank you for including the .YAML-tmLanguage file. I had previously tried modifying various XML based .tmLanguage files to fit my needs and also tried creating one from JSON, but neither were very successful. Reading your YAML file made everything click. Thanks.

The syntax highlighting works fine except for some commands. Some have two coloured highlighting, such as IGetFlags, where IGet is one colour and Flags is another colour. There are a whole lot of IGet and Var commands like that but also a command like LoopContinue, where Loop and Continue are highlighted differently. Not sure what is going on but it smells of regular expression.

I had a problem with the suggested code completion popup not appearing and could see you have defined the scope in most of the files (maybe all) as text.zscript. I believe you need to set the base scope to source for the code completion popup to appear. Replacing all instances of text.zscript with source.zscript gave me my beloved code completion popup.

In regards to your code completions it was cool to see how you scraped the ZBrush ZScript Command Reference using a python script. Very nice :+1: But there is an easier way to get the full list of current ZScript commands. If you start ZBrush and open the ZScript palette you can find the Export Commands button at the bottom, which exports the full list of ZScript commands and parameters into a .txt file file. You will still need to regular expression your way through the command names and parameters but the list is up to date and easier to parse. If you load the file into Sublime Text you can skim it for the aforementioned two toned syntax highlights.

I see a couple of problems with how you are generating .sublime-completions from the ZBrush ZScript Command Reference.

  1. You end up with multiple definitions for the same command. One for the actual command and one or more for any examples given.

  2. The completions are verbatim and contain superfluous descriptions. I am not criticising the documentation nor your scraping technique, but in my humble opinion there is a need for some human curation. For example, typing ibutton and hitting the tab key gives me a wall of text, not succinct parameter descriptions. When you read documentation you want the full story but not very often while coding.

  3. No tabbing between parameters which is a must have, not a nice to have! :slight_smile: This, as I am sure you know, can be solved by including matched cases into the content property of the completion definition.

For example, the following IButton code completion will format the command across multiple lines with a tab indent added to the commands section. It also allows you to press tab to switch between parameters selecting the text as you traverse the command. Seeing as the parameters in this case are comments they can be ignored or replaced, the ZScript will still run.

{“scope”: “source.zscript”,
“completions”: [
{
“trigger”: “ibu .”,
“contents”: “[IButton, “ZPlugin:${1:}”, “${2:POPUP INFO}”,
${3://COMMANDS WHEN PRESSED}
, ${4:/DISABLED ?/}, ${5:/BUTTON WIDTH/}, , ${6:/BUTTON ICON/}, ${7:/BUTTON HEIGHT/}]”
}
]
}

Which results in a much more readable and editable piece of ZScript, IMO:

ibuttonCompletion.jpg

One last thing. Thank you for the work you have put in so far. I hope you do not think I am criticising you. I am simply trying to encourage you to go further. If you agree with the human curation part I am more than willing to lend a hand although I do no not think every single zscript command deserves nor needs a full code completion.

I am slowly but surely writing my own ZScript documentation for Dash which integrates nicely with Sublime Text. You can put the cursor on the command you want to look up and press the shortcut key. Dash will open and show the relevant command. That is what I would prefer to have rather than every single command having a .sublime-completion. But that is maybe just me.

In any case I hope you continue and please let me know if I can help a little.

Hi:

Thanks for the suggestions! I’m a little busy at work writing some other stuff atm, I’ll see if I can do something about the problems you’ve brought up eventually and add them to the issue tracker as well.

I’m currently experimenting with adding some menu commands to launch ZBrush with the ZScript in the SLT view, so I’m less focused on the semantic stuff for now. I saw some examples of using C#/C++ and ShellExecute to launch ZBrush with a specified ZScript. Does ZBrush not have any command line switches for doing so natively?

Thanks for the feedback!

Hi,

As far as I know there are no command line arguments to load a ZScript upon launching ZBrush. However, on Mac OS X I have a solution for ZBrush and Sublime Text and probably any editor that allows command line execution in the build process. Right now I press CMD + B in Sublime Text which saves the source ZPlugin, runs my command line app that switches to ZBrush and issues a hotkey. The hotkey is tied to a ZPlugin whose sole purpose is to reload my actual work in progress ZPlugin.

Why have two ZPlugins? Because you cannot reliably reload ZPlugins that generate ZBrush interface items. A button might cease to function, old code might be executed or everything stops working. And in this case we want to trigger a reload often.

Your second ZPlugin will [IClose,…] the subpalette containing all your interface items or even issue multiple [IClose,…] commands to single interface items instead of a subpalette. Trust me, it is needed and will make your ZScripting life much easier, not harder. You of course never ship the reload ZPlugin.

If all your interface items were located in ZPlugin > sonictk then your reload ZPlugin would look like this:

[IButton, “ZPlugin:Reload sonictk”, “POPUP INFO”,[FileNameSetNext, “sonictkZPlugin.txt”]
[If, [IExists, “ZPlugin:sonictk”],

[INDENT=2] [IClose, “ZPlugin:sonictk”]

]
[IPress, “zscript:load”]

, , 1, , , .5]

When you [IClose,…] an interface item it is as if it never existed (zscriptwise). Therefore it is safe to reload a ZPlugin that generates the same interface item. The only problem is the Interface Item ID, which keeps going up and is finite. But for the purposes of testing ZPlugins it is fine for hundreds of reloads.

Although an extra step the reload ZPlugin is nearly all you need. You simply load your Reload ZPlugin first and press it’s button or hotkey each time you make a change. I unfortunately do not have a one button press solution for Windows.

If you are using OS X then give me a day or two and I can post the console app and sublime.build file that works with Sublime Text and ZBrush.

[HR][/HR]Thanks for the suggestions! :smiley:

I am pretty new to Zscripting but I find you syntax highlighter really helpfull and the formatting readable. :wink:
For a person like me not accustom to read lines of code all the day long it makes editing the Zscripting code much easier.

However I was wondering if would be possible to customize the colors according to the user preferences. :slight_smile:

So many thanks for releasing it and keep up the good work. :+1:

Hi Andrea, you can get many Colour Themes from colorsublime.com. Sublime Text does not have an editor to select which colours are shown for specific commands.

If you decide to use Sublime Text for other things then visit packagecontrol.io and look through the hundreds of packages you can install.

Hi Andrea, you can get many Colour Themes from colorsublime.com. Sublime Text does not have an editor to select which colours are shown for specific commands.

If you decide to use Sublime Text for other things then visit packagecontrol.io and look through the hundreds of packages you can install.

Hi Mark many thanks for the info. :wink:

I think that for the moment the Color Themes from colorsublime.com are just what I need. :smiley:

Thanks for all your info