[Solved] Opening a file containing a FeaturePython from macro: how to ensure the class is imported properly?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
mnesarco
Posts: 446
Joined: Thu Mar 26, 2020 8:52 pm

Re: Opening a file containing a FeaturePython from macro: how to ensure the class is imported properly?

Post by mnesarco »

suzanne.soy wrote: Wed Jan 20, 2021 9:21 pm That's what I've been doing so far, but it prevents distribution using Tools → Addon manager → Macros (or Tools → Addon manager → Workbenches).
Macros can be distributed inside Mod. The Addon manager install macros found inside Mods.
suzanne.soy
Posts: 54
Joined: Sat Dec 19, 2020 11:55 pm

Re: Opening a file containing a FeaturePython from macro: how to ensure the class is imported properly?

Post by suzanne.soy »

That's great to know, I'll try experimenting a bit and post a template here / on the wiki. Marking as solved :)
:?: Please mark your posts as [solved] :!:
:idea: If the answer you got is a good fit for the wiki, you can edit it!
FreeCAD modelling & coding workbenches+macros: twitch GitHub
jmcornil
Posts: 133
Joined: Mon Nov 02, 2020 9:16 am
Location: Versailles (France)
Contact:

Re: Opening a file containing a FeaturePython from macro: how to ensure the class is imported properly?

Post by jmcornil »

mnesarco wrote: Tue Jan 19, 2021 12:42 pm
3. Rename your file to init_gui.py and put it in the new directory
4. Put an empty file there too named __init__.py
Why do you insist on renaming the file to init_gui.py ?
I thought the presence of an empty file called __ init __.py
was enough for any anything.py file to be imported as a module.
Anyway it seems to work for me.
User avatar
mnesarco
Posts: 446
Joined: Thu Mar 26, 2020 8:52 pm

Re: Opening a file containing a FeaturePython from macro: how to ensure the class is imported properly?

Post by mnesarco »

jmcornil wrote: Wed Feb 10, 2021 4:12 pm Why do you insist on renaming the file to init_gui.py ?
I thought the presence of an empty file called __ init __.py
was enough for any anything.py file to be imported as a module.
Anyway it seems to work for me.
Yes you are right. I usually keep __init__.py empty and put code in init_gui.py because many of my extensions requires gui. But this is not mandatory at all, it was a suggestion. In programing there is always more than one way to achieve something.
Post Reply