Draft ShapeString: Difference between revisions

From FreeCAD Documentation
No edit summary
No edit summary
(58 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<languages/>

<translate>
<translate>
<!--T:24-->
{{Docnav
|[[Draft_Point|Point]]
|[[Draft_Facebinder|Facebinder]]
|[[Draft_Module|Draft]]
|IconL=Draft_Point.svg
|IconC=Workbench_Draft.svg
|IconR=Draft_Facebinder.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=Draft → Shape from text ...
|Workbenches=[[Draft Module|Draft]], [[Arch Module|Arch]]
|Shortcut={{KEY|S}} {{KEY|S}}
|SeeAlso=[[Draft Text|Draft Text]], [[Part Extrude|Part Extrude]],<br /> [[Macro_Fonts_Win10_PYMP|Macro Fonts Win10 PYMP]] [[Image:Macro_Fonts_Win10_PYMP.png|24px]]
|Version=0.14
}}


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


<!--T:2-->
<!--T:2-->
The ShapeString tool inserts a compound shape representing a text string at a given point in the current document. Text height, tracking and font can be specified.
The {{Button|[[Image:Draft_ShapeString.svg|16px]] [[Draft_ShapeString|Draft ShapeString]]}} tool inserts a compound shape that represents a text string. Text height, tracking and font can be specified.
The resulting shape can be used with the [[Image:Part_Extrude.svg|24px]] [[Part Extrude|Part Extrude]] tool to create 3D letters.


<!--T:14-->
<!--T:19-->
'''Alternatively''': To insert a simpler text element without a closed shape use [[Image:Draft_Text.svg|24px]] [[Draft Text|Draft Text]]. To create a text label with a lead and an arrow use [[Image:Draft_Label.svg|24px]] [[Draft Label|Draft Label]].

</translate>
[[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:4-->
If your Draft interface mode is set to ToolBar:
# Press the {{KEY|[[Image:Draft_ShapeString16.png]] [[Draft_ShapeString|Draft Shape from text ...]]}} button, or press {{KEY|S}} then {{KEY|S}} keys
# Press the {{Button|[[Image:Draft_ShapeString.svg|16px]] [[Draft_ShapeString|Draft ShapeString]]}} button, or press {{KEY|S}} then {{KEY|S}} keys.
# Click a point on the 3D view, or type a [[Draft_Coordinates|coordinate]]
# Click a point on the 3D view, or type a [[Draft_Coordinates|coordinate]] and press the {{Button|[[Image:Draft_AddPoint.svg|16px]] [[Draft_AddPoint|add point]]}} button.
# Enter the desired text, press {{KEY|ENTER}}
# Enter the desired size, press {{KEY|ENTER}}
# Enter the desired text, and press {{KEY|Enter}}.
# Enter the desired tracking, press {{KEY|ENTER}}
# Enter the desired size, and press {{KEY|Enter}}.
# Enter the desired tracking, and press {{KEY|Enter}}.
# Press {{KEY|ENTER}} to accept the displayed font file, or,
# Press {{KEY|...}} to select a font file.
# Press {{KEY|Enter}} to accept the displayed font file, or press {{Button|...}} to select a font file.
</translate>
[[Image:SSFontSelect.png]]
<translate>

<!--T:27-->
If your Draft interface mode is set to TaskView:
# Press the {{Button|[[Image:Draft_ShapeString.svg|16px]] [[Draft_ShapeString|Draft ShapeString]]}} button, or press {{KEY|S}} then {{KEY|S}} keys.
# A dialog will appear where you can specify your parameters.
# Press {{KEY|OK}} to create the ShapeString.


<!--T:20-->
*The text, size, tracking, and font can be changed after creation, by modifying the values in the Property Editor.
*You will want to set the default font file in [[Draft Preferences|Draft Preferences]], in the {{Button|Texts and dimensions}} tab. This will prefill the font file box in the dialog.
*Supported fonts include TrueType (.ttf), OpenType (.otf), and Type 1 (.pfb).

===Limitations=== <!--T:12-->
* Very small text heights may result in deformed character shapes due to loss of detail in scaling.
* The current version is limited to left-to-right writing.
* To create text arranged in a circular fashion use the {{Button|[[File:FCCircularTextButtom.png|24px]] [[Macro_FCCircularText|Circular Text]]}} macro.


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


<!--T:6-->
<!--T:6-->
* To enter coordinates manually, simply enter the numbers, then press {{KEY|ENTER}} between each X, Y and Z component.
* To enter coordinates manually, simply enter the numbers, then press {{KEY|Enter}} between each X, Y and Z component. You can press the {{Button|[[Image:Draft_AddPoint.svg|16px]] [[Draft_AddPoint|add point]]}} button when you have the desired values to insert the point.
* Pressing {{KEY|ESC}} will cancel the operation.
* Press {{KEY|Esc}} or the {{Button|Close}} button to abort the current command.
* You can set a default font file in Draft/Prefences.


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


<!--T:8-->
<!--T:8-->
* {{PropertyData|Position}}: The base point of the compound shape
* {{PropertyData|Position}}: specifies the position of the base point of the compound shape.
* {{PropertyData|String}}: The contents of the text string
* {{PropertyData|Angle}}: specifies the rotation of the baseline of the shape.
* {{PropertyData|Size}}: The height of the letters in FC units
* {{PropertyData|Axis}}: specifies the axis to use for the rotation.
* {{PropertyData|String}}: specifies the text string to display; unlike the [[Draft Text|Draft Text]] tool, the [[Draft ShapeString|Draft ShapeString]] can only display a single line.
* {{PropertyData|Tracking}}: The inter-character spacing in FC units
* {{PropertyData|Font File}}: The font definition file used to draw the string
* {{PropertyData|Size}}: specifies the general height of the letters.
* {{PropertyData|Tracking}}: specifies the additional inter-character spacing in the string.
* {{PropertyData|Font File}}: specifies the full path of the font file used to draw the string.


==Scripting== <!--T:9-->
==Scripting== <!--T:9-->
{{Emphasis|See also:}} [[Draft API|Draft API]] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]].


<!--T:10-->
<!--T:10-->
The ShapeString tool can by used in [[macros]] and from the python console by using the following function:
The ShapeString tool can be used in [[macros|macros]] and from the [[Python|Python]] console by using the following function:
</translate>
</translate>

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

<!--T:15-->
<!--T:15-->
* Creates a {{incode|ShapeString}} compound shape using the specified {{incode|String}} and the full path of a supported {{incode|FontFile}}.
* Turns a text string into a Compound Shape using a specified font.</translate>
* {{incode|Size}} is the height of the resulting text in millimeters.
* {{incode|Tracking}} is the additional inter-character spacing in millimeters.


<translate><!--T:11-->
<!--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.
Example: </translate>

<!--T:11-->
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>
==Selecting A Font== <!--T:16-->
[[Image:SSFontSelect.png]]


doc = App.newDocument()
<!--T:17-->

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.
font1 = "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf"
</translate>
font2 = "/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf"
<translate>
font3 = "/usr/share/fonts/truetype/freefont/FreeSerifItalic.ttf"
==Limitations== <!--T:12-->

* This tool is not available in FreeCAD versions anterior to 0.14
S1 = Draft.makeShapeString("This is a sample text", font1, 200)
* 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.
S2 = Draft.makeShapeString("Inclined text", font2, 200, 10)
* The current version is limited to left-to-right layouts on a horizontal baseline.

* For creating curved text you can use the macro [[Macro_Circular Text|Circular Text]]
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.makeShapeString("Upside-down text", font3, 200, 10)
S3.Placement.Base = App.Vector(0, -1000, 0)
S3.Placement.Rotation = App.Rotation(ZAxis, 180)

doc.recompute()
}}
<translate>


