Draft Text: Difference between revisions

From FreeCAD Documentation
(Fixed description of the screen argument in the Scripting paragraph.)
(39 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Page_in_progress}}
<languages/>
<languages/>
<translate>
<translate>
Line 5: Line 4:
<!--T:18-->
<!--T:18-->
{{Docnav
{{Docnav
|[[Draft_Hatch|Hatch]]
|[[Draft_ShapeString|ShapeString]]
|[[Draft_Dimension|Dimension]]
|[[Draft_Dimension|Dimension]]
|[[Draft_Module|Draft]]
|[[Draft_Workbench|Draft]]
|IconL=Draft_ShapeString.svg
|IconL=Draft_Hatch.svg
|IconR=Draft_Dimension.svg
|IconR=Draft_Dimension.svg
|IconC=Workbench_Draft.svg
|IconC=Workbench_Draft.svg
Line 17: Line 16:
|Name=Draft Text
|Name=Draft Text
|MenuLocation=Annotation → Text
|MenuLocation=Annotation → Text
|Workbenches=[[Draft_Module|Draft]], [[Arch_Module|Arch]]
|Workbenches=[[Draft_Workbench|Draft]], [[Arch_Workbench|Arch]]
|Shortcut={{KEY|T}} {{KEY|E}}
|Shortcut={{KEY|T}} {{KEY|E}}
|Version=0.7
|Version=0.7
Line 26: Line 25:


<!--T:2-->
<!--T:2-->
The [[Image:Draft_Text.svg|24px]] [[Draft_Text|Draft Text]] command inserts a multi-line textbox at a given point. It uses the [[Draft_Linestyle|Draft Linestyle]] set on the [[Draft_Tray|Draft Tray]].
The [[Image:Draft_Text.svg|24px]] '''Draft Text''' command creates a multi-line text at a given point.

<!--T:11-->
To create a text element with an arrow use the [[Draft_Label|Draft Label]] command instead.


<!--T:3-->
<!--T:3-->
[[Image:Draft_Text_example.png|400px]]
[[Image:Draft_Text_example.png|400px]]
{{Caption|Single point required to position the textbox}}
{{Caption|Single point required to position the text}}


==Usage== <!--T:23-->
==Usage== <!--T:23-->

<!--T:24-->
See also: [[Draft_Tray|Draft Tray]] and [[Draft_Snap|Draft Snap]].


<!--T:4-->
<!--T:4-->
Line 39: Line 44:
#* Select the {{MenuCommand|Annotation → [[Image:Draft_Text.svg|16px]] Text}} option from the menu.
#* Select the {{MenuCommand|Annotation → [[Image:Draft_Text.svg|16px]] Text}} option from the menu.
#* Use the keyboard shortcut: {{KEY|T}} then {{KEY|E}}.
#* Use the keyboard shortcut: {{KEY|T}} then {{KEY|E}}.
# The {{MenuCommand|Text}} task panel opens. See [[#Options|Options]] for more information.
# Click a point on the [[3D_view|3D view]], or type [[Draft_Coordinates|coordinates]] and press the {{Button|[[Image:Draft_AddPoint.svg|16px]] Enter point}} button.
# Pick a point in the [[3D_view|3D view]], or type coordinates and press the {{Button|[[Image:Draft_AddPoint.svg|16px]] Enter point}} button.
# Enter the desired text, pressing {{KEY|Enter}} between each line.
# Press {{KEY|Enter}} twice to finish the command.
# Enter the desired text, press {{KEY|Enter}} to start a new line.
# Press {{KEY|Enter}} twice or press the {{Button|[[Image:Button_valid.svg|16px]] Create text}} button to finish the command.


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

<!--T:25-->
The single character keyboard shortcuts available in the task panel can be changed. See [[Draft_Preferences|Draft Preferences]]. The shortcuts mentioned here are the default shortcuts.


<!--T:6-->
<!--T:6-->
* 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]] Enter point}} button when you have the desired values to insert the point.
* To manually enter coordinates enter the X, Y and Z component, and press {{KEY|Enter}} after each. Or you can press the {{Button|[[Image:Draft_AddPoint.svg|16px]] Enter point}} button when you have the desired values. It is advisable to move the pointer out of the [[3D_view|3D view]] before entering coordinates.
* The {{MenuCommand|Relative}} checkbox has no purpose for this command.
* Hold {{KEY|Ctrl}} while placing the text to force [[Draft_Snap|snapping]] your point to the nearest snap location, independently of the distance.
* Press {{KEY|G}} or click the {{MenuCommand|Global}} checkbox to toggle global mode. If global mode is on, coordinates are relative to the global coordinate system, else they are relative to the [[Draft_SelectPlane|working plane]] coordinate system. {{Version|0.20}}
* Press {{KEY|Enter}} or {{KEY|↓ Down arrow}} to enter a new line of text.
* Click the {{MenuCommand|Continue}} checkbox on the second task panel to toggle continue mode. The {{KEY|T}} keyboard shortcut does not work. If continue mode is on, the command will restart after finishing, allowing you to continue creating texts.
* Press {{KEY|↑ Up arrow}} to edit the previous line of text.
* Press {{KEY|Enter}} or {{KEY| Down arrow}} twice to finish editing the text.
* Press {{KEY|S}} to switch [[Draft_Snap|Draft snapping]] on or off.
* Press {{KEY|Esc}} or the {{Button|Close}} button to abort the command.
* Press {{KEY|Esc}} or the {{Button|Close}} button to abort the command.


