Draft Text: Difference between revisions

From FreeCAD Documentation
Line 117: Line 117:
* 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 aligns with the scene axes and lies on the XY plane.


<!--T:16-->
<!--T:16-->

Revision as of 09:31, 30 March 2021

This documentation is a work in progress. Please don't mark it as translatable since it will change in the next hours and days.

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 inserts a multi-line textbox at a given point. It uses the Draft Linestyle set on the Draft Tray.

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

Single point required to position the textbox

Usage

  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. Click a point on the 3D view, or type coordinates and press the Enter point button.
  3. Enter the desired text, pressing Enter between each line.
  4. Press Enter twice to finish the command.

Options

  • To enter coordinates manually, simply enter the numbers, then press Enter between each X, Y and Z component. You can press the Enter point button when you have the desired values to insert the point.
  • Hold Ctrl while placing the text to force snapping your point to the nearest snap location, independently of the distance.
  • Press Enter or ↓ Down arrow to enter a new line of text.
  • Press ↑ Up arrow to edit the previous line of text.
  • Press Enter or ↓ Down arrow twice to finish editing the text.
  • 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 aligns with the scene axes and lies on the XY plane.

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()