How can i take the x, y, and z of the axis by a part object in python?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
frmgr
Posts: 3
Joined: Fri Sep 23, 2022 8:35 am

How can i take the x, y, and z of the axis by a part object in python?

Post by frmgr »

myCylinder = FreeCAD.ActiveDocument.getObject("Cylinder")
yc = float (myCylinder.Placement.Base.y)

I use this code to take the y value of the position. How can i do to take the value of the y of the axis?


(version 0.20.1 windows)
chrisb
Veteran
Posts: 54168
Joined: Tue Mar 17, 2015 9:14 am

Re: How can i take the x, y, and z of the axis by a part object in python?

Post by chrisb »

I may not understand: The origin of a cylinder is on the axis. Getting the y value of the cylinder gives you the y value of the axis.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
frmgr
Posts: 3
Joined: Fri Sep 23, 2022 8:35 am

Re: How can i take the x, y, and z of the axis by a part object in python?

Post by frmgr »

Sorry, I badly explayned myself: i need to import the rotation axis (i don't know the exact name, but is the one in the attached image)
Attachments
axis.png
axis.png (3.39 KiB) Viewed 512 times
edwilliams16
Veteran
Posts: 3179
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: How can i take the x, y, and z of the axis by a part object in python?

Post by edwilliams16 »

Code: Select all

myCylinder.Placement.Rotation.Axis.y
though it isn't clear what purpose you might have for a single component of the Axis vector. Most applications would require the entire vector.
frmgr
Posts: 3
Joined: Fri Sep 23, 2022 8:35 am

Re: How can i take the x, y, and z of the axis by a part object in python?

Post by frmgr »

thank you, that was what i needed
wmayer
Founder
Posts: 20301
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How can i take the x, y, and z of the axis by a part object in python?

Post by wmayer »

Code: Select all

myCylinder.Placement.Rotation.RawAxis.y
There is a slight difference between Axis and RawAxis. The former always is a normalized vector so that you usually get a different value than shown in the property editor.

If you change x and y of the axis to -1 in the property editor then

Code: Select all

myCylinder.Placement.Rotation.Axis.y
returns -0.7071067811865475 (i.e. -sqrt(0.5)) while

Code: Select all

myCylinder.Placement.Rotation.RawAxis.y
still returns -1.
Post Reply