==Notes==
==Notes== <!--T:26-->


<!--T:21-->
<!--T:21-->
* A Draft Text can be edited by double-clicking it in the [[Tree_view|Tree view]]. {{Version|0.20}}
* Draft Texts created with [[Release_notes_0.18|FreeCAD version 0.18]] are not backward compatible.
* Draft Texts created with [[Release_notes_0.18|FreeCAD version 0.18]] are not backward compatible.


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


<!--T:27-->
=== Data ===
See also: [[Property_editor|Property editor]].

<!--T:28-->
A Draft Text object is derived from an [[App_FeaturePython|App FeaturePython]] object and inherits all its properties. The following properties are additional unless otherwise stated.

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

<!--T:30-->
{{TitleProperty|Base}}


<!--T:12-->
<!--T:12-->
* {{PropertyData|Text}}: specifies the contents of the text block as a list of strings; each element on the list, separated by a comma, indicates a new line.
* {{PropertyData|Placement|Placement}}: specifies the position of the text in the [[3D view|3D view]]. See [[Placement|Placement]].
* {{PropertyData|Position}}: specifies the base point of the first line of the text block.
* {{PropertyData|Text|StringList}}: specifies the contents of the text. Each item in the list represents a new text line.

* {{PropertyData|Angle}}: specifies the rotation of the baseline of the first line of the text block.
=== View === <!--T:31-->
* {{PropertyData|Axis}}: specifies the axis to use for the rotation.

<!--T:32-->
{{TitleProperty|Annotation}}

<!--T:33-->
* {{PropertyView|Annotation Style|Enumeration}}: specifies the annotation style applied to the text. See [[Draft_AnnotationStyleEditor|Draft AnnotationStyleEditor]].
* {{PropertyView|Scale Multiplier|Float}}: specifies the general scaling factor applied to the text.

<!--T:34-->
{{TitleProperty|Display Options}}

<!--T:35-->
* {{PropertyView|Display Mode|Enumeration}}: specifies how the text is displayed. If it is {{value|3D text}} the text will be displayed in a plane defined by its {{PropertyData|Placement}}. If it is {{value|2D text}} the text will always face the camera. This is an inherited property.

<!--T:36-->
{{TitleProperty|Graphics}}

<!--T:37-->
* {{PropertyView|Line Color|Color}}: not used.
* {{PropertyView|Line Width|Float}}: not used.


<!--T:38-->
=== View ===
{{TitleProperty|Text}}


<!--T:13-->
<!--T:13-->
* {{PropertyView|Font Name|Font}}: specifies the font used to draw the text. It can be a font name, such as {{value|Arial}}, a default style such as {{value|sans}}, {{value|serif}} or {{value|mono}}, a family such as {{value|Arial,Helvetica,sans}}, or a name with a style such as {{value|Arial:Bold}}. If the given font is not found on the system, a default font is used instead.
* {{PropertyView|Display Mode}}: if it is "3D text" the text will be aligned to the scene axes, initially lying on the XY plane; if it is "2D text" the text will always face the camera.
* {{PropertyView|Font Name}}: specifies the font to use to draw the text. It can be a font name, such as "Arial", a default style such as "sans", "serif" or "mono", a family such as "Arial,Helvetica,sans" or a name with a style such as "Arial:Bold". If the given font is not found on the system, a generic one is used instead.
* {{PropertyView|Font Size|Length}}: specifies the size of the letters. The text can be invisible in the [[3D_view|3D view]] if this value is very small.
* {{PropertyView|Font Size}}: specifies the size of the letters. If the text object is created in the tree view but no text is visible, increase the size of the text until it is visible.
* {{PropertyView|Justification|Enumeration}}: specifies if the alignment of the text: {{value|Left}}, {{value|Center}} or {{value|Right}}.
* {{PropertyView|Justification}}: specifies if the text aligns to the left, right or at the center of the base point.
* {{PropertyView|Line Spacing|Float}}: specifies the factor applied to the default line height of the text.
* {{PropertyView|Line Spacing}}: specifies the space between lines of text.
* {{PropertyView|Text Color|Color}}: specifies the color of the text.


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


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


