[Solved] Get arc angle and radius

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Get arc angle and radius

Post by jfc4120 »

Thanks for the answer, I'm on mobile now will try later, that would give me last angle, what command would give me the first angle, in case I need it?
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: Get arc angle and radius

Post by heda »

Snip macro screenshot-4f2d35.png
Snip macro screenshot-4f2d35.png (55.52 KiB) Viewed 389 times
User avatar
Roy_043
Veteran
Posts: 8540
Joined: Thu Dec 27, 2018 12:28 pm

Re: Get arc angle and radius

Post by Roy_043 »

jfc4120 wrote: Wed Oct 05, 2022 6:12 pm Thanks for the answer, I'm on mobile now will try later, that would give me last angle, what command would give me the first angle, in case I need it?

Code: Select all

Gui.Selection.getSelectionEx()[0].SubObjects[0].FirstParameter
Some of the confusion in this topic is due to the fact that we do not know which objects you are using. Posting a sample file could have avoided this.
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Get arc angle and radius

Post by jfc4120 »

Thanks everyone. I am still getting used of getSelectionEx and getSelection. Prior I mainly was focusing on points.

I ended up with:

Code: Select all

# -*- coding: utf-8 -*-
import FreeCAD, FreeCADGui
import Draft
import math

# from math import cos, sin, radians
from PySide import QtGui
convert = 25.4

Vector, Placement = App.Vector, App.Placement
doc = App.ActiveDocument


#RAD = Gui.Selection.getSelectionEx()[0].SubObjects[0].Curve.Radius * .039370078
# Either of these lines work
RAD = Gui.Selection.getSelection()[0].Radius * .039370078
RAD = float(RAD)

print(RAD)

FA = Gui.Selection.getSelection()[0].FirstAngle
FA = float(FA)
LA = Gui.Selection.getSelection()[0].LastAngle
LA = float(LA)

print(FA)
print(LA)
DEG = LA - FA

ARCLN = .0174533 * RAD * DEG
print('Arc length = ', ARCLN)

# more code later will be for a drop cheek elbow
I notice two ways to get radius:

Code: Select all

RAD = Gui.Selection.getSelectionEx()[0].SubObjects[0].Curve.Radius * .039370078
# or
RAD = Gui.Selection.getSelection()[0].Radius * .039370078
But did not work for degree.

Is there some master API code somewhere that covers things like: Gui.Selection.getSelectionEx()[0].SubObjects[0].FirstParameter

I see the regular documentation, but how do you guys come up with all the various other options like radius, LastAngle, etc. There has got to be documentation for this stuff.

Edit:

I experimented with LastParameter and FirstParameter also:

Code: Select all

TA = Gui.Selection.getSelectionEx()[0].SubObjects[0].LastParameter * 57.295779513082
I am still trying to figure out why freecad has LastParameter instead of just LastAngle in this case. How did someone derive at LastParameter.

But from what I have seen, many pick up these things from the forum, as there are places in the documentation that don't have deeper examples.
Again that you for the help to everyone.
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: [Solved] Get arc angle and radius

Post by heda »

"how do you guys come up with all the various"

blood, sweat and tears?

"There has got to be documentation"

not necessarily, there is no nature law that auto magically creates understandable documentation
unless someone puts in the time to do it, there is no documentation, and since there are no paying customers,
well, noone can be forced to make documentation..., so it is completely reliant upon some nice souls making it.

given that, the documentation is imho good enough once the penny drops on where to find the traces of a chord which one can pull and try to put things together in a way that one can get over the hurdle at hand.

good enough here does not necessarily mean rated as good for a newcomer, but rather subjectively i would say it is once one figures out the basic possible avenues where one could expect to find some sort of info that is useful in getting further with a bit of imagination and experimentation. and it helps if you are willing to oversee that not everything is perfect and that part of the journey is to learn how to figure things out without everything served on a silver plate...

so how to get around this...

for one, whatever you see in the Property_editor is always available (on the document object itself).
generally, for every object that is listed on the wiki, see Draft_Arc#Properties

for things like what is in .Curve...
6 approaches
a) help(obj.method) or help(obj.attribute) in the console - might be cryptic though
b) trial and error (very effective when done in console on real objects)...
c) Std_PythonHelp is useful to at least know about, basically the same as help() in console
d) https://freecad.github.io/SourceDoc/
e) reading source code
f) web searches with specific code fragments, i.e. "obj.method" is more likely to bring something useful than searches of the type "how do I"

when coding in python, doing the trial and error and exploring of real objects is possible - and surprisingly effective, that particularity of dynamic languages is indeed quite opposite to a compiled language where trial and error is just frustrating and more or less everything has to be figured out by documentation.

at last, if you have a draft/arc that is not really the geometry of an arc, it is just a "view of something that represents the arc", it is a wrapper around another wrapper, first wrapper is a part object (belonging to fc) which in turn is a wrapper around the geometric kernel (occ) object that describes an arc at it's lowest level (disclaimer, this description might not be 100% correct, but to get the gist of how things are wrapped in several layers i gather it is good enough).
more specifically, LastAngle is a fc property made to make it easy on users, whereas LastParameter comes from the occ-object, i.e. the geometric kernel. (and if i am wrong in any of this, i'm sure people will correct me :-))
Post Reply