Measure ShapeString Height/Width via python script

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
MamboDee
Posts: 1
Joined: Tue Jul 27, 2021 1:23 am

Measure ShapeString Height/Width via python script

Post by MamboDee »

After creating a ShapeString with the following code:

Code: Select all

ss=Draft.makeShapeString(String="Hello",FontFile="C:/Windows/Fonts/cour.ttf",Size=10.0,Tracking=0.0)
# Gui.Selection.addSelection('Unnamed','ShapeString')
plm=FreeCAD.Placement()
plm.Base=FreeCAD.Vector(0.13, 0.17, 0.0)
plm.Rotation.Q=(0.0, 0.0, 1.5308084989341915e-17, 1.0)
ss.Placement=plm
ss.Support=None
Draft.autogroup(ss)
Is there a way to get the the height and the width of the ss object? I would like create a macro that measures the selected ShapeString and either gives the measurements on the console or updates an aliased cell on a spreadsheet.

Most Youtube videos involve using the distance tools with is 1) cumbersome and 2) Time consuming when making multiple text size and text placement changes.
chrisb
Veteran
Posts: 54150
Joined: Tue Mar 17, 2015 9:14 am

Re: Measure ShapeString Height/Width via python script

Post by chrisb »

You can use the BoundingBox. To provide correct results the ShapeString must not be rotated then. If you want to rotate it anyway, place it in a compound and rotate that.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply