ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::Group

Overview

Group instances.

Examples:

g = ModraUp.active_model.entities.add_group
g.guid

Instance Method Summary # collapse

Inherited from ModraUp::Drawingelement

Inherited from ModraUp::Entity

  • #typename ⇒ String
    Type name (e.g., Face / Edge / Group).
  • #entityID ⇒ Integer
    Entity ID within the current session: A small integer starting from 1 that increments and remains constant for the lifetime of the entity, unchanged by undo/redo operations. This ID is not preserved when saving the file; it will be renumbered upon reopening the model. For cross-session identification, use #persistent_id. Copied entities will receive new IDs.
  • #persistent_id ⇒ Integer
    Number assigned with the model: A unique, incrementing small integer starting from 1 that persists across model saves and reloads, independent of #entityID. Copied entities receive new numbers, and deleted entities do not reuse their numbers. Edges, faces, vertices, curves, groups, component instances/definitions, dimensions, leader lines/points, section planes, materials, layers, layer folders, and drawing sheets have assigned numbers; all others (rings, EdgeUses, attribute dictionaries, line types, sets, etc.) return 0.
  • #parent ⇒ ModraUp::Model, ModraUp::ComponentDefinition
    Returns the owner of this drawing context. At the root this is the model. Inside a definition it is the definition itself.
  • #model ⇒ ModraUp::Model
    The model it belongs to.
  • #to_s ⇒ String
    String form. Returns "#<Deleted Entity>” when the entity has been deleted.
  • #inspect ⇒ String
    Same as #to_s.
  • #attribute_dictionaries ⇒ ModraUp::AttributeDictionaries, nil
    Collection of attribute dictionaries. Returns nil (evaluates to false) if there are no dictionaries.
  • #attribute_dictionary(name) ⇒ ModraUp::AttributeDictionary, nil
    Retrieve an attribute dictionary by name. If none exists, return nil; if create is true, create an empty dictionary. ModraUp::Loop / ModraUp::EdgeUse / ModraUp::Curve always return nil.
  • #valid? ⇒ Boolean
    Returns true if the entity is valid, meaning it has not been deleted from the model. Revoked entities are false; even if new geometry is drawn occupying its original position, this object remains an invalid entity (still false). Repeating the action to restore it makes it valid again.
  • #deleted? ⇒ Boolean
    Opposite of #valid?.
  • #set_attribute(dict_name, key, value) ⇒ Object
    Write attribute values. Materials, groups, component instances, faces, and edges are supported. When dict_name and key are Symbols, they are converted to strings. The type of data written is the same type that will be read back.
  • #get_attribute(dict_name, key, default = nil) ⇒ Object
    Read the attribute. If dict_name and key are Symbols, convert them to strings (similar to SketchUp). If the dictionary or key does not exist, return default. The return value type is the same as what is written by #set_attribute.
  • #delete_attribute(dict_name) ⇒ Boolean
    Delete a key, or delete the entire dictionary when the key is omitted.

Instance Method Details

group.definition ⇒ ModraUp::ComponentDefinition

The definition corresponding to the group.

Returns:

  • (ModraUp::ComponentDefinition)

Examples:

# Groups also expose their definition
ModraUp.active_model.definitions

group.name ⇒ String

Group name. An empty string if unnamed.

Returns:

  • (String)

Examples:

ModraUp.active_model.selection

group.name=(name) ⇒ String

Set the name of the group.

Parameters:

  • name (String)

Returns:

  • (String)

Examples:

ModraUp.active_model.selection

group.entities ⇒ ModraUp::Entities

Returns the group's drawing context. Editing geometry here first calls #make_unique, so other copies retain the shared definition. Editing through ModraUp::ComponentDefinition#entities changes all instances of that definition.

Returns:

  • (ModraUp::Entities)

Examples:

ents = ModraUp.active_model.entities
g1 = ents.add_group
g2 = ents.add_instance(g1.definition, IDENTITY)
g1.entities.add_line([0, 0, 0], [1, 0, 0])
g1.definition == g2.definition  #=> false

