Draft Label: Difference between revisions

From FreeCAD Documentation
No edit summary
("Hold" instead of "press")
(23 intermediate revisions by the same user not shown)
Line 2: Line 2:
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{GuiCommand
{{GuiCommand|Name=Draft Label|Workbenches=[[Draft Module|Draft]], [[Arch Module|Arch]]|MenuLocation=Draft → Label|Shortcut=D L}}
|Name=Draft Label
|MenuLocation=Draft → Label
|Workbenches=[[Draft Module|Draft]], [[Arch Module|Arch]]
|Shortcut=D L
|SeeAlso=[[Draft Text]], [[Draft ShapeString]]
|Version=0.17
}}


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


<!--T:15-->
<!--T:15-->
This tool inserts a label, which is a piece of text with a 2-segment line and an arrow, in the active document. If an object or a sub-element (face, edge or vertex) is selected when starting the command, the Label can be made to automatically display a certain attribute of the selected element.
The Label tool inserts a multi-line textbox with a 2-segment leader line and an arrow. If an object or a sub-element (face, edge or vertex) is selected when starting the command, the Label can be made to display a certain attribute of the selected element, including position, length, area, volume, or material.

To insert a simpler text element without an arrow use [[Draft Text]]. To create solid text shapes use [[Draft ShapeString]] with [[Part Extrude]].


<!--T:3-->
<!--T:3-->
Line 15: Line 24:


<!--T:5-->
<!--T:5-->
# Press the {{Button|[[Image:Draft Label.png|16px]] [[Draft Label]]}} button, or press {{KEY|D}} then {{KEY|L}} keys.
# Optionally, select an object or a subelement of an object (Vertex, edge or face)
# Click a first 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. This point indicates the target (arrow head). This can be anywhere, it doesn't need to be an element.
# Press the {{KEY|[[Image:Draft Label.png|16px]] [[Draft Label]]}} button, or press {{KEY|D}} then {{KEY|L}} keys
# Click a first point on the 3D view, or type a [[Draft_Coordinates|coordinate]], to indicate the target point (arrow position). This can be anywhere, it doesn't need to be exactly on the selected element
# Click a second 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. This point indicates the start of a horizontal or vertical leader.
# Click a second point on the 3D view, or type a [[Draft_Coordinates|coordinate]], to indicate the middle point that is the start of the straight segment.
# Click a third 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. This point indicates the base point of the text.

# Click a third point on the 3D view, or type a [[Draft_Coordinates|coordinate]], to indicate the position of the text.
{{emphasis|Note:}} the direction of the horizontal straight segment, to the right or to the left, will automatically align the text to the opposite direction. If the leader goes vertically up, the text is aligned to the left; if it goes vertically down, it is aligned to the right.

{{emphasis|Note 2:}} by pre-selecting an object, or a sub-element (vertex, edge or face), before pressing the tool button, the label will become parametric, that is, it will remember which object it is bound to, and it will be able to display a particular attribute of that object. If the attributes of the object change later on, the label will adjust the displayed information.


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


<!--T:7-->
<!--T:7-->
* Click on {{Button|Label type}} to select the type of information to display, including "Custom", "Name", "Label", "Position", "Length", "Area", "Volume", "Tag", and "Material".
* Pressing {{KEY|CTRL}} will [[Draft_Snap|snap]] your point to available snap locations.
* 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.
* Hold {{KEY|Ctrl}} while placing the label to force [[Draft_Snap|snapping]] your point to the nearest snap location, independently of the distance.
* Pressing {{KEY|ESC}} will cancel the operation.
* Press {{KEY|Esc}} or the {{button|Close}} button to abort the current command.
* The direction of the straight segment (right or left) will automatically justify the text left or right.


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


