# ChatGPT can write Python for Glyphs

**URL:** <https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157>\
**Category:** Scripting\
**Created:** [February 19, 2023, 2:03am UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157 "2023-02-19T02:03:53Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tosche](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/tosche/32/412_2.png) [@Tosche](https://forum.glyphsapp.com/u/Tosche)\
**Post date:** [February 19, 2023, 2:03am UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/1 "2023-02-19T02:03:53Z")

</div>

I just wanted to share my experiment with ChatGPT, which can apparently write pretty good Python code for Glyphs if you explain well. Attached image is a quite simple query example, but I have managed to make it generate more complex stuff including viewer plugins (with some rounds of feedback). It’s terrific and terrifying.

 ![スクリーンショット 2023-02-19 1.58.46](https://forum.glyphsapp.com/uploads/default/original/3X/1/a/1a1cd444c64a0fba73613938e0993754e54652a3.png)

---

<div class="post-metadata">

**Author:** ![tribby](https://forum.glyphsapp.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@tribby](https://forum.glyphsapp.com/u/tribby)\
**Post date:** [February 19, 2023, 4:18am UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/2 "2023-02-19T04:18:57Z")

</div>

nice! I have been using chatgpt for glyphs, drawbot, random fonttools scripts… in typescript/react and go too. I wouldn’t say I am terrified but I am surprised by how good it is. not always, but a lot of the time. what I have found is that sometimes, when the problem gets too obscure, it is very confidently wrong about things, and will start making random suggestions like installing a library version that don’t exist

it’s great at refactoring python too, if you ask it to make something more pythonic, or ask it to make an algorithm more efficient

---

<div class="post-metadata">

**Author:** ![SCarewe](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/scarewe/32/18952_2.png) [@SCarewe](https://forum.glyphsapp.com/u/SCarewe)\
**Post date:** [February 19, 2023, 10:22am UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/3 "2023-02-19T10:22:45Z")

</div>

If you’re happy using ChatGPT, I very much recommend GitHub Copilot, if you haven’t tried that already. Integrates perfectly with JetBrains IDEs such as PyCharm. There’s even a third-party plugin that lets it integrate with XCode. Trained on the same model (GPT3), just different training data.

---

<div class="post-metadata">

**Author:** ![mekkablue](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/mekkablue/32/23_2.png) [@mekkablue](https://forum.glyphsapp.com/u/mekkablue)\
**Post date:** [February 19, 2023, 7:03pm UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/4 "2023-02-19T19:03:04Z")

</div>

I had less luck with ChatGPT. It took my correction suggestions in plain English, but it would not produce runnable code, not even after 10 iterations.

I saw it make up PyObjC method names though, rather than producing actual code. 🙂

---

<div class="post-metadata">

**Author:** ![gor.jious](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/gor.jious/32/9472_2.png) [@gor.jious](https://forum.glyphsapp.com/u/gor.jious)\
**Post date:** [February 19, 2023, 11:31pm UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/5 "2023-02-19T23:31:07Z")

</div>

So it’s not going to replace mekkablue—the OG-ChatCPT!—just yet;-)

After seeing this post I tried it for a simple script I wanted to write to assist with, coincidently, Toshi’s BubbleKern.

Prompted it this: _Write a Python script for GlyphsApp that adds 10 units of LSB to the selected glyph in the selected layer, and if there is a layer in the same master named “bubble” then add the same units of LSB._

It quickly generated some code that was 99% accurate only messed up on one line using `.leftMetrics` in `selected_layer.leftMetrics += lsb_offset` instead of using `.LSB`.

I can see this being incredibly helpful though!

Is it actually trained with the Glyphs API and all the open-source glyph scripts/plugins (I know very little of how it all works) or can it be?

I would be curious how other people word/structure prompts to get more accurate results.

---

<div class="post-metadata">

**Author:** ![tribby](https://forum.glyphsapp.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@tribby](https://forum.glyphsapp.com/u/tribby)\
**Post date:** [February 22, 2023, 4:51am UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/6 "2023-02-22T04:51:43Z")

</div>

I’ve had less luck with CoPilot, for me it is more of a powerful autocomplete, whereas ChatGPT is more general purpose / I can actually work through things with it. Maybe I haven’t read enough CoPilot docs to know how and where it is most powerful.  
I am definitely more impressed by both CoPilot and ChatGPT when doing web development where the training corpus is enormous.

---

<div class="post-metadata">

**Author:** ![alexs](https://forum.glyphsapp.com/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@alexs](https://forum.glyphsapp.com/u/alexs)\
**Post date:** [February 22, 2023, 3:50pm UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/7 "2023-02-22T15:50:04Z")

</div>

> [@gor.jious](#):
>
> Is it actually trained with the Glyphs API and all the open-source glyph scripts/plugins (I know very little of how it all works) or can it be?

Seems like it can scan APIs and even work with articles, but sometimes you need to tell it to double-triple-… check stuff. Interestingly, it told me it can’t read forums but seems like has no problems with articles.

---

<div class="post-metadata">

**Author:** ![gor.jious](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/gor.jious/32/9472_2.png) [@gor.jious](https://forum.glyphsapp.com/u/gor.jious)\
**Post date:** [February 22, 2023, 4:13pm UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/8 "2023-02-22T16:13:01Z")

</div>

After using it for a few days, I am finding it helpful in creating short snippets for looping through masters or adding/moving/removing certain things but it seems to struggle with other seemingly simple tasks.

For example: _For GlyphsApp version 3 make a basic vanilla preview window that displays the currently selected glyph_ and it just can’t figure it out…it adds modules/methods that don’t exist even after I feed it back the error messages, working snippets, and link to Glyphs API.

---

<div class="post-metadata">

**Author:** ![gor.jious](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/gor.jious/32/9472_2.png) [@gor.jious](https://forum.glyphsapp.com/u/gor.jious)\
**Post date:** [February 24, 2023, 3:25pm UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/9 "2023-02-24T15:25:21Z")

</div>

Got to say that it is a really fascinating experience using this. We (yes, we) managed to make this fairly involved (at least for an amateur coder like myself) script that can add guidelines to nodes at custom or preset angles and ratios.

 ![Screenshot 2023-02-23 at 18.12.13](https://forum.glyphsapp.com/uploads/default/original/3X/b/2/b26b8867b66707748d48bb89e784d18e9d533ba4.png)

I had the basic idea of what it should do and started asking it to build things up slowly. Things like: _make a window_ then _add a button_ then _trigger that button to add a guideline_. A working prototype came together quickly but then it was a lot of back and forth getting to add all the other functionality, exceptions, checks, etc.

As wholly impressive as it is, there are times when it can become frustrating because apparently there is a some sort of character limit so at a certain point it will just stop generating mid-way if there is too much. Then when you try to ask it to remove something or make it simpler or only do a certain part it would get confused or change things that somehow introduce an error. What is interesting though that sometimes when you feed back the error message it can fix it (or not).

It was quite a long process but certainly not as long as it would be if I had to dedicate the time to figure it out by finding similar scripts, posting on the forum, stackoverflow, youtube etc…it actually probably wouldn’t even have the same result because I find so many ideas come in the moment while testing iterations that it becomes quite easy to ask it “can we also try to add a button that does this…” and have a new prototype in a short amount of time.

All this to say that I hope it encourages more people who have ideas to make more tools and not let python skill level slow you down.

If anyone would like to try out the script, it is available in the newly minted github repo [gorjious-glyph-scripts](https://github.com/gorjious/gorjious-glyphs-scripts)

---

<div class="post-metadata">

**Author:** ![Tosche](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/tosche/32/412_2.png) [@Tosche](https://forum.glyphsapp.com/u/Tosche)\
**Post date:** [February 24, 2023, 4:31pm UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/10 "2023-02-24T16:31:10Z")

</div>

I noticed the length limit too. I think it might be better to make a separate inquiry thread entirely and ask for smaller chunks, assuming you know how to connect them.

---

<div class="post-metadata">

**Author:** ![HugoJ](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/hugoj/32/30341_2.png) [@HugoJ](https://forum.glyphsapp.com/u/HugoJ)\
**Post date:** [February 24, 2023, 4:37pm UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/11 "2023-02-24T16:37:54Z")

</div>

There are chrome extensions that allow the user to create complex prompts in ChatGPT. (AIPRM for example)  
It work pretty well !

---

<div class="post-metadata">

**Author:** ![gor.jious](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/gor.jious/32/9472_2.png) [@gor.jious](https://forum.glyphsapp.com/u/gor.jious)\
**Post date:** [February 24, 2023, 4:38pm UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/12 "2023-02-24T16:38:57Z")

</div>

Had to do that a few times. Just have to be wary of it changing the names of variables, methods, and such.

Oh cool will check it out.

---

<div class="post-metadata">

**Author:** ![George\_Thomas](https://forum.glyphsapp.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@George\_Thomas](https://forum.glyphsapp.com/u/George_Thomas)\
**Post date:** [February 24, 2023, 6:38pm UTC](https://forum.glyphsapp.com/t/chatgpt-can-write-python-for-glyphs/25157/13 "2023-02-24T18:38:48Z")

</div>

Here’s another type of code generator that may be of interest. Uses education-standard pseudocode as input. I have not tried it but intend to.

> **[Pseudocode to Python Converter - PseudoEditor](https://pseudoeditor.com/converters/pseudocode-to-python)**
>
> Convert your pseudocode to python easily online right here, saving your hours of time!
