[SOLVED] Length of a ShapeString
Forum rules
and Helpful information
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!
Also, be nice to others! Read the FreeCAD code of conduct!
[SOLVED] Length of a ShapeString
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.
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.
Re: Length of a ShapeString
I think you need a better answer but in the bounding box you can see the length
Re: Length of a ShapeString
You can center a ShapeString with expressions:
For Placement Position x use:
For Placement Position x use:
Code: Select all
-.Shape.BoundBox.XLength / 2
Re: Length of a ShapeString
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
What's the significance of the -. prefix (or is that just a reference to "Self"), please?
Many thanks.
Re: [SOLVED] Length of a ShapeString
Just pasting the code should work.
But if you want to enter the label:
Which will automatically be changed to:
But if you want to enter the label:
Code: Select all
-<<ShapeString>>.Shape.BoundBox.XLength / 2
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:
Re: [SOLVED] Length of a ShapeString
So. ."Shape is a whole new set of properties I haven't yet discovered!
And the "-" is simply shorthand for maths invert.
Thanks.
And the "-" is simply shorthand for maths invert.
Thanks.
Re: [SOLVED] Length of a ShapeString
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?
I guess mm isn't the units, but some font-specific thing?
-
- Posts: 591
- Joined: Wed Sep 29, 2021 8:35 am
Re: [SOLVED] Length of a ShapeString
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.
Re: [SOLVED] Length of a ShapeString
Yes. Understood. I've a software background, so I also grasp point sizes.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"
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 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').
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.Workshop_Notes wrote: ↑Mon May 29, 2023 5:18 pm This makes it challenging to do any vertical alignment.
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.