ModraUp Ruby API Documentation Ruby API Reference

Class: Layout::Entity

Inherits:
Object
  • Object
show all

Overview

The base class for drawing entities. Objects created using Layout::Rectangle.new and similar methods do not belong to any document until added with Layout::Document#add_entity. Before addition, any set properties are written at the time of joining. After joining, each modification is a step in the undo history; accessing the object after deletion raises a TypeError, and undoing brings it back to a usable state.

Examples:

doc = ModraUp.active_model.layout_document
rect = Layout::Rectangle.new(Geom::Bounds2d.new(10.mm, 10.mm, 40.mm, 20.mm))
doc.add_entity(rect, doc.layers.active, doc.pages.add)
rect.bounds

Instance Method Summary # collapse

Instance Method Details

entity.bounds ⇒ Geom::Bounds2d

The bounding box after rotation, in paper inches.

Returns:

  • (Geom::Bounds2d)

Examples:

r = Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1))
r.bounds.width  #=> 2.0

entity.untransformed_bounds ⇒ Geom::Bounds2d

Unrotated bounds (x, y, width, height), paper inches.

Returns:

  • (Geom::Bounds2d)

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).untransformed_bounds

entity.untransformed_bounds = bounds

Modify position and size, with one undo step. The rules are the same as for the layout: the view preserves scale on resize (default) when Layout::SketchUpModel#preserve_scale_on_resize? is true, otherwise it scales by height only; dimensions and leaders only move and do not scale. If they extend beyond the paper edge, they are clipped back within the paper.

Parameters:

  • bounds (Geom::Bounds2d) inch on the drawing sheet

Returns:

  • (Geom::Bounds2d)

Raises:

  • [ArgumentError] Does not fit on drawing sheet
  • [Layout::LockedLayerError] Layer is locked or hidden

Examples:

doc = ModraUp.active_model.layout_document
r = Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1))
doc.add_entity(r, doc.layers.active, doc.pages.add)
r.untransformed_bounds = Geom::Bounds2d.new(2, 2, 3, 1)

entity.style ⇒ Layout::Style

A copy of the current style. Modifying the copy does not affect the object; use #style= to apply the changes.

Returns:

  • (Layout::Style)

Examples:

r = Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1))
s = r.style
s.stroke_width = 2.0
r.style = s

entity.style = style

Apply the style, undoing one step. Only apply properties relevant to the object type (e.g., text ignoring line type).

Parameters:

  • style (Layout::Style)

Returns:

  • (Layout::Style)

Raises:

  • [Layout::LockedLayerError] Layer is locked or hidden

Examples:

text = Layout::FormattedText.new("Notes", Geom::Point2d.new(1, 1), Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
s = text.style
s.font_size = 14
text.style = s

entity.page ⇒ Layout::Page, nil

The current page; objects on shared layers or those not yet added to the document are nil.

Returns:

  • (Layout::Page, nil)

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).page  #=> nil

entity.document ⇒ Layout::Document, nil

Belongs to a Layout::Entity document; is nil if not added yet.

Returns:

  • (Layout::Document, nil)

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).document  #=> nil

entity.on_shared_layer? ⇒ Boolean

Returns true if the entity is on a shared layer.

Returns:

  • (Boolean)

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).on_shared_layer?  #=> false

entity.layer_instance ⇒ Layout::LayerInstance, nil

The layer it resides on; nil if not added yet.

Returns:

  • (Layout::LayerInstance, nil)

Examples:

doc = ModraUp.active_model.layout_document
r = Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1))
doc.add_entity(r, doc.layers.active, doc.pages.add)
r.layer_instance.definition.name

entity.move_to_layer(layer, pages = nil) ⇒ Layout::Entity

Move to another layer, one undo step. Objects on a shared layer remain on their associated page when moved to a regular layer.

Parameters:

  • layer (Layout::Layer)
  • pages (Array<Layout::Page>, nil) To be compatible with LayOut, accepts but does not use.

Returns:

  • (Layout::Entity) self

Raises:

  • [Layout::LockedLayerError] Any layer is locked or hidden

Examples:

doc = ModraUp.active_model.layout_document
r = Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1))
doc.add_entity(r, doc.layers.active, doc.pages.add)
r.move_to_layer(doc.layers.add("Annotations"))

entity.rotation ⇒ Float

Rotation angle around the bounding box center (degrees).

Returns:

  • (Float)