==Tutorials== <!--T:18-->
==Tutorials== <!--T:18-->
* [[Draft_ShapeString_tutorial|Draft ShapeString tutorial]]


<!--T:28-->
</translate>
* [[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]


==Notes== <!--T:29-->
<languages/>

<!--T:30-->
* Many fonts will generate problematic geometric. This is because font contours are allowed to overlap, have small gaps and have varying directions within a glyph. These conditions are considered errors in the Wires used to define Faces. Options are to correct the font definition with a tool like FontForge or to use another font.

<!--T:23-->
{{Docnav
|[[Draft_Point|Point]]
|[[Draft_Facebinder|Facebinder]]
|[[Draft_Module|Draft]]
|IconL=Draft_Point.svg
|IconC=Workbench_Draft.svg
|IconR=Draft_Facebinder.svg
}}

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

Revision as of 20:10, 24 May 2020

Draft ShapeString

Menu location
Draft → Shape from text ...
Workbenches
Draft, Arch
Default shortcut
S S
Introduced in version
0.14
See also
Draft Text, Part Extrude,
Macro Fonts Win10 PYMP

Description

The Draft ShapeString tool inserts a compound shape that represents a text string. Text height, tracking and font can be specified. The resulting shape can be used with the Part Extrude tool to create 3D letters.

Alternatively: To insert a simpler text element without a closed shape use Draft Text. To create a text label with a lead and an arrow use Draft Label.

Single point required to position the Shapestring

Usage

If your Draft interface mode is set to ToolBar:

  1. Press the Draft ShapeString button, or press S then S keys.
  2. Click a point on the 3D view, or type a coordinate and press the add point button.
  3. Enter the desired text, and press Enter.
  4. Enter the desired size, and press Enter.
  5. Enter the desired tracking, and press Enter.
  6. Press Enter to accept the displayed font file, or press ... to select a font file.

If your Draft interface mode is set to TaskView:

  1. Press the Draft ShapeString button, or press S then S keys.
  2. A dialog will appear where you can specify your parameters.
  3. Press OK to create the ShapeString.


  • The text, size, tracking, and font can be changed after creation, by modifying the values in the Property Editor.
  • You will want to set the default font file in Draft Preferences, in the Texts and dimensions tab. This will prefill the font file box in the dialog.
  • Supported fonts include TrueType (.ttf), OpenType (.otf), and Type 1 (.pfb).

Limitations

  • Very small text heights may result in deformed character shapes due to loss of detail in scaling.
  • The current version is limited to left-to-right writing.
  • To create text arranged in a circular fashion use the Circular Text macro.

Options

  • To enter coordinates manually, simply enter the numbers, then press Enter between each X, Y and Z component. You can press the add point button when you have the desired values to insert the point.
  • Press Esc or the Close button to abort the current command.

Properties

  • DataPosition: specifies the position of the base point of the compound shape.
  • DataAngle: specifies the rotation of the baseline of the shape.
  • DataAxis: specifies the axis to use for the rotation.
  • DataString: specifies the text string to display; unlike the Draft Text tool, the Draft ShapeString can only display a single line.
  • DataSize: specifies the general height of the letters.
  • DataTracking: specifies the additional inter-character spacing in the string.
  • DataFont File: specifies the full path of the font file used to draw the string.

Scripting

See also: Draft API and FreeCAD Scripting Basics.

The ShapeString tool can be used in macros and from the Python console by using the following function:

ShapeString = makeShapeString(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 additional 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.makeShapeString("This is a sample text", font1, 200)

S2 = Draft.makeShapeString("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.makeShapeString("Upside-down text", font3, 200, 10)
S3.Placement.Base = App.Vector(0, -1000, 0)
S3.Placement.Rotation = App.Rotation(ZAxis, 180)

doc.recompute()

Tutorials

Notes

  • Many fonts will generate problematic geometric. This is because font contours are allowed to overlap, have small gaps and have varying directions within a glyph. These conditions are considered errors in the Wires used to define Faces. Options are to correct the font definition with a tool like FontForge or to use another font.