Detect when external geo is selected in Sketcher
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Detect when external geo is selected in Sketcher
Does anyone know how I would go about detecting this, I know when I'm in Sketcher but how would I know if external geo selecting is active? I was hoping to do something to help select external geo.
Thanks
Thanks
Re: Detect when external geo is selected in Sketcher
I not a Python guy, but I think power users will need a more complete explanation to know what you are referring to exactly.
Do you want to know if a specific tool (command) is active? This is, if the user has clicked the external link geometry tool in the toolbar?
Do you want to set a filter to only select external geometry?
Do you want to know if geometry selected is external geometry?
Re: Detect when external geo is selected in Sketcher
This is it exactly.Do you want to know if a specific tool (command) is active? This is, if the user has clicked the external link geometry tool in the toolbar?
I only work with macros so it would be a python thing for me. I don't think this your department , this has got to be a Gui, App, Qt thing. I will work this out another way, sorry for the interruption.
Thank you
Re: Detect when External Geo is selected in Sketcher
I still have an issue. Detecting when External geo is selected all worked great by detecting the mouse click on the icon. Now, is there a way to know when the user has cleared external geo? Is there a Python way to get Sig, Flag, bool or something to trigger on.
I believe this would be a (internal to Sketcher) operation, updating the status of flags. I could probably use when the cursor returns to a standard pointer or no tools are currently selected, something like that.
Thanks
I believe this would be a (internal to Sketcher) operation, updating the status of flags. I could probably use when the cursor returns to a standard pointer or no tools are currently selected, something like that.
Thanks
Last edited by freedman on Mon Jun 21, 2021 5:33 pm, edited 2 times in total.
Re: Detect when external geo is selected in Sketcher
Sorry if this could seem a joke, but sometimes, the right question led to the right answer.
Maybe my guess is wrong, but maybe it could address the problem, as reading this thread it seems that the "point" is not so "clear"
Usually you could check the state of a button "pressed" "not pressed".
(don't take the word as commands)
the correct question now behave like:
How to retrieve the status of the "external geo" button?
In this way you have to find the proper widget and check for the correct property, sadly to retrieve a Qt Widget you have to do some assumptions, if you know the name it is as simple to write:
and then check:
According to this page is possible to check the pressed state:
https://doc.qt.io/qtforpython-5/PySide2 ... .isChecked
More generally these are the Widgets:
https://doc.qt.io/qtforpython-5/PySide2 ... .QtWidgets
Note that FreeCAD use a slightly different hierarchy from PySide2 as it translate the QtWidgets to be "compatible" to the old Pyside 1.x scheme to mantain retro compatibility.
Hope it helps.
Regards
Carlo D.
Maybe my guess is wrong, but maybe it could address the problem, as reading this thread it seems that the "point" is not so "clear"
Usually you could check the state of a button "pressed" "not pressed".
(don't take the word as commands)
the correct question now behave like:
How to retrieve the status of the "external geo" button?
In this way you have to find the proper widget and check for the correct property, sadly to retrieve a Qt Widget you have to do some assumptions, if you know the name it is as simple to write:
Code: Select all
wid = self.tabw.findChild(QtCore.QObject, 'object_name')
Code: Select all
wid.isDown()
https://doc.qt.io/qtforpython-5/PySide2 ... .isChecked
More generally these are the Widgets:
https://doc.qt.io/qtforpython-5/PySide2 ... .QtWidgets
Note that FreeCAD use a slightly different hierarchy from PySide2 as it translate the QtWidgets to be "compatible" to the old Pyside 1.x scheme to mantain retro compatibility.
Hope it helps.
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Detect when external geo is selected in Sketcher
I have tried every flag that I could, within reason. I have the signal for External Geo selected, I need the de-selection.
isChecked, isDown, isEnabled, isModal, checkStateSet, click..... nothing seems to reflect the change in state.
I was hoping this would work; "disconnectNotify" , but no.
It seems the only way to know what flags are updated is to ask the coder or go search the source file of Sketcher.
Thanks
isChecked, isDown, isEnabled, isModal, checkStateSet, click..... nothing seems to reflect the change in state.
I was hoping this would work; "disconnectNotify" , but no.
It seems the only way to know what flags are updated is to ask the coder or go search the source file of Sketcher.
Thanks
Re: Detect when external geo is selected in Sketcher
I have considered looking at the cursor pointer, it changes when Exterrnal geo is selected and not. This could be a good choice because many of Sketchers functions change the cursor pointer. That looks hard.
From a logic standpoint Sketcher uses the ESC key/Right mouse click/select some else to exit External Geo, I was hoping not to go down that path, trying to keep it simple.
From a logic standpoint Sketcher uses the ESC key/Right mouse click/select some else to exit External Geo, I was hoping not to go down that path, trying to keep it simple.
Re: Detect when external geo is selected in Sketcher
try to put some code, so maybe some kindly guy could try to recreate the condition and test something.
It is difficult to cope with complex things in an abstract way.
This is the main reason why in many coding forum, no answer are given if there is no a MWE (Minimal working Example) that show the problem, so it could be reproduced and some test could be done.
Regards
Carlo D.
It is difficult to cope with complex things in an abstract way.
This is the main reason why in many coding forum, no answer are given if there is no a MWE (Minimal working Example) that show the problem, so it could be reproduced and some test could be done.
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Detect when external geo is selected in Sketcher
I get that.It is difficult to cope with complex things in an abstract way.
Here is a macro that works. Best way to use; open any model, open a sketch and just leave it open. Run the macro and click on any feature in the tree, this will start the connection and a 1 sec timer that prints the status from the timer. You can click on the External geo icon and it will report.
Thank you
- Attachments
-
- 10020_short.FCMacro
- (2.94 KiB) Downloaded 27 times
Re: Detect when external geo is selected in Sketcher
probably easier than you think, and why not use pivy for the exit?
- qt for toolbar button
- set your own flag, and hook up a pivy observer (the flag implies that you need to roll your own class for the whole thing)
- once esc-key or right-click is detected, do your thing and then flip the flag & unhook the observer
should be pretty straight forward...
Code_snippets#Observe_mouse_events_in_the_3D_viewer_via_Python
Code_snippets#Display_keys_pressed_and_Events_command
Pivy (example of unhook on the fly...)
Last edited by heda on Tue Jun 22, 2021 9:43 pm, edited 1 time in total.