possible to write python code from extetrnal editor and run in freecad?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: possible to write python code from extetrnal editor and run in freecad?

Post by DeepSOIC »

emills2 wrote: Sun Sep 01, 2019 9:48 pm can you share a bit more info on how to make work in py3?
just from importlib import reload, and then do the stuff you did in py2, maybe it just works. As I said, I had limited success with reload, with both py2 and py3, and I can't really tell you much.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: possible to write python code from extetrnal editor and run in freecad?

Post by DeepSOIC »

Bad Blue Bull wrote: Sun Sep 01, 2019 2:52 pm I don't know how to access stuff created in this scirpt from console.
Like I assign a value to a variable x, how can I access the variable from console?
I have this hack for when I want to play with an object created somewhere deep in a script:
insert this to your script:

Code: Select all

#debug
FreeCADGui.doCommand(
    'import ctypes\n'
    'my_stupid_faulty_object = ctypes.cast({id}, ctypes.py_object).value'.format(id= repr(id(x)))
)
then, the object in your "x" variable will be available in py console as my_stupid_faulty_object, after your script runs the inserted bit.
usbhub
Posts: 280
Joined: Tue Apr 02, 2019 8:22 pm
Location: Earth

Re: possible to write python code from extetrnal editor and run in freecad?

Post by usbhub »

Why so complicated? Just edit your .py file with the (external) editor you want and save. But I don't know, if its working with own workbenches too, but for macros, it works fine. (I write my macros only with an external editor)

usbhub
Post Reply