[SOLVED] Length of a ShapeString

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
KDM
Posts: 147
Joined: Sun Feb 20, 2022 9:30 am

[SOLVED] Length of a ShapeString

Post by KDM »

This can't not have been asked before, but I can't find a reference that I don't find convoluted.

I don't see a Length property for a ShapeString which is accessible in the Property Viewer. This is one means I might use to centre a string.

Is there an easy way to centre a ShapeString?

(Follow-up question: It has a "Size" which looks to be synonymous with Height. Why not a Width of Length?)

Even if someone points me to the "Duh, that's been asked and answered loads of times" post, that's fine.

Thanks.
Last edited by KDM on Mon May 29, 2023 3:03 pm, edited 1 time in total.
User avatar
Willem
Veteran
Posts: 1852
Joined: Fri Aug 12, 2016 3:27 pm
Location: Lisse, The Netherlands

Re: Length of a ShapeString

Post by Willem »

I think you need a better answer but in the bounding box you can see the length
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: Length of a ShapeString

Post by Roy_043 »

You can center a ShapeString with expressions:

For Placement Position x use:

Code: Select all

-.Shape.BoundBox.XLength / 2
User avatar
KDM
Posts: 147
Joined: Sun Feb 20, 2022 9:30 am

Re: Length of a ShapeString

Post by KDM »

Willem wrote: Mon May 29, 2023 12:30 pm I think you need a better answer but in the bounding box you can see the length
I can SEE, it but if it was a property I could automagically centre it and do other funky things. Thank you, though.
User avatar
KDM
Posts: 147
Joined: Sun Feb 20, 2022 9:30 am

Re: Length of a ShapeString

Post by KDM »

Roy_043 wrote: Mon May 29, 2023 2:27 pm

Code: Select all

-.Shape.BoundBox.XLength / 2
Boom! That's exactly what I'm looking for.

Since ShapeString is the label of my part, I had tried

Code: Select all

<<ShapeString>>.BoundBox.XLength / 2
...but ShapesTring has no BoundBox property. What is the "Shape" object we're referring to? Is that just a reference to "Self"?
What's the significance of the -. prefix (or is that just a reference to "Self"), please?

Many thanks.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: [SOLVED] Length of a ShapeString

Post by Roy_043 »

Just pasting the code should work.

But if you want to enter the label:

Code: Select all

-<<ShapeString>>.Shape.BoundBox.XLength / 2
Which will automatically be changed to:

Code: Select all

-.Shape.BoundBox.XLength / 2

Code: Select all

OS: Windows 8 build 9600
Word size of FreeCAD: 64-bit
Version: 0.21.0.33321 (Git)
Build type: Release
Branch: master
Hash: 1d61ed187c9633702818c6cc5d7a1f07dd052ca8
Python 3.10.11, Qt 5.15.8, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: C/Default (C) [ OS: Dutch/Netherlands (nl_NL) ]
Installed mods:
User avatar
KDM
Posts: 147
Joined: Sun Feb 20, 2022 9:30 am

Re: [SOLVED] Length of a ShapeString

Post by KDM »

So. ."Shape is a whole new set of properties I haven't yet discovered!
And the "-" is simply shorthand for maths invert.
Thanks.
User avatar
KDM
Posts: 147
Joined: Sun Feb 20, 2022 9:30 am

Re: [SOLVED] Length of a ShapeString

Post by KDM »

If I want to add extra width onto that amount, normally, I have to put the units ("mm"). This property actively rejects the units.
I guess mm isn't the units, but some font-specific thing?
Workshop_Notes
Posts: 590
Joined: Wed Sep 29, 2021 8:35 am

Re: [SOLVED] Length of a ShapeString

Post by Workshop_Notes »

KDM wrote: Mon May 29, 2023 12:15 pm It has a "Size" which looks to be synonymous with Height
Take note of the actual words here:

https://wiki.freecad.org/Draft_ShapeString#Data

"specifies the general height of the text"

The connection between 'Size' and bounding box height is not a simple one. It depends on the font you choose and the actual contents of the shapestring - a lowercase string will likely have a different height to the same uppercase string. If you have a lowercase string with no ascenders or decenders (e.g. 'case'), it will have a different height to one with only ascenders (e.g. 'fish') and different alignment to one with only decenders (e.g. 'quay') and different again to ascenders and decenders (e.g. 'fang').

This makes it challenging to do any vertical alignment.
User avatar
KDM
Posts: 147
Joined: Sun Feb 20, 2022 9:30 am

Re: [SOLVED] Length of a ShapeString

Post by KDM »

Workshop_Notes wrote: Mon May 29, 2023 5:18 pm Take note of the actual words here:
https://wiki.freecad.org/Draft_ShapeString#Data
"specifies the general height of the text"
Yes. Understood. I've a software background, so I also grasp point sizes.
Workshop_Notes wrote: Mon May 29, 2023 5:18 pm The connection between 'Size' and bounding box height is not a simple one. It depends on the font you choose and the actual contents of the shapestring - a lowercase string will likely have a different height to the same uppercase string. If you have a lowercase string with no ascenders or decenders (e.g. 'case'), it will have a different height to one with only ascenders (e.g. 'fish') and different alignment to one with only decenders (e.g. 'quay') and different again to ascenders and decenders (e.g. 'fang').
Yup, I'm still with you. I Do get that a lowercase "y" hangs below the line. Who invented this stupid "writing" thing, anyway? Had they no foresight?! :-)
Workshop_Notes wrote: Mon May 29, 2023 5:18 pm This makes it challenging to do any vertical alignment.
See, this is the odd part for me. I'm trying to do horizontal alignment! Fortunately, I've chosen an all-caps font, so horizontal alignment sort of works by default.

I'd have thought, though, that a "bounding" box, regardless of font, ascenders, descenders... would have simply been the maximum extents of whatever string one entered.

If I were designing an LED display (I'm not, but this is the best analogy I can thin of) I would want to now how many horizontal and vertical pixels I needed. Regardless of whether they were populated, or how likely they were to be populated.
Post Reply