group.transformation ⇒ Geom::Transformation

Transformation of a group within its parent drawing context.

Returns:

  • (Geom::Transformation)

Examples:

ModraUp.active_model.selection

group.transformation=(transformation) ⇒ Geom::Transformation

Sets the transformation of the group within its parent drawing context.

Parameters:

  • transformation (Geom::Transformation)

Returns:

  • (Geom::Transformation)

Examples:

ModraUp.active_model.selection

group.transform!(transformation) ⇒ self

Apply the transformation by left multiplication.

Parameters:

  • transformation (Geom::Transformation)

Returns:

  • (ModraUp::Group)

Examples:

ModraUp.active_model.selection

group.explode ⇒ Array<ModraUp::Entity>, false

Explodes the group into its parent drawing context. The parent can be an unclosed group or a definition. Returns false on failure.

Returns:

  • (Array<ModraUp::Entity>, false)

Examples:

defn = ModraUp.active_model.definitions.add("Box")
inst = ModraUp.active_model.entities.add_instance(defn)
inst.explode

group.make_unique ⇒ ModraUp::Group

If any other group shares the same definition, make a unique copy of the definition and point only this group to it. If it is already unique, perform no operation.

Returns:

  • (ModraUp::Group)

Raises:

  • [RuntimeError] The group has been deleted.

Examples:

ents = ModraUp.active_model.entities
g1 = ents.add_group
g2 = ents.add_instance(g1.definition, IDENTITY)
g1.make_unique
g1.definition == g2.definition  #=> false

group.to_component ⇒ ModraUp::ComponentInstance

Convert this group into a component instance. Other copies sharing the definition remain groups. The group object is then #deleted?. The parent context does not need to be the active drawing context (groups or definitions not in use can be converted, consistent with SketchUp).

Returns:

  • (ModraUp::ComponentInstance, nil)

Raises:

  • [RuntimeError] The group has been deleted.

Examples:

g = ModraUp.active_model.entities.add_group
g.entities.add_line([0, 0, 0], [1, 0, 0])
inst = g.to_component
inst.is_a?(ModraUp::ComponentInstance)  #=> true
inst.definition.group?  #=> false

Convert inside an outer group that is closed for editing

outer = ModraUp.active_model.entities.add_group
inner = outer.entities.add_group
inner.to_component.is_a?(ModraUp::ComponentInstance)  #=> true

group.copy ⇒ ModraUp::Group

Copy this group within the same parent context. The new group has its own definition with identical geometry and instance properties as the source group.

Returns:

  • (ModraUp::Group)

Raises:

  • [RuntimeError] The group has been deleted.

Examples:

g = ModraUp.active_model.entities.add_group
g.entities.add_line([0, 0, 0], [1, 0, 0])
g2 = g.copy
g2.is_a?(ModraUp::Group)  #=> true
g.definition == g2.definition  #=> false

group.scaled_size ⇒ Array<Numeric>

Apply the scaled group definition bounding box size.

Returns:

  • (Array<Numeric>)

Examples:

ModraUp.active_model.selection

group.local_bounds ⇒ Geom::BoundingBox

Define the group's local bounding box without including the group's transform.

Returns:

  • (Geom::BoundingBox)

Examples:

ModraUp.active_model.definitions

group.add_observer(observer) ⇒ Boolean

Register a ModraUp::InstanceObserver. Adding the same object a second time returns false.

Parameters:

  • observer (ModraUp::InstanceObserver)

Returns:

  • (Boolean)

Examples:

ModraUp::InstanceObserver.new

group.remove_observer(observer) ⇒ Boolean

Remove the previously registered instance observer.

Parameters:

  • observer (ModraUp::InstanceObserver)

Returns:

  • (Boolean)

Examples:

obs = ModraUp::InstanceObserver.new
obs

group.description ⇒ String

Description of the group definition.

Returns:

  • (String)

Examples:

ModraUp.active_model.selection

group.description=(text) ⇒ String

