Init.py question

Hi, sorry if its too of a beginner question, but I got a script from Github( customise_stylesheets.py ), when I run it in the script editor , everything is working and I can change the color,font etc, but when I put it in init.py and start Mocha the scripts doesn’t change the UI e.g. doesn’t work.

Thanks!

Hi, we’d have to see where it’s going wrong to diagnose the script. Have you checked out our python guide? Boris FX | Mocha Python API

Yes, I checked it, I mean only the part about the init.py , it’s says that ‘‘If unset, the default locations above will be used.’’ , maybe I wasn’t clear, my question is : Should I just paste the script that was working in the Python editor in Mocha in the init.py file without adding anything extra and expect to work the same way.

Python is not my strong suit, but yes, that has worked for me before as long as it’s just another set of lines in the body of the file and not blowing away other data.

You will need to register and call the script if you want to keep it separate. this is very easy to do.

For example, with customise_stylesheets.py you would just place the script file in the same directory as the init.py script, and then in the init.py file you would write:

import customise_stylesheets

If you want to debug whether the script was imported and run, just add a print statement to the bottom of the stylesheet script and it will appear in the Python Script Editor log window in Mocha.

Thank you, actually the script is working now when I directly put in init.py but I follow your advice and kept it in different script but in the same directory as the init.py and I used the print statement to see if it runs, everything is good now, thank you again.

No worries! I’m glad you’re finding the Python script repository useful.