Class: Layout::Entity

Inherits:
Object
  • Object
show all

Overview

An entity is an object shown on a page of a LayOut document.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
# Get the shared entities in the document. If there are no shared layers,
# the resulting array will be empty.
entities = doc.shared_entities

# Count how many of the shared entites are rectangles.
rectangle_count = entities.grep(Layout::Rectangle).size

Version:

  • LayOut 2018

Instance Method Summary # collapse

Instance Method Details

#==(other) ⇒ Boolean

The #== method checks to see if the two Layout::Entitys are equal. This checks whether the Ruby Objects are pointing to the same internal object.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
page_entities = doc.pages.first.entities
layer_entities = doc.layers.first.layer_instance(page).entities
page_entities.first == layer_entities.first

Parameters:

Returns:

  • (Boolean)

Version:

  • LayOut 2018

#attribute_dictionary(name) ⇒ Layout::Dictionary?

The #attribute_dictionary method returns a copy of the entity's attribute dictionary with the given name.

no attribute dictionary

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entity = doc.pages.first.entities.first
entity.set_attribute("jane_doe_doc_maker", "made_by_doc_maker", true)
attributes = entity.attribute_dictionary("jane_doe_doc_maker")
# Adding to this Layout::Dictionary does not apply to the entity's attribute dictionary, use
#Layout::Entity#set_attribute.
attributes.merge!(doc_id: 42)

Parameters:

Returns:

  • (Layout::Dictionary, nil)

    A copy of the entity's attribute dictionary, or nil if there is

Version:

  • LayOut 2026.0

#boundsGeom::Bounds2d

The #bounds method returns the 2D rectangular bounds of the Layout::Entity.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities
bounds = entities.first.bounds

Returns:

Version:

  • LayOut 2018

#delete_attribute(dictionary_name) ⇒ Boolean #delete_attribute(dictionary_name, key) ⇒ Boolean

The #delete_attribute method is used to delete an attribute from an entity.

Overloads:

  • #delete_attribute(dictionary_name) ⇒ Boolean

    Examples:

    doc = Layout::Document.open("C:/path/to/document.layout")
    entity = doc.pages.first.entities.first
    entity.set_attribute("jane_doe_doc_maker", "made_by_doc_maker", true)
    entity.delete_attribute("jane_doe_doc_maker")

    Parameters:

    • dictionary_name (String)

      The name of an attribute dictionary.

    Returns:

    • (Boolean)
  • #delete_attribute(dictionary_name, key) ⇒ Boolean

    Examples:

    doc = Layout::Document.open("C:/path/to/document.layout")
    entity = doc.pages.first.entities.first
    entity.set_attribute("jane_doe_doc_maker", "made_by_doc_maker", true)
    entity.delete_attribute("jane_doe_doc_maker", "made_by_doc_maker")

    Parameters:

    • dictionary_name (String)

      The name of an attribute dictionary.

    • key (String)

      An attribute key.

    Returns:

    • (Boolean)

Version:

  • LayOut 2026.0

#documentLayout::Document?

The #document method returns the Document that the Layout::Entity belongs to, or nil if it is not in a Document.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.shared_entities
# entity_doc should be the same document as doc
entity_doc = entities.first.document

Returns:

Version:

  • LayOut 2018

#drawing_boundsGeom::OrientedBounds2d

The #drawing_bounds method returns the 2D rectangular drawing bounds of the Layout::Entity.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities
draw_bounds = entities.first.drawing_bounds

Returns:

Version:

  • LayOut 2018

#get_attribute(name, key, default_value = nil) ⇒ String, ...

The #get_attribute method is used to retrieve the value of an attribute in the entity's attribute dictionary.

If the third parameter, default_value, is not passed and there is no attribute that matches the given name, it returns nil.

If default_value is provided and there is no matching attribute it returns the given value. It does not create an attribute with that name though.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entity = doc.pages.first.entities.first
# Read an attribute value from the entity. In this case this will return the
# default value provided: 42.
entity.get_attribute("jane_doe_doc_maker", "doc_id", 42)

Parameters:

  • name (String)

    The name of an attribute dictionary.

  • key (String)

    An attribute key.

  • default_value (String, Boolean, Integer, Float, Hash, Layout::Dictionary, nil) (defaults to: nil)

    A default value to return if no attribute is found.

Returns:

Version:

  • LayOut 2026.0

#groupLayout::Group?

The #group method returns the Group the Layout::Entity belongs to, or nil if it is not in a Group.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
pages = doc.pages
entities = pages.first.entities
group = entities.first.group

Returns:

Version:

  • LayOut 2018

#layer_instanceLayout::LayerInstance?

Note:

Groups are never associated with a LayerInstance.

The #layer_instance method returns the LayerInstance that the Layout::Entity is on, or nil if it is not associated with a LayerInstance.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities
entity_layer_instance = entities.first.layer_instance

Returns:

Version:

  • LayOut 2018

