How can I get the axis(x,y,z) of a 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
oscarchan
Posts: 47
Joined: Mon Apr 11, 2022 2:04 am

How can I get the axis(x,y,z) of a object???

Post by oscarchan »

Hi guys!
I am using FC0.18.
I am trying to access the Axis data of a selected object. eg:I wanna get (-3.2,-0.22,4.4) in the case below.
But through the code

Code: Select all

Gui.Selection.getSelection()[0].Placement.Rotation.Axis
I can't make it.
How do you guys get that infomation??? Thanks in advance!
rotation_placement.png
rotation_placement.png (35.54 KiB) Viewed 847 times
Last edited by oscarchan on Thu Aug 18, 2022 1:06 am, edited 1 time in total.
Thank you!
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: How can I get the axis(x,y,z) of a object???

Post by Roy_043 »

The rotation axis is returned as a unit vector. If you save and reopen the file the axis values will have been recalculated accordingly.
demonlibra
Posts: 79
Joined: Tue Jan 21, 2020 1:11 pm

Re: How can I get the axis(x,y,z) of a object???

Post by demonlibra »

Code: Select all

element = Gui.Selection.getSelection()[0]

position_x = element.Placement.Base[0]
position_y = element.Placement.Base[1]
position_z = element.Placement.Base[2]

rotation_x = element.Placement.Rotation.Axis.x
rotation_y = element.Placement.Rotation.Axis.y
rotation_z = element.Placement.Rotation.Axis.z

from math import *
rotation_angle = degrees(element.Placement.Rotation.Angle)
wmayer
Founder
Posts: 20242
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How can I get the axis(x,y,z) of a object???

Post by wmayer »

Code: Select all

Gui.Selection.getSelection()[0].Placement.Rotation.RawAxis
gives you the information as shown in the property editor
oscarchan
Posts: 47
Joined: Mon Apr 11, 2022 2:04 am

Re: How can I get the axis(x,y,z) of a object???

Post by oscarchan »

wmayer wrote: Wed Aug 17, 2022 11:15 am

Code: Select all

Gui.Selection.getSelection()[0].Placement.Rotation.RawAxis
Thanks I tried in FC0.20 it works but in FC0.18, it says 【AttributeError: 'Base.Rotation' object has no attribute 'RawAxis'】
Thank you!
oscarchan
Posts: 47
Joined: Mon Apr 11, 2022 2:04 am

Re: How can I get the axis(x,y,z) of a object???

Post by oscarchan »

@Roy_043 Thank you. It works like you mentioned.
@demonlibra Thank you!
Thank you!
chrisb
Veteran
Posts: 53920
Joined: Tue Mar 17, 2015 9:14 am

Re: How can I get the axis(x,y,z) of a object???

Post by chrisb »

oscarchan wrote: Thu Aug 18, 2022 1:05 am Thanks I tried in FC0.20 it works but in FC0.18, it says 【AttributeError: 'Base.Rotation' object has no attribute 'RawAxis'】
Is there a good reason to use 0.18?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
wmayer
Founder
Posts: 20242
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How can I get the axis(x,y,z) of a object???

Post by wmayer »

Thanks I tried in FC0.20 it works but in FC0.18, it says
Oh, I missed that information. IIRC the attribute has been added with v0.19.
Post Reply