How to capture sketcher commands?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

How to capture sketcher commands?

Post by freedman »

While in Sketcher Edit mode I see commands in the Python console like this when a tool is clicked on:
>>> Gui.runCommand('Sketcher_CompConstrainRadDia',0)
>>> Gui.runCommand('Sketcher_CompCreateFillets',0)
>>> Gui.runCommand('Sketcher_CompCreateBSpline',0)

How can I capture these commands from the console? I'm running a macro and I want to know what sketcher is currently doing.
Thank you
CoderMusashi
Posts: 92
Joined: Mon Nov 19, 2018 8:26 pm

Re: How to capture sketcher commands?

Post by CoderMusashi »

You sure can by using the Record macro button....
Attachments
macrorecorder.png
macrorecorder.png (183.94 KiB) Viewed 1522 times
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: How to capture sketcher commands?

Post by freedman »

I did some testing using this:

Code: Select all

 
mw=Gui.getMainWindow()   
self.t_console=mw.findChild(QtGui.QPlainTextEdit, "Python console")
I don't know enough about python but this looks like the python console is a text based object. I tried a couple things and it's apparent that with a little work all the sketcher commands could be captured. The text comes in what they call blocks. My goal is to know when external geo is selected.

Reading the python text can get us the current sketcher command but there is no feedback to know when the command is cleared, this will take monitoring "Esc or right mouse click".
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: How to capture sketcher commands?

Post by openBrain »

freedman wrote: Fri Oct 29, 2021 5:24 am My goal is to know when external geo is selected.
What do you mean? When 'External geomtry' command is run? Or when the user select a 'external geometry' of the sketch?
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: How to capture sketcher commands?

Post by freedman »

What do you mean? When 'External geometry' command is run? Or when the user select a 'external geometry' of the sketch?
I wanted to know when 'External geometry' is selected and when it's deselected. This is a follow-on of this post:
https://forum.freecadweb.org/viewtopic. ... al#p512170

Ultimately, my goal was a macro to try a visualization approach, while in sketch-edit if the user selects 'External geometry' do this:
1) Tilt the camera view 5 degrees
2) Set to Wireframe
3) Trigger a dialog to select the object (hide unselected) under the cursor.

And of coarse undo all of that when 'External geometry' is de-selected.

I know that getting this info from the python console is far from ideal but Sketcher is not exposing itself much. If nothing else maybe this will inspire some API work for Sketcher.
Post Reply