Coding with Style (in Python)

Dive into the art of style in scripting and explore the beauty of collaboration.


Effects America was kind enough to invite me to do a masterclass for a selective audience. They asked me for an upgraded version of Scripting for Artists to match with their more technical event. After one month next to my work at Dwarf Animation Studio and during the lunch breaks a 60 pages script of Scripting for Artists {Advanced} was born. The masterclass became a 4.5/5 star success with artists, leads and heads from Framestore and Ubisoft attending to advance in their daily scripting especially in Python for their work in Maya, Houdini and MotionBuilder.


Introduction


After Season 1 of Scripting for Artists we now continue our journey in becoming an extraordinary technical artist or director in the Animation and VFX industry. The core point of Scripting for Artists is not skill but a round up solution of multiple layers. The mixture of skill, mindset and branding creates opportunities and a fulfilling path of working your way, under your conditions and understanding. Only then we can succeed to work in better environment while overtaking those who stuck in the realms and expectations of yesterday. Skill is useless if you can not land a job and both will create anxiety and stress if you don’t believe in yourself or are too reserved for new tasks and exploration. The idea is to provide you with the basics and typical practical examples to open up greater possibilities working with Python in Animation and VFX. During the masterclass we only focus 50% of the time on skills. The other 50% is about collaboration which in terms of scripting means readability. The moment you can grasp the code quickly and understand its ins and outs while adding value you can make it production ready. As a result, you know what is important and how it can be used.

"Code creates content. Style creates collaboration."

Style in Scripting


Coding with Style describes a form of writing scripts that allow collaboration. While in the beginning of your learning you're mostly focused on writing scripts that can "do the job". It's just later that you understand how vital it is to develop a common and personal style. Style enhances readability, shows an advanced skill and adds a layer of joy to what you are reading. One of the best advice early in my scripting and programming carrier was:

“Be sure to learn the style first - it can save you.”

Like a spoke language with proper pronunciation coding style creates a better understanding of what someone else is trying to express. It adds a layer of clearness and can be fun seeing a well structured codebase.

I took this advice to heart and started to look into different standards and coding styles. After some time I arrived at this point where it is a habit of correcting and reviewing. Like a writer rewriting a chapter multiple times until every sentence expresses the story and leads the book to its arcs. Every line, block, function, class or module needs to be crafted to create a sense of wholeness. The more you practice this way of working the more it is a part of your flow and it will come naturally. Even now if I see something that catches my eye through its design or effective simplicity I copy it and see how it works in my own scripts.

Working Pythonic in Python means following the common guidelines and expressing its intent in what is considered "the best way". It is an expression used to describe code which uses its language to its fullest potential. The opposite would be operating quirks and schemes from other languages like C++ or MEL in a Python environment which results in poor understanding and performance.

To help you with the style every scripting and programming language has so called style guides. In Python it is PEP8 but there numerous individual and company created style sheets to keep things consistent. Readability is one of the core pillars of this idea to keep everything clear and understandable instead of just functional and "doing the job". This is especially important in collaborative environments when multiple developers work together but it also shouldn't be neglected for solo artists who try to make sense of what their worked on three months ago. The feeling of "who wrote this?" is definitely an indication of bad style.

Good style looks clean and even in the overview organised

The importance of UI


User Interfaces (short UI) create the bridge between the intentions of the developer and the intentions of the artist. Creating a great UI is an art form in itself and should be part of your attention when you develop a script which interacts with a user other than yourself.

Why? Since it is the only reflection of what the app is capable to someone who cannot see inside and investigate the code. The same principle as for the coding style applies for the interaction with the user of the scripts. While it is vitally important that the script does its job it is as important that the user or artist is using it in the easiest, clearest and successful way possible. The alternative is you created a high performing tool for yourself.

“If your UI fails - you failed to solve the problem.”

Animation and VFX projects tend to jump frantically between software packages (DCCs). The only sane solution to counter this is to use Python as the default scripting language to keep the system clear and consistent. The same blessing comes to us with the PySide API which is integrated in most packages (Maya, Nuke, Houdini, 3ds Max, ...). This means you can use your UI independently of the software you are using it in - as long as the code provides the right interfaces/connections with the current software. This allows you to create scripts which can be used independently to their environment.

Same UI in Maya, Nuke, Houdini and 3ds Max

Additionally templates can help to redefine a style and default functions which are inhabited by other scripts. This workflow adds flexible, avoids repetition and overwhelming complexity.

Plex: Using arUtil to define all apps in the project

Coding with Style is a chapter in my newest Masterclass Scripting for Artists {Advanced}. You can watch the video of my talk at the Effects America 2019 on YouTube and have a look here for more information.

Best, Alex


The whole talk at the Effects America 19 in Montreal

For a personal Python training see here. Make sure to subscribe to the newsletter to get access to the Python cheat sheet and future updates.

youtube.png

Be the first to know!

Get valuable resources and insides. Updates and articles.

*You can unsubscribe at any time.