How does the actual custom parameter need to be attached to the setCustomParameters_? I tried putting the CP as an argument in parenthesis and other funky stuff, but I cannot figure out how to use this particular one properly.
Let’s say I got the snippet:
thisFont = Glyphs.font
for instance in thisFont.instances:
....print instance.customParameters
....instance.setCustomParameters_
This is a setter method for the whole parameter list. You would need to supply a list of parameters to get this to work.
The content of the parameter is a array and this is displayed in one line (using the \n instead of the actual line break). This has to do with the nesting of the lists
There is one catch. If there already is a “Test” property, it will be overwritten. If you need more than one parameter with the same name, you need to use .append()
Georg, that is so cool! Thanks again. Actually I was even trying to check if it’s already there. In my particular case I need it exactly as you describe: overwriting (or doing nothing).
No. As there could be more than one entry with the same name. So 'customParameters' acts as a 'list' object.
del() is a standard method for list objects.
I
As I said, you can only access the entries by index. And you should be careful if you interacting a list and change it at the same time. Iterating backwards prevents problems.
thisFont = Glyphs.font
cpName = “Rename Glyphs”
for instance in thisFont.instances:
…for i in reversed(range(len(instance.customParameters))):
…if ((instance.customParameters[i].name == cpName:
…del(instance.customParameters[i])
My bad, sorry. I wasn't aware of it being treated like that. Good to know that one can work with multiple keys of the same name.
Thanks, this works perfectly. We just need to add the 2 closing parenthesis like so:
if ((instance.customParameters[i].name == cpName)):
Thanks again for all your effort. Really glad to get this working.
Hopefully one last thing on that. Now I encountered an interesting behavior. The script I am working on uses a delay in order to wait some seconds for the otf export and go on after this. For that i use
import time
and
time.sleep(15)
While this works perfectly run from the macro window, when running it from a .py file file out of the scripts menu, the delay is not working. It seems to employ it immediately, displaying the beachball for 15 seconds and then run the script all at once. What’s the difference here with the macro window and the run of .py file?