<!--T:9-->
=== Data === <!--T:9-->
* {{PropertyData|Label Type}}: The type of information shown by this label (see below)
* {{PropertyData|Label Type}}: specifies the type of information shown by this label (see below).
* {{PropertyData|Custom Text}}: The text to display when Label Type is set to custom
* {{PropertyData|Custom Text}}: specifies the text block to display when {{PropertyData|Label Type}} is set to "Custom", or the label is not parametric. The text is given as a list of strings; each element on the list, separated by a comma, indicates a new line of text.
* {{PropertyData|Placement}}: Indicates the rotation and the position of the text
* {{PropertyData|Text}}: (read-only) indicates the actual text displayed by the label, depending on the {{PropertyData|Label Type}}.
* {{PropertyData|Straight Distance}}: The length of the straight segment
* {{PropertyData|Target Point}}: specifies the position of the tip of the leader.
* {{PropertyData|Straight Direction}}: The direction of the straight segment Horizontal or vertical
* {{PropertyData|Straight Direction}}: specifies the direction of the straight segment of the leader, either horizontal or vertical.
* {{PropertyData|Straight Distance}}: specifies the length of the straight segment of the leader, starting from the base point of the text. If the distance is positive, the leader starts from the right side of the text, and the text aligns to the right; otherwise, the leader starts from the left side of the text, and the text aligns to the left.
* {{PropertyData|Target Point}}: The point indicated by this label
* {{PropertyData|Position}}: specifies the base point of the first line of the text block; it also influences how the leader is drawn.
* {{PropertyView|Text Size}}: The size of the text
* {{PropertyData|Angle}}: specifies the rotation of the baseline of the first line of the text block; it also influences how the leader is drawn, as it will no longer be horizontal or vertical.
* {{PropertyView|Text Font}}: The font used for the text
* {{PropertyData|Axis}}: specifies the axis to use for the rotation.
* {{PropertyView|Text Alignment}}: The vertical alignment of the text: Top, middle or bottom
* {{PropertyView|Text Color}}: The color of the text
* {{PropertyView|Line Width}}: The width of the line
* {{PropertyView|Line Color}}: The color of the line
* {{PropertyView|Arrow Type}}: The type of the arrow: Dot, circle, arrow or tick.
* {{PropertyView|Arrow Size}}: The size of the arrow
* {{PropertyView|Frame}}: Draws a frame around the text


== Label types == <!--T:10-->
==== Label types ==== <!--T:10-->


<!--T:11-->
<!--T:11-->
* '''Custom''': Shows the contents of the Custom Text property
* '''Custom''': displays the contents of {{PropertyData|Custom Text}}.
* '''Name''': Shows the name of the target object
* '''Name''': displays the internal name of the target object; the internal name is assigned to the object at its creation time, and remains fixed throughout the existence of the object.
* '''Label''': Shows the label of the target object
* '''Label''': displays the label of the target object; the label of the object can be changed by the user at any time.
* '''Position''': Shows the coordinates of the target object (Placement base point), or the coordinates of the target vertex, if applicable, or the coordinates of the center of the target subelement (center of mass)
* '''Position''': displays the coordinates of the base point of the target object, of the target vertex, or of the center of mass of the target sub-element, if applicable.
* '''Length''': Shows the length of the target subelement, if possible
* '''Length''': displays the length of the target sub-element, if applicable.
* '''Area''': Shows the area of the target subelement, if possible
* '''Area''': displays the area of the target sub-element, if applicable.
* '''Volume''': Shows the volume of the target object, if possible
* '''Volume''': displays the volume of the target object, if applicable.
* '''Tag''': Shows the tag value of the target object, if the target object has such property (which is the case of all Arch objects)
* '''Tag''': displays the {{incode|Tag}} attribute of the target object, if the object has such property, for example, objects created with the [[Arch Workbench]].
* '''Material''': Shows the label of the material of the target object, if the target object has such property
* '''Material''': displays the label of the material of the target object, if the target object has such property.

