Attacher: Python version of attachment editor

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
DeepSOIC
Veteran
Posts: 7900
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Attacher: Python version of attachment editor

Post by DeepSOIC »

I started implementing a python attachment editor dialog.
https://github.com/DeepSOIC/FreeCAD-PyAttachmentEditor/
It is currently in its very infancy, and the only thing it does is editing superPlacement x coordinate working quite well.

How to run:
copy repository to AttachmentEditor directory made in macros directory.
Then select the object, and run this in console:

Code: Select all

from AttachmentEditor import TaskAttachmentEditor as tae
tae.editAttachment()
It requires Py interface of Attacher, that is currently in pull request was merged.
User avatar
DeepSOIC
Veteran
Posts: 7900
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Attacher: Python version of attachment editor

Post by DeepSOIC »

Almost there :ugeek:
py-attachment-ui-workinprogress.png
py-attachment-ui-workinprogress.png (69.95 KiB) Viewed 2291 times
User avatar
DeepSOIC
Veteran
Posts: 7900
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Attacher: Python version of attachment editor

Post by DeepSOIC »

Bonus. Attachment dialog now works with non-attachable objects :P Non-parametric, of course, but fun to play with anyway!
py-attachment-ui-workinprogress2.png
py-attachment-ui-workinprogress2.png (193.8 KiB) Viewed 2277 times
py-attachment-ui-workinprogress2.FCStd
(10.75 KiB) Downloaded 59 times
cox
Posts: 971
Joined: Wed Nov 26, 2014 11:37 pm

Re: Attacher: Python version of attachment editor

Post by cox »

@DeepSOIC, Wow you amaze me. Thanks :D
Need help? Feel free to ask, but please read the guidelines first
User avatar
DeepSOIC
Veteran
Posts: 7900
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Attacher: Python version of attachment editor

Post by DeepSOIC »

New cool feature: smart visibility.
Let's suppose you want to edit attachment of a datum plane in middle of history:
py-attachment-ui-workinprogress3-0.png
py-attachment-ui-workinprogress3-0.png (108.71 KiB) Viewed 2243 times
Start editing:
py-attachment-ui-workinprogress3-1.png
py-attachment-ui-workinprogress3-1.png (86.88 KiB) Viewed 2243 times
Finish editing: visibility restored
py-attachment-ui-workinprogress3-2.png
py-attachment-ui-workinprogress3-2.png (106.67 KiB) Viewed 2243 times
I think there are many places where this logic might be useful. The helpful object is in TempoVis.py.
Usage example:

Code: Select all

#obj = feature about to be edited
tv = TempoVis(obj.Document)
tv.hide_all_dependent(self.obj)
tv.show(self.obj)
tv.show([obj for (obj,subname) in self.attacher.References])

#when finished:
tv.restore()
#or
del(tv)
User avatar
DeepSOIC
Veteran
Posts: 7900
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Attacher: Python version of attachment editor

Post by DeepSOIC »

The Py interface of Attacher was merged recently. So you should be able to try the attachment editor.
User avatar
f3nix
Posts: 346
Joined: Sat May 30, 2015 11:58 am

Re: Attacher: Python version of attachment editor

Post by f3nix »

Hi,
I get a crash on Linux after last changes:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
0x00007fffcbc44dc9 in initPartGui () at /home/f3nix/devel/freecad/FreeCAD/src/Mod/Part/Gui/AppPartGui.cpp:126
126         Py_INCREF(pAttachEngineTextsModule);
(gdb) bt
#0  0x00007fffcbc44dc9 in initPartGui () at /home/f3nix/devel/freecad/FreeCAD/src/Mod/Part/Gui/AppPartGui.cpp:126
#1  0x00007ffff59b4437 in _PyImport_LoadDynamicModule () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#2  0x00007ffff59b5250 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#3  0x00007ffff59b64aa in PyImport_ImportModuleLevel () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#4  0x00007ffff596d598 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#5  0x00007ffff59c9933 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#6  0x00007ffff5a72917 in PyEval_CallObjectWithKeywords () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#7  0x00007ffff5962496 in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#8  0x00007ffff5a734ec in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#9  0x00007ffff595ea59 in PyEval_EvalCode () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#10 0x00007ffff59dc8b6 in PyRun_StringFlags () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#11 0x00007ffff5f6232e in Base::InterpreterSingleton::runString[abi:cxx11](char const*) (this=0x6a1aa0, sCmd=0x7fffccbb5a47 "import PartGui") at /home/f3nix/devel/freecad/FreeCAD/src/Base/Interpreter.cpp:196
#12 0x00007fffcca87722 in initPartDesignGui () at /home/f3nix/devel/freecad/FreeCAD/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp:108
#13 0x00007ffff59b4437 in _PyImport_LoadDynamicModule () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#14 0x00007ffff59b5250 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#15 0x00007ffff59b64aa in PyImport_ImportModuleLevel () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#16 0x00007ffff596d598 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#17 0x00007ffff59c9933 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#18 0x00007ffff5a72917 in PyEval_CallObjectWithKeywords () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#19 0x00007ffff5962496 in PyEval_EvalFrameEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#20 0x00007ffff5a734ec in PyEval_EvalCodeEx () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#21 0x00007ffff59f5450 in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#22 0x00007ffff59c9933 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#23 0x00007ffff5a1d61c in ?? () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#24 0x00007ffff59c9933 in PyObject_Call () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#25 0x00007ffff5a72917 in PyEval_CallObjectWithKeywords () from /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
#26 0x00007ffff71e3c73 in Py::Callable::apply (this=0x7fffffffc1a0, args=...) at /home/f3nix/devel/freecad/FreeCAD/src/CXX/Python2/Objects.hxx:3215
#27 0x00007ffff71da5e1 in Gui::Application::activateWorkbench (this=0x7fffffffcc40, name=0x975a80 "PartDesignWorkbench") at /home/f3nix/devel/freecad/FreeCAD/src/Gui/Application.cpp:1054
#28 0x00007ffff71df506 in Gui::Application::runApplication () at /home/f3nix/devel/freecad/FreeCAD/src/Gui/Application.cpp:1762
#29 0x0000000000408db2 in main (argc=1, argv=0x7fffffffe0a8) at /home/f3nix/devel/freecad/FreeCAD/src/Main/MainGui.cpp:235
Cheers,
Mateusz
User avatar
DeepSOIC
Veteran
Posts: 7900
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Attacher: Python version of attachment editor

Post by DeepSOIC »

f3nix wrote:Hi,I get a crash on Linux after last changes:
This may be the fix. Can you try please?
https://github.com/DeepSOIC/FreeCAD-ell ... 6e2833a4c0
User avatar
yorik
Founder
Posts: 13466
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Attacher: Python version of attachment editor

Post by yorik »

I had no crash at startup but the self-tests indeed crashed. Your latest fix works for me, and I merged the pull request
User avatar
f3nix
Posts: 346
Joined: Sat May 30, 2015 11:58 am

Re: Attacher: Python version of attachment editor

Post by f3nix »

DeepSOIC wrote:
f3nix wrote:Hi,I get a crash on Linux after last changes:
This may be the fix. Can you try please?
https://github.com/DeepSOIC/FreeCAD-ell ... 6e2833a4c0
Hi,
it does work as expected! :) Thank you!

Cheers,
Mateusz
Post Reply