Class: Sketchup::Text

Inherits:
Drawingelement show all

Overview

The Text class contains method to manipulate a Text entity object.

Version:

  • SketchUp 6.0

Instance Method Summary # collapse

Methods inherited from Drawingelement

#bounds, #casts_shadows=, #casts_shadows?, #erase!, #hidden=, #hidden?, #layer, #layer=, #material, #material=, #receives_shadows=, #receives_shadows?, #visible=, #visible?

Methods inherited from Entity

#add_observer, #attribute_dictionaries, #attribute_dictionary, #delete_attribute, #deleted?, #entityID, #get_attribute, #inspect, #model, #parent, #persistent_id, #remove_observer, #set_attribute, #to_s, #typename, #valid?

Instance Method Details

#arrow_typeInteger

The arrow_type method retrieves the current arrow type used for the leader text.

Valid arrow types are:

Examples:

type = text.arrow_type=0

Returns:

  • (Integer)

    a numerical representation for the type of arrow.

Version:

  • SketchUp 6.0

#arrow_type=(type) ⇒ Integer

The arrow_type= method sets the arrow type used for leader text.

Valid arrow types are:

Examples:

arrow = text.arrow_type=type

Parameters:

  • type (Integer)

    A numerical representation of the type of arrow to be set.

Returns:

  • (Integer)

    a numerical representation for the type of arrow.

Version:

  • SketchUp 6.0

#attached_toArray(Sketchup::InstancePath, Geom::Point3d)?

The #attached_to method returns an array of the attached InstancePath object and the Geom::Point3d.

Examples:

# Have a text annotation attached to a drawing element and selected
Sketchup.active_model.selection[0].attached_to

Returns:

Version:

  • SketchUp 2019

#attached_to=(path) ⇒ Object

The #attached_to= method will attach the Sketchup::Text to another DrawingElement.

Examples:

# Have a text annotation attached to a drawing element and selected
array = Sketchup.active_model.selection[0].attached_to
Sketchup.active_model.selection[0].attached_to = [array[0], Geom::Point3d.new(0, 0, 0)]

Parameters:

Version:

  • SketchUp 2019

#display_leader=(status) ⇒ Boolean

The display_leader= method accepts true or false for whether to display the leader.

Leader text that is not displayed is set to Hidden type.

Examples:

leader = text.display_leader=true

Parameters:

  • status (Boolean)

    true if you want to display the leader text, false if you do not want to display the leader text.

Returns:

  • (Boolean)

    the status that you set.

Version:

  • SketchUp 6.0

#display_leader?Boolean

The display_leader? method returns the status of the leader.

Examples:

status = text.display_leader

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0

#fontHash{Symbol => String, Integer, Boolean}?

The #font method returns the font properties of the Text object as a Hash.

Examples:

Get font properties

text = Sketchup.active_model.entities.add_text("Hello", ORIGIN)
props = text.font
# => { name: "Arial", size: 12, bold: false, italic: false }
puts props[:name]  # => "Arial"
puts props[:size]  # => 12

Returns:

  • (Hash{Symbol => String, Integer, Boolean}, nil)

    A Hash of font properties. Text is created with a default font, so a Hash is typically always returned. nil only if no per-entity font is associated (the model default is used for display in that case).

    Keys:

    • :name [String] Font face name.

    • :size [Integer] Size in points (1–1000).

    • :bold [Boolean] Bold weight.

    • :italic [Boolean] Italic style.

Version:

  • SketchUp 2026.2

#font=(properties) ⇒ Object

Note:

If the :name value is not a font installed on the current system, SketchUp substitutes a system fallback font without raising an error. The stored face name is still set to the requested value and will be honored if the font is later installed.

The #font= method sets the font properties of the Text object.

Keys omitted from the hash inherit their values from the entity's current font (or the model default if no per-entity font has been set yet). Passing an empty Hash is a no-op.

Examples:

Set all properties at once

text = Sketchup.active_model.entities.add_text("Hello", ORIGIN)
text.font = { name: "Times New Roman", size: 18, bold: false, italic: true }

Change only the size, keeping all other properties

text.font = { size: 24 }

Parameters:

  • properties (Hash)

    Font properties. Keys:

    • :name [String] Font face name.

    • :size [Integer] Size in points. Must be in the range 1–1000.

    • :bold [Boolean] Bold weight.

    • :italic [Boolean] Italic style.

Raises:

  • (TypeError)

    if properties is not a Hash.

  • (RangeError)

    if :size is outside the range 1–1000.

Version:

  • SketchUp 2026.2

#has_leader?Boolean

The has_leader method is used to determine if the Text object has a leader.

Examples:

status = text.has_leader

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0

#leader_typeInteger

The #leader_type method retrieves the currently set leader type.

Valid leaders types are:

Examples:

leader = text.leader_type

Returns:

  • (Integer)

    a numerical value representing the currently set leader type.

Version:

  • SketchUp 6.0

#leader_type=(type) ⇒ Integer

Note:

ALeaderNone cannot be set. It is only used internally as a default value. Trying to set it will raise a warning.

The #leader_type= method sets the leader type.

Valid leaders types are:

Examples:

leader = text.leader_type=1

Parameters:

  • type (Integer)

    A numerical value representing the leader type to be set.

Returns:

  • (Integer)

    a numerical value representing the leader type you just set.

Raises:

  • (RangeError)

    if the value is other than (ALeaderView, or ALeaderModel).

Version:

  • SketchUp 6.0

#line_weightInteger

The line_weight method returns a line weight in number of pixels.

Defalt line weight is 1.

Examples:

weight = text.line_weight

Returns:

  • (Integer)

    the line weight in pixels

Version:

  • SketchUp 6.0

#line_weight=(weight) ⇒ Integer

The line_weight= method sets the line weight in pixels.

Default line weight is 1.

Examples:

newweight = text.line_weight = 4

Parameters:

  • weight (Integer)

    The line weight to be set (in pixels).

Returns:

  • (Integer)

    The line weight that has been set.

Version:

  • SketchUp 6.0

#pointGeom::Point3d

The point method is used to get the point associated with the text.

Examples:

point3d = text.point

Returns:

Version:

  • SketchUp 6.0

#point=(point3d) ⇒ Geom::Point3d

The point= method is used to set the point associated with the text.

Examples:

status = text.point = point3d

Parameters:

Returns:

Version:

  • SketchUp 6.0

#set_text(textstring) ⇒ Sketchup::Text

The set_text method is used to set the text within a Text object without recording an Undo operation.

Examples:

text = text.set_text "This is another text"

Parameters:

  • textstring (String)

    The string to be set within the Text object.

Returns:

Version:

  • SketchUp 6.0

Known Bugs:

  • Sketchup::Text objects without leaders that are attached to the model viewport will not immediatly display content changes. Changes can be triggered by the user with a view refresh (clicking inside the view) or programmatically by calling View#invalidate.

#textString

The text method is used to retrieve the string version of a Text object.

Examples:

textstring = text.text

Returns:

  • (String)

    the string representation of the Text object

Version:

  • SketchUp 6.0

#text=(textstring) ⇒ String

The text= method is used to set the string version of a Text object.

Examples:

textstring = text.text= "text"

Parameters:

Returns:

  • (String)

    the newly set text

Version:

  • SketchUp 6.0

#vectorGeom::Vector3d

The vector method is used to get the vector associated with the text.

Examples:

vector = text.vector

Returns:

Version:

  • SketchUp 6.0

#vector=(vector) ⇒ Geom::Vector3d

The vector= method is used to set the vector associated with the text.

Examples:

vector = text.vector

Parameters:

Returns:

Version:

  • SketchUp 6.0