App::PropertyDirection vs. App::PropertyVector?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Jolbas
Posts: 330
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: App::PropertyDirection vs. App::PropertyVector?

Post by Jolbas »

edwilliams16 wrote: Fri Jan 20, 2023 6:56 pm How do I drill down to Axis or RawAxis?
They are part of either a App::PropertyPlacement or App::PropertyRotation. They are vectors but aren't standalone properties and neither App::PropertyDirection nor App::PropertyVector

Axis is the RawAxis normalized upon call
RawAxis is the one you see and set in the property view after expanding the Placement property, but there it's called just Axis

In Python the obj.Placement.Rotation.RawAxis is readonly. but obj.Placement.Rotation.Axis = App.Vector(1,2,3) sets the RawAxis and then obj.Placement.Rotation.Axis will return it as normalized: Vector (0.2672612419124244, 0.5345224838248488, 0.8017837257372732)
edwilliams16
Veteran
Posts: 3180
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: App::PropertyDirection vs. App::PropertyVector?

Post by edwilliams16 »

OK. So neither are App::PropertyDirection Will have to look elsewhere for its use.
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: App::PropertyDirection vs. App::PropertyVector?

Post by onekk »

edwilliams16 wrote: Sat Jan 21, 2023 12:52 am OK. So neither are App::PropertyDirection Will have to look elsewhere for its use.
Where did you find it?

I was curious and I've tried to search sources using github search bar.

But I have not managed to find anything.

Regards

Carlo D.
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/
User avatar
Jolbas
Posts: 330
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: App::PropertyDirection vs. App::PropertyVector?

Post by Jolbas »

I would say, the App::PropertyDistance App::PropertyDirection, App::PropertyPosition and App::PropertyVectorDistance are all equal. They all have length units on their coordinates, for example meters. App::PropertyVector is the base for those and have no unit. That means that units are discarded for expressions on PropertyVector and a default unit is added on the other property types.

Edit: Corrected App::PropertyDistance to App::PropertyDirection
Last edited by Jolbas on Sun Jan 22, 2023 10:24 pm, edited 1 time in total.
edwilliams16
Veteran
Posts: 3180
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: App::PropertyDirection vs. App::PropertyVector?

Post by edwilliams16 »

Jolbas wrote: Sun Jan 22, 2023 5:53 pm That means that units are discarded for expressions on PropertyVector and a default unit is added on the other property types.
So a PropertyDirection has units? Seems counter-intuitive. If I decomposed a vector

Code: Select all

vector = direction_unit_vector * length
I would have expected length to carry the units.
User avatar
Jolbas
Posts: 330
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: App::PropertyDirection vs. App::PropertyVector?

Post by Jolbas »

edwilliams16 wrote: Sun Jan 22, 2023 7:15 pm So a PropertyDirection has units? Seems counter-intuitive.
I agree. It seems unnecessary to have a unit on the direction. I do not fully understand the handling of units here. The PropertyDirection is presented with units in property view.

This expression on a PropertyDirection works:

Code: Select all

anotherDirectionProperty * 5mm
But this expression on the x coordinate of a PropertyDirection does not work:

Code: Select all

anotherDirectionProperty.x * 5mm
The last expression works on a PropertyVector.x which just discards any unit.
User avatar
Roy_043
Veteran
Posts: 8551
Joined: Thu Dec 27, 2018 12:28 pm

Re: App::PropertyDirection vs. App::PropertyVector?

Post by Roy_043 »

User avatar
Roy_043
Veteran
Posts: 8551
Joined: Thu Dec 27, 2018 12:28 pm

Re: App::PropertyDirection vs. App::PropertyVector?

Post by Roy_043 »

Jolbas wrote: Sun Jan 22, 2023 10:19 pm The PropertyDirection is presented with units in property view.
Thanks, I missed that.

This works

Code: Select all

obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython", "InternalObjectName")
obj.Label = "User-friendly label"
obj.addProperty("App::PropertyDirection", "ThePropertyName", "Subsection", "Description for tooltip")
obj.ThePropertyName = (1.0, 2.0, 3.0)

len = FreeCAD.Units.Quantity(123, App.Units.Length)
print(obj.ThePropertyName * len)
print(obj.ThePropertyName.z * len)
Post Reply