Note: ModraUp extension. LayOut uses transformation; OpenSu does not have Geom::Transformation2d.

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).rotation  #=> 0.0

entity.rotation = degrees

Rotate around the bounding box center, one step in undo. Dimensions and leaders do not accept rotation (they follow their endpoints).

Parameters:

  • degrees (Numeric) -360~360

Returns:

  • (Numeric)

Raises:

  • [ArgumentError] Out of range or object cannot be rotated
Note: ModraUp extension.

Examples:

r = Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1))
r.rotation = 30

entity.get_attribute(dictionary, key, default = nil) ⇒ Object

Read plugin data on the object. Plugins can use this to identify objects they generate, such as re-creating automatic leader and dimension annotations.

Parameters:

  • dictionary (String)
  • key (String)
  • default (Object)

Returns:

  • (Object)

Examples:

r = Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1))
r.set_attribute("auto_dim", "source", 42)
r.get_attribute("auto_dim", "source")  #=> 42

entity.set_attribute(dictionary, key, value) ⇒ Object

Save plugin data on the object with a single undo step. Values can only be types that JSON can represent (nil, true, false, numbers, strings, Array, Hash), and a single object should not exceed 64 KB.

Parameters:

  • dictionary (String)
  • key (String)
  • value (Object)

Returns:

  • (Object) value

Raises:

  • [ArgumentError] The value cannot be serialized to JSON or exceeds 64 KB
Note: ModraUp extension. LayOut supports a wider range of value types.

Examples:

r = Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1))
r.set_attribute("auto_dim", "source", 42)

entity.delete_attribute(dictionary) ⇒ Booleanentity.delete_attribute(dictionary, key) ⇒ Boolean

Delete a key or an entire dictionary.

Parameters:

  • dictionary (String)
  • key (String)

Returns:

  • (Boolean) Did the content delete?

Examples:

r = Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1))
r.set_attribute("a", "b", 1)
r.delete_attribute("a")  #=> true

entity.attribute_dictionary(name, create = false) ⇒ Hash, nil

A copy of a dictionary.

Parameters:

  • name (String)
  • create (Boolean) Returns an empty Hash if it does not exist.

Returns:

  • (Hash, nil)
Note: ModraUp extension. LayOut returns a Layout::Dictionary; here, it returns a copy of a Hash, modifying it will not write back.

Examples:

r = Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1))
r.set_attribute("a", "b", 1)
r.attribute_dictionary("a")  #=> {"b"=>1}

entity.locked? ⇒ raises

Unsupported: OpenSu does not support object-level locking (please lock the layer).

Raises:

  • [NotImplementedError]
Note: ModraUp extension. Unlike LayOut.

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).locked? rescue puts $!.message

entity.locked = locked ⇒ raises

Unsupported: OpenSu does not support object-level locking (please lock the layer).

Parameters:

  • locked (Boolean)

Raises:

  • [NotImplementedError]
Note: ModraUp extension. Unlike LayOut.

Examples:

begin
  Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).locked = true
rescue NotImplementedError => error
  puts error.message
end

entity.transform!(transformation) ⇒ raises

Unsupported: OpenSu does not support Geom::Transformation2d. For translation, use #untransformed_bounds=, and for rotation, use #rotation=.

Raises:

  • [NotImplementedError]
Note: ModraUp extension. Unlike LayOut.

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).transform!(nil) rescue puts $!.message

entity.group ⇒ raises

Does not support: OpenSu drawings cannot be grouped.

Raises:

  • [NotImplementedError]
Note: ModraUp extension. Unlike LayOut.

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).group rescue puts $!.message

entity == other ⇒ Boolean

Returns whether the two references identify the same drawing entity.

Parameters:

  • other (Object)

Returns:

  • (Boolean)

Examples:

doc = ModraUp.active_model.layout_document
page = doc.pages.add
doc.add_entity(Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)), doc.layers.active, page)
page.entities[0] == page.entities[0]  #=> true

entity.eql?(other) ⇒ Boolean

Like #==, used as a key in a Hash.

Parameters:

  • other (Object)

Returns:

  • (Boolean)

Examples:

r = Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1))
r.eql?(r)  #=> true

entity.hash ⇒ Integer

Hash value consistent with #eql?.

Returns:

  • (Integer)

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).hash

entity.inspect ⇒ String

A brief description.

Returns:

  • (String)

Examples:

Layout::Rectangle.new(Geom::Bounds2d.new(1, 1, 2, 1)).inspect