find the center of a circle with python
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
find the center of a circle with python
I made a circle that is tangent to two circles and a point, now I would like to find the center of the circle using python. I know I can just click on it and it will tell me in the python console, but I need to automate this process. Any thoughts?
Re: find the center of a circle with python
If it is shown in the Python console, can't you use the commands shown there as well?
If you need more help, it could be helpful to attach the file. We don't even know if you use Sketcher or Draft workbench for the circle.
If you need more help, it could be helpful to attach the file. We don't even know if you use Sketcher or Draft workbench for the circle.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: find the center of a circle with python
hi
with object selected in 3D view
given the name
EDIT: 20/04/2021 12h21 Paris adding the code for search radius given name
mario
with object selected in 3D view
Code: Select all
try:
selectedEdge = FreeCADGui.Selection.getSelectionEx()[0].SubObjects[0] # select one element
print(selectedEdge.Curve)
print(selectedEdge.Curve.Radius)
print(selectedEdge.Curve.Center)
except Exception:
print("Oups")
Code: Select all
selectedEdge = App.ActiveDocument.getObject("Circle") # name of circle
print(selectedEdge.Shape.Edge1.Curve) # Edge1 = numero of edge
print(selectedEdge.Shape.Edge1.Curve.Radius)
print(selectedEdge.Shape.Edge1.Curve.Center)
mario
Last edited by mario52 on Tue Apr 20, 2021 10:23 am, edited 1 time in total.
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
Re: find the center of a circle with python
When you are asking for python help, better to put some code on which someone could work on.
Maybe answer is a matter of a line or two.
But it depends on what you want to achieve.
You made circle how. With scripting or using the GUI?
Maybe answer is a matter of a line or two.
But it depends on what you want to achieve.
You made circle how. With scripting or using the GUI?
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: find the center of a circle with python
Hi
mario
good reflection I added the code for a named object
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.