Draft ShapeString: Difference between revisions

From FreeCAD Documentation
(Typo, small edits)
(Button text.)
 
(157 intermediate revisions by 9 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>

<!--T:24-->
{{Docnav
|[[Draft_Facebinder|Facebinder]]
|[[Draft_Hatch|Hatch]]
|[[Draft_Workbench|Draft]]
|IconL=Draft_Facebinder.svg
|IconR=Draft_Hatch.svg
|IconC=Workbench_Draft.svg
}}

<!--T:13-->
<!--T:13-->
{{GuiCommand
{{GuiCommand|Name=Draft ShapeString|Workbenches=[[Draft Module|Draft]], [[Arch Module|Arch]]|MenuLocation=Draft → Shape from text ...|Shortcut=S S}}
|Name=Draft ShapeString
|MenuLocation=Drafting → Shape from text
|Workbenches=[[Draft_Workbench|Draft]], [[Arch_Workbench|Arch]]
|Shortcut=
|Version=0.14
|SeeAlso=[[Draft_Text|Draft Text]], [[Draft_Label|Draft Label]], [[Part_Extrude|Part Extrude]]
}}


==Description== <!--T:1-->
==Description== <!--T:1-->


<!--T:2-->
<!--T:2-->
The ShapeString tool inserts a compound shape that represents a text string. Text height, tracking and font can be specified.
The [[Image:Draft_ShapeString.svg|24px]] '''Draft ShapeString''' command creates a compound shape that represents a text string. This shape can be used to create 3D letters with the [[Part_Extrude|Part Extrude]] command.
The resulting shape can be used with the [[Part Extrude]] tool to create 3D letters.


<!--T:19-->
The [[Draft Text]] tool is a simpler alternative that does not produce a closed shape.
The Draft ShapeString command is not intended for standard text annotations. The [[Draft_Text|Draft Text]] command or the [[Draft_Label|Draft Label]] command should be used for that purpose.


</translate>
<!--T:14-->
[[Image:Draft_ShapeString_Example400.png]]
[[Image:Draft_ShapeString_Example400.png]]
<translate>
<!--T:14-->
{{Caption|Single point required to position the ShapeString}}


==How to use== <!--T:3-->
==Usage== <!--T:3-->


<!--T:4-->
<!--T:47-->
For Windows users: please read the [[#Font_file_selection_on_Windows|Font file selection on Windows]] paragraph first.
# Press the {{KEY|[[Image:Draft_ShapeString16.png]] [[Draft_ShapeString|Draft Shape from text ...]]}} button, or press {{KEY|S}} then {{KEY|S}} keys

# Click a point on the 3D view, or type a [[Draft_Coordinates|coordinate]]
<!--T:27-->
# Enter the desired text, press {{KEY|ENTER}}
# There are several ways to invoke the command:
# Enter the desired size, press {{KEY|ENTER}}
#* Press the {{Button|[[Image:Draft_ShapeString.svg|16px]] [[Draft_ShapeString|Shape from text]]}} button.
# Enter the desired tracking, press {{KEY|ENTER}}
#* Select the {{MenuCommand|Drafting → [[Image:Draft_ShapeString.svg|16px]] Shape from text}} option from the menu.
# Press {{KEY|ENTER}} to accept the displayed font file, or,
# The {{MenuCommand|ShapeString}} task panel opens.
# Press {{KEY|...}} to select a font file.
# Click a point in the [[3D_view|3D view]], or type coordinates.
# Optionally press the {{Button|Reset Point}} button to reset the point to the origin.
# Enter a {{MenuCommand|String}}.
# Specify the {{MenuCommand|Height}}.
# To select a font do one of the following:
#* Enter a file path in the {{MenuCommand|Font file}} input box.
#* Press the {{Button|...}} button and select a file.
# Press the {{Button|OK}} button to finish the command.
# Optionally change the {{PropertyData|Justification}} of the ShapeString. See [[#Properties|Properties]].


==Options== <!--T:5-->
==Options== <!--T:5-->


<!--T:6-->
<!--T:6-->
* Press {{KEY|Esc}} or the {{Button|Cancel}} button to abort the command.
* To enter coordinates manually, simply enter the numbers, then press {{KEY|ENTER}} between each X, Y and Z component.

* Pressing {{KEY|ESC}} will cancel the operation.
==Notes== <!--T:33-->
* You can set a default font file in Draft/Prefences.

<!--T:12-->
* A Draft ShapeString can be edited by double-clicking it in the [[Tree_view|Tree view]]. {{Version|0.20}}
* Supported fonts include TrueType ({{FileName|.ttf}}), OpenType ({{FileName|.otf}}) and Type 1 ({{FileName|.pfb}}).
* The command is restricted to left-to-right text. Right-to-left and top-to-bottom text are not supported.
* Very small text heights may result in deformed character shapes due to loss of detail in scaling.
* Fonts can generate problematic geometry. This is because font contours are allowed to overlap and have small gaps. These conditions are considered errors in wires used to define faces.
* Draft ShapeStrings can also be created with the [[Macro_Fonts_Win10_PYMP|Macro Fonts Win10 PYMP]].
* To create Draft ShapeStrings arranged in a circular fashion use the [[Macro_FCCircularText|Macro FCCircularText]].

==Font file selection on Windows== <!--T:43-->

<!--T:44-->
On Windows access to the default font folder is restricted. This affects the font file selection for ShapeStrings. There are three cases in FreeCAD where a font file for ShapeStrings can be specified: in the ShapeString task panel, when changing the {{PropertyData|Font File}} property of a ShapeString, and when specifying the default font file in the [[Draft_Preferences#Texts_and_dimensions|Draft Preferences]].

<!--T:45-->
Pressing the {{Button|...}} button and then selecting a file from the default Windows font folder is not possible when using the native file dialog. There are a number of workarounds:
* Make sure {{MenuCommand|DontUseNativeFontDialog}} is set to {{True}}, which is the default value for this preference. This will only call a different, non-native, file dialog when pressing the {{Button|...}} button in the ShapeString task panel. With this file dialog the default Windows font folder can be accessed.
* Change {{MenuCommand|DontUseNativeDialog}} to {{True}}. This instructs FreeCAD to always use the non-native file dialog.
* Specify the font file in the input box. You can of course type the full path or copy-paste the path from the Windows File Explorer. But there is also another way to enter the path. If you enter {{Value|C:\}} a dropdown list will appear. Select {{Value|Windows}} from that list and add {{Value|\F}}. Select {{Value|Fonts}} from the new dropdown list. Finally add {{Value|\}} and the first letter(s) of the font file, and then select it from the dropdown list.
* Create a custom folder for your font files.

<!--T:46-->
See the [[#Preferences|Preferences]] paragraph below for the location of the mentioned preferences.

==Tutorials== <!--T:18-->

<!--T:28-->
* [[Draft_ShapeString_tutorial|Draft ShapeString tutorial]]: extrude a ShapeString, position it in 3D space, and create an engraving in another body.
* [https://forum.freecadweb.org/viewtopic.php?f=3&t=36623 How to use ShapeStrings in PartDesign]

==Preferences== <!--T:31-->

<!--T:42-->
See also: [[Preferences_Editor|Preferences Editor]], [[Draft_Preferences|Draft Preferences]] and [[Std_DlgParameter|Std DlgParameter]].

<!--T:32-->
* The default font file can be changed in the preferences: {{MenuCommand|Edit → Preferences... → Draft → Texts and dimensions → Default ShapeString font file}}.
* For Windows users:
** Set {{MenuCommand|Tools → Edit parameters... → BaseApp → Preferences → Dialog → DontUseNativeFontDialog}} to {{True}} to use the non-native file dialog when selecting a font file from the ShapeString task panel.
** Alternatively, set {{MenuCommand|Tools → Edit parameters... → BaseApp → Preferences → Dialog → DontUseNativeDialog}} to {{True}} to always use the non-native file dialog.


==Properties== <!--T:7-->
==Properties== <!--T:7-->

<!--T:34-->
See also: [[Property_editor|Property editor]].

<!--T:35-->
A Draft ShapeString object is derived from a [[Part_Part2DObject|Part Part2DObject]] and inherits all its properties. It also has the following additional properties:

===Data=== <!--T:36-->

<!--T:37-->
{{TitleProperty|Draft}}


<!--T:8-->
<!--T:8-->
* {{PropertyData|Position}}: The base point of the compound shape
* {{PropertyData|Font File|File}}: Font file name.
* {{PropertyData|Fuse|Bool}}: Fuse faces if faces overlap, usually not required (can be very slow). Ignored if {{PropertyData|Make Face}} is {{FALSE}}. {{Version|0.22}}
* {{PropertyData|String}}: The contents of the text string
* {{PropertyData|Justification|Enumeration}}: Horizontal and vertical alignment. Options: {{value|Top-Left}}, {{value|Top-Center}}, {{value|Top-Right}}, {{value|Middle-Left}}, {{value|Middle-Center}}, {{value|Middle-Right}}, {{value|Bottom-Left}}, {{value|Bottom-Center}}, {{value|Bottom-Right}}. {{Version|0.22}}
* {{PropertyData|Size}}: The height of the letters in FC units
* {{PropertyData|Justification Reference|Enumeration}}: Height reference used for justification. Options: {{value|Cap Height}}, {{value|Shape Height}}. The shape height depends on the characters in {{PropertyData|String}}. {{Version|0.22}}
* {{PropertyData|Tracking}}: The inter-character spacing in FC units
* {{PropertyData|Font File}}: The font definition file used to draw the string
* {{PropertyData|Keep Left Margin|Bool}}: Keep left margin and leading white space when justification is left. {{Version|0.22}}
* {{PropertyData|Make Face|Bool}}: Fill letters with faces.
* {{PropertyData|Oblique Angle|Angle}}: Oblique (slant) angle. Must be in the -80° to +80° range. {{Version|0.22}}
* {{PropertyData|Scale To Size|Bool}}: Scale to ensure cap height is equal to size. If set to {{FALSE}}, depending on the font, cap height will not match {{PropertyData|Size}} exactly. {{Version|0.22}}
* {{PropertyData|Size|Length}}: Height of text.
* {{PropertyData|String|String}}: Text string. A ShapeString can only display a single text line.
* {{PropertyData|Tracking|Distance}}: Inter-character spacing. The property type has been updated ({{Version|0.22}}).


</translate>
==Scripting== <!--T:9-->
[[Image:Draft_ShapeString_Justification.png|200px]]
<translate>
<!--T:48-->
{{Caption|The height of the red rectangle (solid line) is equal to the cap height.<br>
The height of the green rectangle (dashed line) is equal to the shape height.<br>
The corners, the midpoints of the edges, and the center of the rectangles<br>
match the 9 justification options: Top-Left to Bottom-Right.}}

==Scripting== <!--T:41-->

<!--T:9-->
See also: [https://freecad.github.io/SourceDoc/ Autogenerated API documentation] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]].


<!--T:10-->
<!--T:10-->
To create a Draft ShapeString use the {{incode|make_shapestring}} method ({{Version|0.19}}) of the Draft module. This method replaces the deprecated {{incode|makeShapeString}} method.
The ShapeString tool can be used in [[macros]] and from the Python console by using the following function:
</translate>


</translate>
{{Code|code=
{{Code|code=
ShapeString = makeShapeString(String, FontFile, Size=100, Tracking=0)
shapestring = make_shapestring(String, FontFile, Size=100, Tracking=0)
}}
}}
<translate>
<translate>

<!--T:15-->
<!--T:15-->
* Creates a <code>ShapeString</code> compound shape using the specified <code>String</code>
* Creates a {{incode|shapestring}} compound shape using the specified {{incode|String}} and the full path of a supported {{incode|FontFile}}.
* {{incode|Size}} is the height of the resulting text in millimeters.
* <code>FontFile</code> is mandatory and must be the full path of a supported font file
* <code>Size</code> is the height of the resulting text in millimeters
* {{incode|Tracking}} is the inter-character spacing in millimeters.

* <code>Tracking</code> is the additional inter-character spacing in millimeters
<!--T:22-->
The placement of the ShapeString can be changed by overwriting its {{incode|Placement}} attribute, or by individually overwriting its {{incode|Placement.Base}} and {{incode|Placement.Rotation}} attributes.


<!--T:11-->
<!--T:11-->
Example: </translate>
Example:

</translate>
{{Code|code=
{{Code|code=
import FreeCAD, Draft
import FreeCAD as App
import Draft
Draft.makeShapeString("This is a sample text",
"/usr/share/fonts/truetype/msttcorefonts/Arial.ttf",
200.0, 10)
}}
<translate>


doc = App.newDocument()
==Selecting A Font== <!--T:16-->
[[Image:SSFontSelect.png]]


font1 = "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf"
<!--T:17-->
font2 = "/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf"
ShapeString uses the internal geometry of a font to make FreeCAD shapes. To do this it must read the actual font file (*.tff, etc). If the Font Selection box is empty, you must type the full path to the font file or use {{KEY|...}} to select a font file.
font3 = "/usr/share/fonts/truetype/freefont/FreeSerifItalic.ttf"


S1 = Draft.make_shapestring("This is a sample text", font1, 200)
==Limitations== <!--T:12-->
* This tool is not available in FreeCAD versions anterior to 0.14
* TrueType(*.ttf), OpenType(*.otf) and Type1(*.pfb) font files are supported.
* Very small text heights may result in deformed character glyphs due to loss of detail in scaling.
* The current version is limited to left-to-right layouts on a horizontal baseline.
* For creating curved text you can use the macro [[File:FCCircularTextButtom.png|24px]][[Macro_Circular Text|Circular Text]]


S2 = Draft.make_shapestring("Inclined text", font2, 200, 10)
==Tutorials== <!--T:18-->

* [[Draft_ShapeString_tutorial|Draft ShapeString tutorial]]
zaxis = App.Vector(0, 0, 1)
p2 = App.Vector(-1000, 500, 0)
place2 = App.Placement(p2, App.Rotation(zaxis, 45))
S2.Placement = place2

S3 = Draft.make_shapestring("Upside-down text", font3, 200, 10)
S3.Placement.Base = App.Vector(0, -1000, 0)
S3.Placement.Rotation = App.Rotation(zaxis, 180)

doc.recompute()
}}
<translate>


<!--T:23-->
{{Docnav
|[[Draft_Facebinder|Facebinder]]
|[[Draft_Hatch|Hatch]]
|[[Draft_Workbench|Draft]]
|IconL=Draft_Facebinder.svg
|IconR=Draft_Hatch.svg
|IconC=Workbench_Draft.svg
}}


</translate>
</translate>
{{Draft Tools navi{{#translation:}}}}
{{Userdocnavi{{#translation:}}}}

Latest revision as of 17:04, 3 December 2023

Draft ShapeString

Menu location
Drafting → Shape from text
Workbenches
Draft, Arch
Default shortcut
None
Introduced in version
0.14
See also
Draft Text, Draft Label, Part Extrude

Description

The Draft ShapeString command creates a compound shape that represents a text string. This shape can be used to create 3D letters with the Part Extrude command.

The Draft ShapeString command is not intended for standard text annotations. The Draft Text command or the Draft Label command should be used for that purpose.

Single point required to position the ShapeString

Usage

For Windows users: please read the Font file selection on Windows paragraph first.

  1. There are several ways to invoke the command:
    • Press the Shape from text button.
    • Select the Drafting → Shape from text option from the menu.
  2. The ShapeString task panel opens.
  3. Click a point in the 3D view, or type coordinates.
  4. Optionally press the Reset Point button to reset the point to the origin.
  5. Enter a String.
  6. Specify the Height.
  7. To select a font do one of the following:
    • Enter a file path in the Font file input box.
    • Press the ... button and select a file.
  8. Press the OK button to finish the command.
  9. Optionally change the DataJustification of the ShapeString. See Properties.

Options

  • Press Esc or the Cancel button to abort the command.

Notes

  • A Draft ShapeString can be edited by double-clicking it in the Tree view. introduced in version 0.20
  • Supported fonts include TrueType (.ttf), OpenType (.otf) and Type 1 (.pfb).
  • The command is restricted to left-to-right text. Right-to-left and top-to-bottom text are not supported.
  • Very small text heights may result in deformed character shapes due to loss of detail in scaling.
  • Fonts can generate problematic geometry. This is because font contours are allowed to overlap and have small gaps. These conditions are considered errors in wires used to define faces.
  • Draft ShapeStrings can also be created with the Macro Fonts Win10 PYMP.
  • To create Draft ShapeStrings arranged in a circular fashion use the Macro FCCircularText.

Font file selection on Windows

On Windows access to the default font folder is restricted. This affects the font file selection for ShapeStrings. There are three cases in FreeCAD where a font file for ShapeStrings can be specified: in the ShapeString task panel, when changing the DataFont File property of a ShapeString, and when specifying the default font file in the Draft Preferences.

Pressing the ... button and then selecting a file from the default Windows font folder is not possible when using the native file dialog. There are a number of workarounds:

  • Make sure DontUseNativeFontDialog is set to true, which is the default value for this preference. This will only call a different, non-native, file dialog when pressing the ... button in the ShapeString task panel. With this file dialog the default Windows font folder can be accessed.
  • Change DontUseNativeDialog to true. This instructs FreeCAD to always use the non-native file dialog.
  • Specify the font file in the input box. You can of course type the full path or copy-paste the path from the Windows File Explorer. But there is also another way to enter the path. If you enter C:\ a dropdown list will appear. Select Windows from that list and add \F. Select Fonts from the new dropdown list. Finally add \ and the first letter(s) of the font file, and then select it from the dropdown list.
  • Create a custom folder for your font files.

See the Preferences paragraph below for the location of the mentioned preferences.

Tutorials

Preferences

See also: Preferences Editor, Draft Preferences and Std DlgParameter.

  • The default font file can be changed in the preferences: Edit → Preferences... → Draft → Texts and dimensions → Default ShapeString font file.
  • For Windows users:
    • Set Tools → Edit parameters... → BaseApp → Preferences → Dialog → DontUseNativeFontDialog to true to use the non-native file dialog when selecting a font file from the ShapeString task panel.
    • Alternatively, set Tools → Edit parameters... → BaseApp → Preferences → Dialog → DontUseNativeDialog to true to always use the non-native file dialog.

Properties

See also: Property editor.

A Draft ShapeString object is derived from a Part Part2DObject and inherits all its properties. It also has the following additional properties:

Data

Draft

  • DataFont File (File): Font file name.
  • DataFuse (Bool): Fuse faces if faces overlap, usually not required (can be very slow). Ignored if DataMake Face is false. introduced in version 0.22
  • DataJustification (Enumeration): Horizontal and vertical alignment. Options: Top-Left, Top-Center, Top-Right, Middle-Left, Middle-Center, Middle-Right, Bottom-Left, Bottom-Center, Bottom-Right. introduced in version 0.22
  • DataJustification Reference (Enumeration): Height reference used for justification. Options: Cap Height, Shape Height. The shape height depends on the characters in DataString. introduced in version 0.22
  • DataKeep Left Margin (Bool): Keep left margin and leading white space when justification is left. introduced in version 0.22
  • DataMake Face (Bool): Fill letters with faces.
  • DataOblique Angle (Angle): Oblique (slant) angle. Must be in the -80° to +80° range. introduced in version 0.22
  • DataScale To Size (Bool): Scale to ensure cap height is equal to size. If set to false, depending on the font, cap height will not match DataSize exactly. introduced in version 0.22
  • DataSize (Length): Height of text.
  • DataString (String): Text string. A ShapeString can only display a single text line.
  • DataTracking (Distance): Inter-character spacing. The property type has been updated (introduced in version 0.22).

The height of the red rectangle (solid line) is equal to the cap height.
The height of the green rectangle (dashed line) is equal to the shape height.
The corners, the midpoints of the edges, and the center of the rectangles
match the 9 justification options: Top-Left to Bottom-Right.

Scripting

See also: Autogenerated API documentation and FreeCAD Scripting Basics.

To create a Draft ShapeString use the make_shapestring method (introduced in version 0.19) of the Draft module. This method replaces the deprecated makeShapeString method.

shapestring = make_shapestring(String, FontFile, Size=100, Tracking=0)
  • Creates a shapestring compound shape using the specified String and the full path of a supported FontFile.
  • Size is the height of the resulting text in millimeters.
  • Tracking is the inter-character spacing in millimeters.

The placement of the ShapeString can be changed by overwriting its Placement attribute, or by individually overwriting its Placement.Base and Placement.Rotation attributes.

Example:

import FreeCAD as App
import Draft

doc = App.newDocument()

font1 = "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf"
font2 = "/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf"
font3 = "/usr/share/fonts/truetype/freefont/FreeSerifItalic.ttf"

S1 = Draft.make_shapestring("This is a sample text", font1, 200)

S2 = Draft.make_shapestring("Inclined text", font2, 200, 10)

zaxis = App.Vector(0, 0, 1)
p2 = App.Vector(-1000, 500, 0)
place2 = App.Placement(p2, App.Rotation(zaxis, 45))
S2.Placement = place2

S3 = Draft.make_shapestring("Upside-down text", font3, 200, 10)
S3.Placement.Base = App.Vector(0, -1000, 0)
S3.Placement.Rotation = App.Rotation(zaxis, 180)

doc.recompute()