Set the description text for the group definition (same as ModraUp::ComponentDefinition#description=).

Parameters:

  • text (String)

Returns:

  • (String)

Examples:

g = ModraUp.active_model.entities.add_group
g.description = "crate"
g.description  #=> "crate"

group.guid ⇒ String

Base64 unique ID for the group placement. Will be an empty string if not imported.

Returns:

  • (String)

Examples:

ModraUp.active_model.entities.add_group.guid.is_a?(String)  #=> true

group.manifold? ⇒ Boolean

Returns:

  • (Boolean)

Examples:

g = ModraUp.active_model.entities.add_group
g.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]).pushpull(1)
g.manifold?  #=> true

group.volume ⇒ Float

Returns the volume in cubic inches. The value is positive for a manifold solid and negative for non-manifold geometry.

Returns:

  • (Float)

Examples:

g = ModraUp.active_model.entities.add_group
g.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
g.volume > 0  #=> true

group.move!(transformation) ⇒ ModraUp::Group, nil

Set the transformation without recording it in the undo stack.

Parameters:

  • transformation (Geom::Transformation)

Returns:

  • (ModraUp::Group, nil)

Examples:

g = ModraUp.active_model.entities.add_group
g.move!(Geom::Transformation.translation(1, 0, 0)).equal?(g)  #=> true

group.subtract(other) ⇒ ModraUp::Group, nil

Subtract this group from other (result is other - this group). The result is a new group in the parent context (geometry baked into the parent space, transformed to the identity matrix). Both must be manifold shells in the same parent ModraUp::Entities. On success, both are deleted. Returns nil if either is not a manifold shell, the result is empty, one is locked, deleted, or not in the same parent context, with no model change.

Parameters:

  • other (ModraUp::Group, ModraUp::ComponentInstance)

Returns:

  • (ModraUp::Group, nil)

Raises:

  • [TypeError] other is not a group or component instance

Examples:

ents = ModraUp.active_model.entities
a = ents.add_group
a.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
b = ents.add_group
b.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
b.move!(Geom::Transformation.translation(5, 0, 0))
a.subtract(b).is_a?(ModraUp::Group)  #=> true

group.trim(other) ⇒ ModraUp::Group, nil

Cut the other group with this group. The group remains unchanged; other is replaced by other minus this group, with the result returned as a new group in the same parent context. Failure conditions are the same as for #subtract, returning nil without modifying the model.

Parameters:

  • other (ModraUp::Group, ModraUp::ComponentInstance)

Returns:

  • (ModraUp::Group, nil)

Raises:

  • [TypeError] other is not a group or component instance

Examples:

ents = ModraUp.active_model.entities
cutter = ents.add_group
cutter.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
target = ents.add_group
target.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
target.move!(Geom::Transformation.translation(5, 0, 0))
cutter.trim(target).is_a?(ModraUp::Group)  #=> true

group.union(other) ⇒ ModraUp::Group, nil

The union of this group with other, resulting in a new group in the parent context. Both sides are deleted upon success. Failure conditions are the same as for ##subtract.

Parameters:

  • other (ModraUp::Group, ModraUp::ComponentInstance)

Returns:

  • (ModraUp::Group, nil)

Raises:

  • [TypeError] other is not a group or component instance

Examples:

ents = ModraUp.active_model.entities
a = ents.add_group
a.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
b = ents.add_group
b.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
b.move!(Geom::Transformation.translation(5, 0, 0))
a.union(b).is_a?(ModraUp::Group)  #=> true

group.intersect(other) ⇒ ModraUp::Group, nil

The intersection volume between this group and other. The result is a new group in the parent context (geometry baked into the parent space). Both entities must be manifold shells in the same parent ModraUp::Entities. If successful, both entities are deleted. If they do not intersect, are non-manifold, locked, deleted, or not in the same parent context, it returns nil, with the model unchanged.

Parameters:

  • other (ModraUp::Group, ModraUp::ComponentInstance)

Returns:

  • (ModraUp::Group, nil)

Raises:

  • [TypeError] other is not a group or component instance

Examples:

