Drilling down to info of selected object

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: 9003
Joined: Sun Mar 02, 2014 4:35 pm

Drilling down to info of selected object

Post by drmacro »

My goal is to write a script where the user selects an edge (in this particular case it's a circle displayed in a view in a TechDraw page)

I want to access the center point and the radius.

I have done this by hand at the python console, but I used:

Code: Select all

myobj.FreeCAD.ActiveDocument.View.getEdgeByIndex(4)
myobj.Curve.Location   # the center, returns a Vector
myobj.Curve.Radius     # returns a real
Problem is I want to use what the user has selected, but, I can't figure out to get the same info from:

Code: Select all

sel = FreeCADGui.Selection.getSelection()
I have gone through lots of examples and looked at the api wiki pages...but, have not been able to sort it out of what I've seen to this point. :oops:

It seems I can never figure out how to drill down to the bits I need. :roll:
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Drilling down to info of selected object

Post by TheMarkster »

Code: Select all

edge = Gui.Selection.getSelectionEx()[0].SubObjects[0]
You'll want to do some error checking, of course.
Post Reply