<!--T:14-->
<!--T:14-->
To create a Draft Text use the {{incode|make_line}} method of the Draft module:
To create a Draft Text use the {{incode|make_text}} method ({{Version|0.19}}) of the Draft module. This method replaces the deprecated {{incode|makeText}} method.


</translate>
</translate>
Line 92: Line 132:


<!--T:9-->
<!--T:9-->
* Creates a {{incode|text}} object, at {{incode|placement}}, which can be a {{incode|FreeCAD.Placement}}, but also a {{incode|FreeCAD.Rotation}}, or a {{incode|FreeCAD.Vector}}.
* Creates a {{incode|text}} object, at {{incode|placement}}, which can be a {{incode|FreeCAD.Placement}}, but also a {{incode|FreeCAD.Rotation}} or a {{incode|FreeCAD.Vector}}.
* {{incode|string}} is a string, or a list of strings. If it is a list, each element is displayed on its own line.
* {{incode|string}} is a string or a list of strings. If it is a list, each element is displayed on its own line.
* If {{incode|screen}} is {{incode|True}}, the text always faces the camera, otherwise it aligns with the scene axes, and lies on the XY plane.
* If {{incode|screen}} is {{incode|True}}, the text always faces the camera, otherwise it is displayed in a plane defined by its {{PropertyData|Placement}}.


<!--T:16-->
<!--T:16-->
The view properties of {{incode|Text}} can be changed by overwriting its attributes; for example, overwrite {{incode|ViewObject.FontSize}} with the new size in millimeters.
The view properties of {{incode|text}} can be changed by overwriting its attributes; for example, overwrite {{incode|ViewObject.FontSize}} with the new size in millimeters.


