Arguments shown in recorded macro

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
drmacro
Veteran
Posts: 8980
Joined: Sun Mar 02, 2014 4:35 pm

Arguments shown in recorded macro

Post by drmacro »

Two macros recorded one in sketch edit mode, one not in edit mode, same vertex selected.

Code: Select all

# -*- coding: utf-8 -*-

# Macro Begin: /home/mac/SharedData/FC_common/SelectInEdit.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
import FreeCAD

# Gui.runCommand('Std_DlgMacroRecord',0)
# Gui.Selection.addSelection('Unnamed','Body','Sketch.Vertex4',30,-10,0.012,False)
# Macro End: /home/mac/SharedData/FC_common/SelectInEdit.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++

Code: Select all

# -*- coding: utf-8 -*-

# Macro Begin: /home/mac/SharedData/FC_common/SelectInModel.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
import FreeCAD

# Gui.runCommand('Std_DlgMacroRecord',0)
# Gui.Selection.clearSelection()
# Gui.Selection.addSelection('Unnamed','Body','',30,-10,0)
# Macro End: /home/mac/SharedData/FC_common/SelectInModel.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
Where are the arguments shown in the following lines documented?

Code: Select all

# Gui.Selection.addSelection('Unnamed','Body','Sketch.Vertex4',30,-10,0.012,False)

Code: Select all

# Gui.Selection.addSelection('Unnamed','Body','',30,-10,0)
I know these are included as what the UI did and are included as comments.

So:
  • 'Unnamed' is the document
  • 'Body' is in the tree
  • the next argument is obviously what was selected
  • 30,-10,0.012 is the mouse position on the click??? and why is Z anything other than 0.0?
  • False??? used in one but not the other...why???
For that matter, where are any of these arguments documented?

Go to the wiki https://wiki.freecadweb.org/Selection_API and it says obsolete...and doesn't detail the arguments anyway. :roll:
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Arguments shown in recorded macro

Post by onekk »

Don't know all the answers, but:

why the z is not 0.0, it could be because if numbers are mouse positions, maybe you've not selected the same thing:

Code: Select all

'Unnamed','Body','Sketch.Vertex4',30,-10,0.012,False)
You have selected a Vertex, note the name Sketch.Vertex4 for the 0.012 maybe (not 100% sure) is the "position of the click" not the position off the "vertex" itself.

Code: Select all

Gui.Selection.addSelection('Unnamed','Body','',30,-10,0)
This is a selection at point (30,-10,0) of the "Body" solid, or line or whatever else is "Body" not the empty '' after "Body" indicating that the selection has not a Topological name, in other word, is not an edge, vertex, face or other relevant topological "component".

If you type in the pyhton console this print command

Code: Select all

print(Gui.Selection.addSelection.__doc__)
addSelection(object,[string,float,float,float]) -- Add an object to the selection
where string is the sub-element name and the three floats represent a 3d point
Probably the docstring is not updated as it lacks of the first component, I could guess:

Code: Select all

addSelection(document, object,[string,float,float,float]) 
as Unnamed resemble the default document prior to a save action that ask and assign a name.

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/
drmacro
Veteran
Posts: 8980
Joined: Sun Mar 02, 2014 4:35 pm

Re: Arguments shown in recorded macro

Post by drmacro »

onekk wrote: Thu Apr 29, 2021 3:19 pm ...
why the z is not 0.0, it could be because if numbers are mouse positions, maybe you've not selected the same thing:
...
You'll note that the non-zero Z value is not in the selection from 3D, but from the open sketch. How then could the mouse not get a zero Z value?

In addition, the horizontal/vertical constraints of the vertex are set to 30,10 in the sketch. And the Sketch Attachment and Placement Z values are 0.0.
🤔
Probably the docstring is not updated as it lacks of the first component, I could guess:

...
I am aware of the doc strings. But, I submit it is of little value, unless you have some idea what is described.

Clearly the argument from the doc string is not current, since in one case there is a boolean argument.

So, is the Boolean optional? Are any of them optional? Unknown from the doc string... :(
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Arguments shown in recorded macro

Post by onekk »

Sadly after some research in my local copy of ./Mod sources (taken from a not very recent AppImage), there is no such thing, I suspect that it is in App or Gui part of FreeCAD sources.

for Z values, take in account, that number shown as mouse position, are "derived" from the "scenegraph" (Coin 3D) that are not the "3d model" itself, but his "graphics representation" so some misalignement are to be take in account.

The most visible thing, is the "polygonalization" of circular edges, like cylinder circles, that are "perfect circular" on the "3d model", but are interpolated by "Coin 3D" as polygons, see the image:
coin3d.png
coin3d.png (10.19 KiB) Viewed 357 times
These value control the match between the internal representation of the "3d model" that is "precise" as it is derived by mathematical operation, and the "triangulated" representation (pratically a 3d mesh) done by Coin3D to show it on the screen.

This is one of "the most forgotten things" of FreeCAD. You have two engines:

1) the "modelling engine" OCCT and the Part workbench that contains most of the OCCT "exposed interface"
2) the "rendering engine" Coin3D, (That follow the standard version of OpenInventor) that is "crunching triangles" to pass to the graphics hardware that with good approximation is showing vertexes.

And you have to cope with this things.

To return to the topics.

mouse position are relative to Coin3D but are also managed by the Qt interface, mouse position are passed by "Qt to "Coin3D" and I supose that Coin3D will translate the X,Y mouse position to his internal 3D representation to output the (X, Y, Z) position of the model.

So with so much conversion, some misalignement is a very "normal thing".

If you want the exact position you could take the "name of the subelement" and retrieve is "modeling engine" coordinate by yourself.

Obviously as I'm not an expert, but only a "intermediate" user, i could stop here, and i will be very interested if some developer will come in an explain some more:

@chrisb or @wmayer, maybe will note this citation and will give an "autohritative explanation".

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/
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Arguments shown in recorded macro

Post by openBrain »

The 12 um offset is due to how Sketcher renders geometry to ensure correct items layering and prevent Z fighting display (with axis and all this).

For 'addSelection', arguments are :
* Document
* Object
* Subobject
* Click point
* Reset preselection (True/False, default = False)

Notice that there exist several different "signatures" for 'addSelection' call. ;)
Post Reply