#locked=(is_locked) ⇒ Object

The #locked= method sets the Layout::Entity as locked or unlocked. When locked, the Layout::Entity cannot be modified directly.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities
entities.first.locked = true

Parameters:

  • is_locked (Boolean)

Version:

  • LayOut 2018

#locked?Boolean

The #locked? method returns whether the Layout::Entity is locked or unlocked.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities
is_first_locked = entities.first.locked?

Returns:

  • (Boolean)

Version:

  • LayOut 2018

#move_to_group(group) ⇒ Object

The #move_to_group method moves the Layout::Entity into a Group. If the Layout::Entity is already in a Group, it will be removed from that Group prior to being added to the new one. If this action results in the old Group containing only one Layout::Entity, the old Group will be collapsed and the remaining Layout::Entity will be moved to the old Group's parent.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
# We consider that there are two rectangle objects in the entities.
entities = doc.layers.first.layer_instance(doc.pages.first).entities
# We move the first rectangle to a new group.
group = Layout::Group.new([entities.first])
# We move the second rectangle to the same group.
entities[1].first.move_to_group(new_group)

Parameters:

Raises:

Version:

  • LayOut 2018

#move_to_layer(layer) ⇒ Object #move_to_layer(layer, pages) ⇒ Object

The #move_to_layer method moves the Layout::Entity to the given Layer. If the Layer is non-shared and the Layout::Entity is currently on a shared Layer, an array of Pages must be provided to move the Layout::Entity to. In all other cases, passing in an array of Pages is not necessary. The Layout::Entity must belong to the same Document as the the Layer and the Pages.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities
layers = doc.layers
entities.last.move_to_layer(layers.first)

Overloads:

Raises:

Version:

  • LayOut 2018

Known Bugs:

  • In LayOut versions prior to LayOut 2024.0 this method would fail to move entities from non-shared layers.

#on_shared_layer?Boolean

The #on_shared_layer? method returns whether or not the Layout::Entity is on a shared Layer. This function works for all Layout::Entity types, including Group. Groups do not belong to a specific Layer, but their children are all on either a shared or non-shared Layer.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities
on_shared_layer = entities.first.on_shared_layer?

Returns:

  • (Boolean)

Raises:

Version:

  • LayOut 2018

#pageLayout::Page?

The #page method returns the Page that the Layout::Entity belongs to, or nil if it is on a shared Layer or not in a Document.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
# page will be nil
page = doc.shared_entities.first.page
# page will be the first page of the document
page = doc.pages.first.nonshared_entities.first.page

Returns:

Version:

  • LayOut 2018

#set_attribute(name, key, value) ⇒ Object

The #set_attribute method adds an attribute to the entity's attribute dictionary.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entity = doc.pages.first.entities.first
entity.set_attribute("jane_doe_doc_maker", "doc_id", 42)

Parameters:

  • name (String)

    The name of an attribute dictionary. @param [String] key An attribute key. @param [String, Boolean, Integer, Float, Hash, Layout::Dictionary, nil] value The value for the

    attribute.
    

Version:

  • LayOut 2026.0

#styleLayout::Style?

The #style method returns the Style of the Layout::Entity. If the Layout::Entity is a Group, nil will be returned, as they do not have a Style.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.entities
style = entities.first.style

Returns:

Version:

  • LayOut 2018

#style=(style) ⇒ Object

The #style= method sets the Style of the Layout::Entity.

Parameters:

Raises:

Version:

  • LayOut 2018

#transform!(transformation) ⇒ Object

The #transform! method transforms the Layout::Entity with a given Geom::Transformation2d.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities
transform = Geom::Transformation2d.new([1.0, 0.0, 0.0, 1.0, 1.0, 1.0])
entity = entities.first.transform!(transform)

Parameters:

Raises:

Version:

  • LayOut 2018

#transformationGeom::Transformation2d?

The #transformation method returns the explicit Geom::Transformation2d.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities
transform = entities.first.transformation

Returns:

Version:

  • LayOut 2018

#untransformed_boundsGeom::Bounds2d

The #untransformed_bounds method returns the untransformed bounds of the Layout::Entity. This is the bounds of the Layout::Entity before its explicit Geom::Transformation2d is applied.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities
bounds = entities.first.untransformed_bounds

Returns:

Raises:

Version:

  • LayOut 2018

#untransformed_bounds=(bounds) ⇒ Object

The #untransformed_bounds= method sets the untransformed bounds of the Layout::Entity. This is the bounds of the Layout::Entity before its explicit Geom::Transformation2d is applied.

Examples:

doc = Layout::Document.open("C:/path/to/document.layout")
entities = doc.pages.first.entities
point1 = Geom::Point2d.new(1, 1)
point2 = Geom::Point2d.new(2, 2)
bounds = Geom::Bounds2d(point1, point2)
entities.first.untransformed_bounds = bounds

Parameters:

Raises:

Version:

  • LayOut 2018