<!--T:10-->
<!--T:10-->
Line 104: Line 144:
</translate>
</translate>
{{Code|code=
{{Code|code=
import FreeCAD, Draft
import FreeCAD as App
import Draft

doc = App.newDocument()


p1 = FreeCAD.Vector(0, 0, 0)
t1 = "This is a sample text"
t1 = "This is a sample text"
p1 = App.Vector(0, 0, 0)


p2 = FreeCAD.Vector(1000, 1000, 0)
t2 = ["First line", "second line"]
t2 = ["First line", "second line"]
p2 = App.Vector(1000, 1000, 0)


Text1 = Draft.makeText(t1, point=p1)
text1 = Draft.make_text(t1, p1)
Text2 = Draft.makeText(t2, point=p2)
text2 = Draft.make_text(t2, p2)
Text1.ViewObject.FontSize = 200
text1.ViewObject.FontSize = 200
Text2.ViewObject.FontSize = 200
text2.ViewObject.FontSize = 200

zaxis = App.Vector(0, 0, 1)


p3 = FreeCAD.Vector(-1000, -500, 0)
t3 = ["Upside", "down"]
t3 = ["Upside", "down"]
p3 = App.Vector(-1000, -500, 0)
place3 = App.Placement(p3, App.Rotation(zaxis, 180))
text3 = Draft.make_text(t3, place3)
text3.ViewObject.FontSize = 200


doc.recompute()
Text3 = Draft.makeText(t3, point=p3)
Text3.ViewObject.FontSize = 200

ZAxis = FreeCAD.Vector(0, 0, 1)
place3 = FreeCAD.Placement(p3, FreeCAD.Rotation(ZAxis, 175))
Text3.Placement = place3

Text4 = Draft.makeText(t3, point=p3)
Text4.ViewObject.FontSize = 200
Text4.Placement.Rotation = FreeCAD.Rotation(ZAxis, -30)
}}
}}
<translate>
<translate>
Line 136: Line 175:
<!--T:17-->
<!--T:17-->
{{Docnav
{{Docnav
|[[Draft_Hatch|Hatch]]
|[[Draft_ShapeString|ShapeString]]
|[[Draft_Dimension|Dimension]]
|[[Draft_Dimension|Dimension]]
|[[Draft_Module|Draft]]
|[[Draft_Workbench|Draft]]
|IconL=Draft_ShapeString.svg
|IconL=Draft_Hatch.svg
|IconR=Draft_Dimension.svg
|IconR=Draft_Dimension.svg
|IconC=Workbench_Draft.svg
|IconC=Workbench_Draft.svg

Revision as of 07:22, 26 October 2021

Draft Text

Menu location
Annotation → Text
Workbenches
Draft, Arch
Default shortcut
T E
Introduced in version
0.7
See also
Draft Label, Draft ShapeString

Description

The Draft Text command creates a multi-line text at a given point.

To create a text element with an arrow use the Draft Label command instead.

Single point required to position the text

Usage

See also: Draft Tray and Draft Snap.

  1. There are several ways to invoke the command:
    • Press the Draft Text button.
    • Select the Annotation → Text option from the menu.
    • Use the keyboard shortcut: T then E.
  2. The Text task panel opens. See Options for more information.
  3. Pick a point in the 3D view, or type coordinates and press the Enter point button.
  4. Enter the desired text, press Enter to start a new line.
  5. Press Enter twice or press the Create text button to finish the command.

Options

The single character keyboard shortcuts available in the task panel can be changed. See Draft Preferences. The shortcuts mentioned here are the default shortcuts.

  • To manually enter coordinates enter the X, Y and Z component, and press Enter after each. Or you can press the Enter point button when you have the desired values. It is advisable to move the pointer out of the 3D view before entering coordinates.
  • The Relative checkbox has no purpose for this command.
  • Press G or click the Global checkbox to toggle global mode. If global mode is on, coordinates are relative to the global coordinate system, else they are relative to the working plane coordinate system. introduced in version 0.20
  • Click the Continue checkbox on the second task panel to toggle continue mode. The T keyboard shortcut does not work. If continue mode is on, the command will restart after finishing, allowing you to continue creating texts.
  • Press S to switch Draft snapping on or off.
  • Press Esc or the Close button to abort the command.

Notes

Properties

See also: Property editor.

A Draft Text object is derived from an App FeaturePython object and inherits all its properties. The following properties are additional unless otherwise stated.

Data

Base

  • DataPlacement (Placement): specifies the position of the text in the 3D view. See Placement.
  • DataText (StringList): specifies the contents of the text. Each item in the list represents a new text line.

View

Annotation

  • ViewAnnotation Style (Enumeration): specifies the annotation style applied to the text. See Draft AnnotationStyleEditor.
  • ViewScale Multiplier (Float): specifies the general scaling factor applied to the text.

Display Options

  • ViewDisplay Mode (Enumeration): specifies how the text is displayed. If it is 3D text the text will be displayed in a plane defined by its DataPlacement. If it is 2D text the text will always face the camera. This is an inherited property.

Graphics

  • ViewLine Color (Color): not used.
  • ViewLine Width (Float): not used.

Text

  • ViewFont Name (Font): specifies the font used to draw the text. It can be a font name, such as Arial, a default style such as sans, serif or mono, a family such as Arial,Helvetica,sans, or a name with a style such as Arial:Bold. If the given font is not found on the system, a default font is used instead.
  • ViewFont Size (Length): specifies the size of the letters. The text can be invisible in the 3D view if this value is very small.
  • ViewJustification (Enumeration): specifies if the alignment of the text: Left, Center or Right.
  • ViewLine Spacing (Float): specifies the factor applied to the default line height of the text.
  • ViewText Color (Color): specifies the color of the text.

Scripting

See also: Autogenerated API documentation and FreeCAD Scripting Basics.

To create a Draft Text use the make_text method (introduced in version 0.19) of the Draft module. This method replaces the deprecated makeText method.

text = make_text(string, placement=None, screen=False)
  • Creates a text object, at placement, which can be a FreeCAD.Placement, but also a FreeCAD.Rotation or a FreeCAD.Vector.
  • string is a string or a list of strings. If it is a list, each element is displayed on its own line.
  • If screen is True, the text always faces the camera, otherwise it is displayed in a plane defined by its DataPlacement.

The view properties of text can be changed by overwriting its attributes; for example, overwrite ViewObject.FontSize with the new size in millimeters.

Example:

import FreeCAD as App
import Draft

doc = App.newDocument()

t1 = "This is a sample text"
p1 = App.Vector(0, 0, 0)

t2 = ["First line", "second line"]
p2 = App.Vector(1000, 1000, 0)

text1 = Draft.make_text(t1, p1)
text2 = Draft.make_text(t2, p2)
text1.ViewObject.FontSize = 200
text2.ViewObject.FontSize = 200

zaxis = App.Vector(0, 0, 1)

t3 = ["Upside", "down"]
p3 = App.Vector(-1000, -500, 0)
place3 = App.Placement(p3, App.Rotation(zaxis, 180))
text3 = Draft.make_text(t3, place3)
text3.ViewObject.FontSize = 200

doc.recompute()