ents = ModraUp.active_model.entities
a = ents.add_group
a.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
b = ents.add_group
b.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
b.move!(Geom::Transformation.translation(5, 0, 0))
a.intersect(b).is_a?(ModraUp::Group)  #=> true

group.outer_shell(other) ⇒ ModraUp::Group, nil

The outer surface of two manifold shells (volume union, internal faces removed). The result is a new group in the parent context. Both are deleted if successful. Solids do not need to intersect: if they are completely separate, both shells remain in the resulting group; if one completely encloses the other, only the outer shell remains. Failure conditions are the same as for #intersect.

Parameters:

  • other (ModraUp::Group, ModraUp::ComponentInstance)

Returns:

  • (ModraUp::Group, nil)

Raises:

  • [TypeError] other is not a group or component instance

Examples:

ents = ModraUp.active_model.entities
a = ents.add_group
a.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
b = ents.add_group
b.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
b.move!(Geom::Transformation.translation(30, 0, 0))
a.outer_shell(b).is_a?(ModraUp::Group)  #=> true

group.split(other) ⇒ Array(ModraUp::Group, ModraUp::Group, ModraUp::Group), nil

Splits two manifold solids at their intersection. Returns three new groups on Layer0 in this order: the part of other outside the receiver (Difference2), the part of the receiver outside other (Difference1), and their shared volume (Intersection). The operation removes the original objects. If the volumes do not overlap, the intersection group is empty and the difference groups contain the original solids. For a non-manifold input or a failed operation, returns nil and leaves the model unchanged.

Parameters:

  • other (ModraUp::Group, ModraUp::ComponentInstance)

Returns:

  • (Array(ModraUp::Group, ModraUp::Group, ModraUp::Group), nil)

Raises:

  • [TypeError] other is not a group or component instance

Examples:

ents = ModraUp.active_model.entities
a = ents.add_group
a.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
b = ents.add_group
b.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
b.move!(Geom::Transformation.translation(5, 0, 0))
diff2, diff1, inter = a.split(b)
inter.name  #=> "Intersection"

group.show_differences(other) ⇒ Booleangroup.show_differences(other, verbose) ⇒ Boolean

Compares the volumes of two manifold solids in their shared parent space. Returns true for equal volumes in the same location, otherwise false. Both containers move to Layer0. Coincident faces and edges go on a layer ending in _same and remaining geometry on a layer ending in _diff. The prefix is the group instance name (or its definition name if empty), or the component definition name. With verbose enabled, the console lists the centers of differing faces. A non-manifold, locked, deleted, or differently parented input returns false without changing the model. Shared definitions are made unique first, preserving other instances.

Parameters:

  • other (ModraUp::Group, ModraUp::ComponentInstance)
  • verbose (Boolean) Does printing the differences to the console default to false?

Returns:

  • (Boolean)

Raises:

  • [TypeError] other is not a group or component instance
Note: ModraUp extension. Shared definitions will be uniquified to avoid affecting other instances.

Examples:

ents = ModraUp.active_model.entities
a = ents.add_group
a.name = "Left"
a.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
b = ents.add_group
b.name = "Right"
b.entities.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]).pushpull(10)
a.show_differences(b, false)  #=> true

#hatch_pattern ⇒ ModraUp::HatchPattern, nil

Read the hatch pattern of this group/component itself. It also applies to nested groups and components, taking precedence over material patterns.

Returns:

  • (ModraUp::HatchPattern, nil)

Examples:

group = ModraUp.active_model.entities.grep(ModraUp::Group).first
group.hatch_pattern if group

#hatch_pattern=(hatch_pattern) ⇒ ModraUp::HatchPattern, nil

Sets the hatch pattern for this group/component itself, no material assignment needed; nil removes the pattern.

Parameters:

  • hatch_pattern (ModraUp::HatchPattern, nil) The hatch pattern of this model.

Returns:

  • (ModraUp::HatchPattern, nil)

Raises:

  • [ArgumentError] The hatch pattern belongs to another model.

Examples:

model = ModraUp.active_model
group = model.entities.grep(ModraUp::Group).first
group.hatch_pattern = model.hatch_patterns.first if group