Import DrawBot in Plugin

I’ve installed drawBot plugin via manager and try to draw something as a svg.

After testing my code in macro with a demo window based on vanilla, I want to port it to my plugin. When I want to import drawBot in the plugin via

from drawBot import *

it shows an error after restarting:

ModuleNotFoundError: No module named 'drawBot'

Thus, I’ve try to copy the drawbot lib folder from DrawBot.glyphsPlugin/Contents/Resources/drawBot to my plugin’s Resources folder to try to access the lib. This time it returns another error:

However, I’ve checked that all of module in Plugin Manager has been installed, and the Python version I use shows 3.9.1 (Glyphs) in preference.

How to solve this issue to import the drawBot? I think I was install the drawBot lib.

Does drawBot only works in macro and drawBot UI? Or does it means that I can only call drawBot by a script, rather than a plugin?

Thank you.

You could try to add these lines to the start method of your plugin:

from sys import path

Then you can see if the drawBot plugin is in you path. It should list something like /Users/<user>/Library/Application Support/Glyphs 3/Repositories/DrawBotGlyphsPlugin/DrawBot.glyphsPlugin/Contents/Resources, and if this is contained in the list, you should be able to import from drawBot.

But I think this was broken in a couple of Glyphs versions. Maybe try updating to the most recent version?

Thanks for your reply!

I’ve check that /Users/<user>/Library/Application Support/Glyphs 3/Repositories/DrawBotGlyphsPlugin/DrawBot.glyphsPlugin/Contents/Resources is in my path, and also update to the latest Glyphs version.

However, the plugin still get the error while trying to import drawBot module. :frowning:

It might be that the plugins are loaded in the “wrong” order. Meaning that your plugin is loaded before the Drawbot plugin. What you can do, is to add the from drawBot import * into the function that needs the drawbot stuff. Because by the time your code is run, the drawbot should be there.

You’re right, I’ve fixed this error by importing module inside function rather than on the top of begining. Thank you very much.