=== View ===
* {{PropertyView|Text Font}}: 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|Text Size}}: specifies the size of the text. If the label object is created in the tree view but no text is visible in the 3D view, increase the size of the text until it is visible.
* {{PropertyView|Text Alignment}}: specifies the vertical alignment of the baseline of the text with respect to the leader. It can be top, middle or bottom.
* {{PropertyView|Text Color}}: specifies the color of the text in an RGB tuple (R, G, B).
* {{PropertyView|Line Width}}: specifies the width of the leader.
* {{PropertyView|Line Color}}: specifies the color of the leader.
* {{PropertyView|Arrow Size}}: specifies the size of the symbol displayed at the tip of the leader.
* {{PropertyView|Arrow Type}}: specifies the type of symbol displayed at the tip of the leader, which can be dot, circle, arrow, or tick.
* {{PropertyView|Frame}}: if it is "Rectangle" it will draw a frame around the text.
* {{PropertyView|Line}}: if it is {{TRUE}} the leader line will be displayed; otherwise only the text and the symbol at the tip will be displayed.
* {{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.


==Scripting== <!--T:12-->
==Scripting== <!--T:12-->
{{Emphasis|See also:}} [[Draft API]] and [[FreeCAD Scripting Basics]].
The Text tool can by used in [[macros]] and from the python console by using the following function:

The Label tool can be used in [[macros]] and from the [[Python]] console by using the following function:
</translate>
</translate>
{{Code|code=
{{Code|code=
makeLabel(targetpoint=None,target=None,direction=None,distance=None,labeltype=None,placement=None)
Label = makeLabel(targetpoint=None, target=None, direction=None, distance=None, labeltype=None, placement=None)
}}
}}
<translate>
<translate>


<!--T:13-->
<!--T:13-->
* Creates a {{incode|Label}} object, with the leader pointing to {{incode|targetpoint}}, and linking to the {{incode|target}} object which must be a {{incode|DocumentObject}} ({{emphasis|Editor:}} or a SelectionObject? This is unclear).
* Returns the newly created object.
* {{incode|direction}} is either "Horizontal", "Vertical", or "Custom".
* {{incode|distance}} is the distance from the base point of the text to the leader.
* {{incode|labeltype}} is one of "Custom", "Name", "Label", "Position", "Length", "Area", "Volume", "Tag", or "Material".
* If a {{incode|placement}} is given, it is used for the base point of the text; otherwise the text is created at the origin.

Change the custom text by overwriting the {{incode|CustomText}} attribute. A list of strings can be used; each element will be displayed in its own line.

The view properties of {{incode|Label}} can be changed by overwriting its attributes; for example, overwrite {{incode|ViewObject.TextSize}} with the new size in millimeters.


<!--T:14-->
<!--T:14-->
Line 76: Line 105:
</translate>
</translate>
{{Code|code=
{{Code|code=
import FreeCAD,Draft
import FreeCAD, Draft
selection = FreeCADGui.Selection.getSelectionEx()[0]
Draft.makeLabel(FreeCAD.Vector(10,-10,0),selection,"Horizontal",20,"Label")
}}


Rectangle = Draft.makeRectangle(4000, 1000)

p1 = FreeCAD.Vector(-200, 1000, 0)
place1 = FreeCAD.Placement(FreeCAD.Vector(-1000, 1300, 0), FreeCAD.Rotation())

Label1 = Draft.makeLabel(p1, Rectangle, "Horizontal", 500, "Label", place1)
Label1.ViewObject.TextSize = 200

p2 = FreeCAD.Vector(-200, 0, 0)
place2 = FreeCAD.Placement(FreeCAD.Vector(-1000, -300, 0), FreeCAD.Rotation())

Label2 = Draft.makeLabel(p2, Rectangle, "Horizontal", 500, "Custom", place2)
Label2.CustomText = ["Beware of the", "sharp edges"]
Label2.ViewObject.TextSize = 200
FreeCAD.ActiveDocument.recompute()

p3 = FreeCAD.Vector(1000, 1200, 0)
place3 = FreeCAD.Placement(FreeCAD.Vector(2000, 1800, 0), FreeCAD.Rotation())

Label3 = Draft.makeLabel(p3, Rectangle, "Horizontal", -500, "Area", place3)
Label3.ViewObject.TextSize = 200
FreeCAD.ActiveDocument.recompute()
}}
{{Draft Tools navi}}
{{Userdocnavi}}
{{clear}}
{{clear}}

Revision as of 22:04, 12 November 2018

Draft Label

Menu location
Draft → Label
Workbenches
Draft, Arch
Default shortcut
D L
Introduced in version
0.17
See also
Draft Text, Draft ShapeString

Description

The Label tool inserts a multi-line textbox with a 2-segment leader line and an arrow. If an object or a sub-element (face, edge or vertex) is selected when starting the command, the Label can be made to display a certain attribute of the selected element, including position, length, area, volume, or material.

To insert a simpler text element without an arrow use Draft Text. To create solid text shapes use Draft ShapeString with Part Extrude.

How to use

  1. Press the Draft Label button, or press D then L keys.
  2. Click a first point on the 3D view, or type a coordinate and press the add point button. This point indicates the target (arrow head). This can be anywhere, it doesn't need to be an element.
  3. Click a second point on the 3D view, or type a coordinate and press the add point button. This point indicates the start of a horizontal or vertical leader.
  4. Click a third point on the 3D view, or type a coordinate and press the add point button. This point indicates the base point of the text.

Note: the direction of the horizontal straight segment, to the right or to the left, will automatically align the text to the opposite direction. If the leader goes vertically up, the text is aligned to the left; if it goes vertically down, it is aligned to the right.

Note 2: by pre-selecting an object, or a sub-element (vertex, edge or face), before pressing the tool button, the label will become parametric, that is, it will remember which object it is bound to, and it will be able to display a particular attribute of that object. If the attributes of the object change later on, the label will adjust the displayed information.

Options

  • Click on Label type to select the type of information to display, including "Custom", "Name", "Label", "Position", "Length", "Area", "Volume", "Tag", and "Material".
  • 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.
  • Hold Ctrl while placing the label to force snapping your point to the nearest snap location, independently of the distance.
  • Press Esc or the Close button to abort the current command.

Properties

Data

  • DataLabel Type: specifies the type of information shown by this label (see below).
  • DataCustom Text: specifies the text block to display when DataLabel Type is set to "Custom", or the label is not parametric. The text is given as a list of strings; each element on the list, separated by a comma, indicates a new line of text.
  • DataText: (read-only) indicates the actual text displayed by the label, depending on the DataLabel Type.
  • DataTarget Point: specifies the position of the tip of the leader.
  • DataStraight Direction: specifies the direction of the straight segment of the leader, either horizontal or vertical.
  • DataStraight Distance: specifies the length of the straight segment of the leader, starting from the base point of the text. If the distance is positive, the leader starts from the right side of the text, and the text aligns to the right; otherwise, the leader starts from the left side of the text, and the text aligns to the left.
  • DataPosition: specifies the base point of the first line of the text block; it also influences how the leader is drawn.
  • DataAngle: specifies the rotation of the baseline of the first line of the text block; it also influences how the leader is drawn, as it will no longer be horizontal or vertical.
  • DataAxis: specifies the axis to use for the rotation.

Label types

  • Custom: displays the contents of DataCustom Text.
  • Name: displays the internal name of the target object; the internal name is assigned to the object at its creation time, and remains fixed throughout the existence of the object.
  • Label: displays the label of the target object; the label of the object can be changed by the user at any time.
  • Position: displays the coordinates of the base point of the target object, of the target vertex, or of the center of mass of the target sub-element, if applicable.
  • Length: displays the length of the target sub-element, if applicable.
  • Area: displays the area of the target sub-element, if applicable.
  • Volume: displays the volume of the target object, if applicable.
  • Tag: displays the Tag attribute of the target object, if the object has such property, for example, objects created with the Arch Workbench.
  • Material: displays the label of the material of the target object, if the target object has such property.

View

  • ViewText Font: 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.
  • ViewText Size: specifies the size of the text. If the label object is created in the tree view but no text is visible in the 3D view, increase the size of the text until it is visible.
  • ViewText Alignment: specifies the vertical alignment of the baseline of the text with respect to the leader. It can be top, middle or bottom.
  • ViewText Color: specifies the color of the text in an RGB tuple (R, G, B).
  • ViewLine Width: specifies the width of the leader.
  • ViewLine Color: specifies the color of the leader.
  • ViewArrow Size: specifies the size of the symbol displayed at the tip of the leader.
  • ViewArrow Type: specifies the type of symbol displayed at the tip of the leader, which can be dot, circle, arrow, or tick.
  • ViewFrame: if it is "Rectangle" it will draw a frame around the text.
  • ViewLine: if it is true the leader line will be displayed; otherwise only the text and the symbol at the tip will be displayed.
  • ViewDisplay 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.

Scripting

See also: Draft API and FreeCAD Scripting Basics.

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

Label = makeLabel(targetpoint=None, target=None, direction=None, distance=None, labeltype=None, placement=None)
  • Creates a Label object, with the leader pointing to targetpoint, and linking to the target object which must be a DocumentObject (Editor: or a SelectionObject? This is unclear).
  • direction is either "Horizontal", "Vertical", or "Custom".
  • distance is the distance from the base point of the text to the leader.
  • labeltype is one of "Custom", "Name", "Label", "Position", "Length", "Area", "Volume", "Tag", or "Material".
  • If a placement is given, it is used for the base point of the text; otherwise the text is created at the origin.

Change the custom text by overwriting the CustomText attribute. A list of strings can be used; each element will be displayed in its own line.

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

Example:

import FreeCAD, Draft

Rectangle = Draft.makeRectangle(4000, 1000)

p1 = FreeCAD.Vector(-200, 1000, 0)
place1 = FreeCAD.Placement(FreeCAD.Vector(-1000, 1300, 0), FreeCAD.Rotation())

Label1 = Draft.makeLabel(p1, Rectangle, "Horizontal", 500, "Label", place1)
Label1.ViewObject.TextSize = 200

p2 = FreeCAD.Vector(-200, 0, 0)
place2 = FreeCAD.Placement(FreeCAD.Vector(-1000, -300, 0), FreeCAD.Rotation())

Label2 = Draft.makeLabel(p2, Rectangle, "Horizontal", 500, "Custom", place2)
Label2.CustomText = ["Beware of the", "sharp edges"]
Label2.ViewObject.TextSize = 200
FreeCAD.ActiveDocument.recompute()

p3 = FreeCAD.Vector(1000, 1200, 0)
place3 = FreeCAD.Placement(FreeCAD.Vector(2000, 1800, 0), FreeCAD.Rotation())

Label3 = Draft.makeLabel(p3, Rectangle, "Horizontal", -500, "Area", place3)
Label3.ViewObject.TextSize = 200
FreeCAD.ActiveDocument.recompute()