ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::Entities

Inherits:
Object
  • Object
show all
Includes:
Enumerable

Overview

The edges, faces, groups, component instances, linear dimensions, construction points, and construction lines in a drawing context. Obtain this collection from ModraUp::Model#entities, ModraUp::Model#active_entities, or ModraUp::ComponentDefinition#entities.

Examples:

ents = ModraUp.active_model.entities
ents.add_face([0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0])

Instance Method Summary # collapse

Instance Method Details

entities.add_face(point, point, point, ...) ⇒ ModraUp::Faceentities.add_face(array_of_points) ⇒ ModraUp::Faceentities.add_face(edge, edge, edge, ...) ⇒ ModraUp::Faceentities.add_face(array_of_edges) ⇒ ModraUp::Faceentities.add_face(curve) ⇒ ModraUp::Face

Create a face from at least three points, or a set of closed coplanar edges / a closed ModraUp::Curve. The edges must form a ring; otherwise, it returns nil. If creation fails, it also returns nil.

Parameters:

  • entities (Geom::Point3d, Array<Numeric>, ModraUp::Edge, Array<ModraUp::Edge>, ModraUp::Curve)

Returns:

  • (ModraUp::Face, nil)

Raises:

  • [ArgumentError] Not enough points
  • [TypeError] The edge list contains non-ModraUp::Edge objects.

Examples:

Point

face = ModraUp.active_model.entities.add_face(
  [0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0])

An existing edge

ents = ModraUp.active_model.entities.add_group.entities
ents.add_line([0, 0, 0], [1, 0, 0])
ents.add_line([1, 0, 0], [1, 1, 0])
ents.add_line([1, 1, 0], [0, 1, 0])
ents.add_line([0, 1, 0], [0, 0, 0])
face = ents.add_face(ents.grep(ModraUp::Edge))

entities.add_line(start_pt, end_pt) ⇒ ModraUp::Edgeentities.add_line([start_pt, end_pt]) ⇒ ModraUp::Edge

Add an edge between two points and split any existing coplanar faces. Airborne wireframes must call ModraUp::Edge#find_faces to form faces.

Parameters:

  • start_pt (Geom::Point3d, Array<Numeric>)
  • end_pt (Geom::Point3d, Array<Numeric>)

Returns:

  • (ModraUp::Edge, nil)

Examples:

ModraUp.active_model.entities.add_line([0, 0, 0], [1, 0, 0])

entities.add_dimension_linear(start_pt_or_entity, end_pt_or_entity, offset_vector) ⇒ ModraUp::DimensionLinear

Add a linear dimension. The offset_vector is the parallel offset from the start point to the dimension line.

Parameters:

  • start_pt_or_entity (Geom::Point3d, ModraUp::Vertex, Array<Numeric>)
  • end_pt_or_entity (Geom::Point3d, ModraUp::Vertex, Array<Numeric>)
  • offset_vector (Geom::Vector3d, Array<Numeric>)

Returns:

  • (ModraUp::DimensionLinear, nil)

Examples:

dim = ModraUp.active_model.entities.add_dimension_linear(
  [0, 0, 0], [10, 0, 0], [0, 0, 5])
dim.is_a?(ModraUp::DimensionLinear)

entities.add_text(text, point, vector = nil) ⇒ ModraUp::Text

Add an annotation text. The point is a 3D annotation point (can also be a Vertex or InputPoint), and the vector is the 3D offset from the annotation point to the text; if omitted, the text is placed directly on the point with no leader. The text always faces the screen.

Parameters:

  • text (String)
  • point (Geom::Point3d, ModraUp::Vertex, ModraUp::InputPoint, Array<Numeric>)
  • vector (Geom::Vector3d, Array<Numeric>, nil)

Returns:

  • (ModraUp::Text, nil)

Examples:

txt = ModraUp.active_model.entities.add_text("Top panel", [0, 0, 10], [20, 0, 20])
txt.has_leader?  #=> true

entities.add_cpoint(point) ⇒ ModraUp::ConstructionPoint

Add an auxiliary point. Not a vertex, does not weld or create an edge.

Parameters:

  • point (Geom::Point3d, Array<Numeric>)

Returns:

  • (ModraUp::ConstructionPoint)

Examples:

pt = ModraUp.active_model.entities.add_cpoint([0, 0, 1])
pt.is_a?(ModraUp::ConstructionPoint)
ModraUp.active_model.entities.grep(ModraUp::ConstructionPoint).include?(pt)

entities.add_cline(start_point, end_point) ⇒ ModraUp::ConstructionLineentities.add_cline(point, vector) ⇒ ModraUp::ConstructionLine

Add a helper line. Two points define a finite line segment; a point {Geom::Vector3d} defines an infinite line. Repeated points or zero vector return nil.

Parameters:

  • start_point (Geom::Point3d, Array<Numeric>)
  • end_point (Geom::Point3d, Geom::Vector3d, Array<Numeric>)

Returns:

  • (ModraUp::ConstructionLine, nil)

Examples:

Limited

ModraUp.active_model.entities.add_cline([0, 0, 0], [10, 0, 0]).end.to_a
#=> [10.0, 0.0, 0.0]

No limit

line = ModraUp.active_model.entities.add_cline([0, 0, 2], Geom::Vector3d.new(0, 1, 0))
line.start.nil? && line.end.nil?

entities.add_3d_text(string, alignment, font, is_bold = false, is_italic = false,letter_height = 1.0, tolerance = 0.0, z = 0.0, is_filled = true,extrusion = 0.0) ⇒ Boolean

Generates 3D text geometry on the XY plane (similar to the "Tools ▸ 3D Text" command). The alignment parameter is for TextAlignLeft, TextAlignCenter, or TextAlignRight, which only determines the line alignment; the text block origin always remains at the lower left corner. The letter_height parameter specifies the height of capital letters. When is_filled is false, only the outline is generated; when extrusion is non-zero, it extrudes into a solid (only if filled). Returns true on success.

Examples:

ModraUp.active_model.entities.add_3d_text("OpenSu", TextAlignLeft, "Arial",
  false, false, 10.inch, 0.0, 0.0, true, 1.inch)  #=> true

entities.add_circle(center, normal, radius) ⇒ Array<ModraUp::Edge>entities.add_circle(center, normal, radius, numsegs) ⇒ Array<ModraUp::Edge>

Add a circle on a plane (create a closed ModraUp::ArcCurve and add a face).

Parameters:

  • center (Geom::Point3d, Array<Numeric>)
  • normal (Geom::Vector3d, Array<Numeric>)
  • radius (Numeric, Length)
  • numsegs (Integer) Segments, default 24; value range is 3..999

Returns:

  • (Array<ModraUp::Edge>, nil)

Examples:

edges = ModraUp.active_model.entities.add_circle([0, 0, 0], [0, 0, 1], 5, 12)
edges[0].curve.num_segments  #=> 12

entities.add_edges(point, point, ...) ⇒ Array<ModraUp::Edge>entities.add_edges(array_of_points) ⇒ Array<ModraUp::Edge>

Add edges from a list of line points, joining existing boundaries and splitting coplanar faces, returning the complete edge chain split at intersections. Airborne wireframes must call ModraUp::Edge#find_faces to form faces.

Parameters:

  • point (Geom::Point3d, Array<Numeric>)

Returns:

  • (Array<ModraUp::Edge>)

Raises:

  • [ArgumentError] Not enough points

Examples:

ModraUp.active_model.entities.add_edges([0, 0, 0], [1, 0, 0], [1, 1, 0])

entities.add_arc(center, xaxis, normal, radius, start_angle, end_angle) ⇒ Array<ModraUp::Edge>entities.add_arc(center, xaxis, normal, radius, start_angle, end_angle, num_segments) ⇒ Array<ModraUp::Edge>

Add an open arc (ModraUp::ArcCurve), splitting edges and faces when it intersects with existing coplanar geometry. An isolated open arc does not close to form a face. Angles are specified in radians, rotating from the xaxis around the normal.

Parameters:

  • center (Geom::Point3d, Array<Numeric>)
  • xaxis (Geom::Vector3d, Array<Numeric>)
  • normal (Geom::Vector3d, Array<Numeric>)
  • radius (Numeric, Length)
  • start_angle (Numeric) radians
  • end_angle (Numeric) radians
  • num_segments (Integer) The number of sides, default is 24; value range is 2..999.

Returns:

  • (Array<ModraUp::Edge>, nil)

Examples:

ModraUp.active_model.entities.add_arc(
  [0, 0, 0], [1, 0, 0], [0, 0, 1], 5, 0, Math::PI, 8)

entities.add_ngon(center, normal, radius, numsides) ⇒ Array<ModraUp::Edge>

Add a regular polygon, where the is_polygon? method returns true.

Parameters:

  • center (Geom::Point3d, Array<Numeric>)
  • normal (Geom::Vector3d, Array<Numeric>)
  • radius (Numeric, Length)
  • numsides (Integer) The value must be in the range 3..999.

Returns:

  • (Array<ModraUp::Edge>, nil)

Examples:

ModraUp.active_model.entities.add_ngon([0, 0, 0], [0, 0, 1], 3, 6)

entities.add_curve(point, point, ...) ⇒ Array<ModraUp::Edge>entities.add_curve(array_of_points) ⇒ Array<ModraUp::Edge>

Create a ModraUp::Curve by adding a polyline from a list of points and weld it together.

Parameters:

  • point (Geom::Point3d, Array<Numeric>)

Returns:

  • (Array<ModraUp::Edge>)

Raises:

  • [ArgumentError] Not enough points

Examples:

edges = ModraUp.active_model.entities.add_curve([0, 0, 0], [1, 0, 0], [2, 0, 0])
edges[0].curve.is_a?(ModraUp::Curve)

entities.add_group ⇒ ModraUp::Groupentities.add_group(*entities) ⇒ ModraUp::Groupentities.add_group { |group| ... } ⇒ ModraUp::Group

Create an empty group, or add the entities in this context to a group. If a block is provided, pass the group to the block.

Parameters:

  • entities (ModraUp::Drawingelement)

Returns:

  • (ModraUp::Group)

Yields:

  • @yieldparam group [ModraUp::Group]

Examples:

ents = ModraUp.active_model.entities
g = ents.add_group
g.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0])

entities.add_instance(definition) ⇒ ModraUp::ComponentInstanceentities.add_instance(definition, transform) ⇒ ModraUp::ComponentInstance, ModraUp::Group

Place a component instance in the current drawing context. Omitting transform uses the unit transformation. A group definition returns a ModraUp::Group.

Parameters:

  • definition (ModraUp::ComponentDefinition)
  • transform (Geom::Transformation)

Returns:

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

Examples:

defn = ModraUp.active_model.definitions.add("Box")
xf = Geom::Transformation.translation(10, 0, 0)
ModraUp.active_model.entities.add_instance(defn, xf)

entities.add_faces_from_mesh(mesh) ⇒ Integerentities.add_faces_from_mesh(mesh, smooth_flags, front_material = nil, back_material = nil) ⇒ Integer

Add faces from a Geom::PolygonMesh as polygons. Returns the number of faces successfully added.

In the absence of context, this operation follows a batch path: only weld vertices and share edges, with a time complexity of O(n log n); when entities are present, each polygon is processed by #add_face (which may subdivide and embed existing geometry).

The default smooth_flags are AUTO_SOFTEN | SMOOTH_SOFT_EDGES: soften and smooth edges between nearly coplanar adjacent faces (within a 20° angle); HIDE_BASED_ON_INDEX / SOFTEN_BASED_ON_INDEX hide / soften edges starting from a point based on negative indices. Wavy polygons are split into triangles. Grid UVs are not currently used.

Parameters:

  • mesh (Geom::PolygonMesh)
  • smooth_flags (Integer)
  • front_material (ModraUp::Material, String, nil)
  • back_material (ModraUp::Material, String, nil)

Returns:

  • (Integer)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_polygon([0, 0, 0], [2, 0, 0], [1, 1, 0])
ModraUp.active_model.entities.add_faces_from_mesh(mesh)

entities.fill_from_mesh(mesh) ⇒ Booleanentities.fill_from_mesh(mesh, weld_vertices, smooth_flags, front_material = nil, back_material = nil) ⇒ Boolean

Fills the context with faces from a mesh only if it is empty (batch path). Returns false if there are existing entities. Vertices are always welded, and other parameters are the same as #add_faces_from_mesh.

Parameters:

  • mesh (Geom::PolygonMesh)
  • weld_vertices (Boolean)
  • smooth_flags (Integer)
  • front_material (ModraUp::Material, String, nil)
  • back_material (ModraUp::Material, String, nil)

Returns:

  • (Boolean)

Examples:

g = ModraUp.active_model.entities.add_group
mesh = Geom::PolygonMesh.new
mesh.add_polygon([0, 0, 0], [1, 0, 0], [0, 1, 0])
g.entities.fill_from_mesh(mesh)

entities.add_observer(observer) ⇒ Boolean

Register a ModraUp::EntitiesObserver. Adding the same object a second time will return false. #add_face / #add_line / #add_instance etc. will dispatch an onElementAdded event.

Parameters:

  • observer (ModraUp::EntitiesObserver)

Returns:

  • (Boolean)

Examples:

class MyEnts < ModraUp::EntitiesObserver
  def onElementAdded(entities, entity)
    entity.typename
  end
end
ModraUp.active_model.entities.add_observer(MyEnts.new)

entities.remove_observer(observer) ⇒ Boolean

Remove the observer from the entity collection.

Parameters:

  • observer (ModraUp::EntitiesObserver)

Returns:

  • (Boolean)

Examples:

ents = ModraUp.active_model.entities
obs = ModraUp::EntitiesObserver.new
ents.add_observer(obs)
ents.remove_observer(obs)

entities.transform_entities(transformation, *entities) ⇒ Booleanentities.transform_entities(transformation, array) ⇒ Booleanentities.transform_entities(transformation, selection) ⇒ Boolean

Transforms vertices, faces, edges, groups, or component instances. Accepts a Selection and returns false for an empty collection. The host snapshots the selection and validates all targets before applying the transformation. Each distinct target is transformed once, in its owning collection. Targets may belong to different collections in the same model. Targets in the active editing context or its ancestors use world coordinates. Other targets use local coordinates. Moving a group or component instance alone leaves its internal geometry and shared definition intact.

Parameters:

  • transformation (Geom::Transformation)
  • entities (ModraUp::Entity, Array<ModraUp::Entity>, ModraUp::Selection)

Returns:

  • (Boolean)

Examples:

ents = ModraUp.active_model.entities
edge = ents.add_line([0, 0, 0], [1, 0, 0])
ents.transform_entities(Geom::Transformation.translation(0, 0, 1), edge)

entities.intersect_with(recurse, transform1, entities1, transform2, hidden, entities2) ⇒ Array<ModraUp::Edge>

Intersect the geometry with the faces in the receiver's entities and add the resulting edges to entities1. Apply transform1 to transform the receiver to the common intersection coordinate system; apply transform2 to transform the output context to this coordinate system. Write the edges using the inverse transform of transform2. If recurse is true, enter nested groups/components. Faces from the same instance and with the same transform will not intersect with themselves or duplicate their existing common boundaries; the source and cutting sets can overlap, and intersections are calculated even between different instances or transforms.

Parameters:

  • recurse (Boolean)
  • transform1 (Geom::Transformation)
  • entities1 (ModraUp::Entities) Output context
  • transform2 (Geom::Transformation)
  • hidden (Boolean) Does the receiver geometry include hidden entities?
  • entities2 (ModraUp::Entity, Array<ModraUp::Entity>) section plane, group, or instance

Returns:

  • (Array<ModraUp::Edge>) New generated intersection lines (excluding edges that were only split)

Examples:

Intersect a horizontal face with a vertical cutting plane

m = ModraUp.active_model
id = Geom::Transformation.new
host = m.entities.add_group
host.entities.add_face [0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]
cutter = m.entities.add_group
cutter.entities.add_face [5, -5, -5], [5, 15, -5], [5, 15, 5], [5, -5, 5]
host.entities.intersect_with false, id, host.entities, id, true, cutter

entities.transform_by_vectors(entities, vectors) ⇒ self

Applies corresponding translation vectors to each vertex or entity simultaneously. The two arrays must be of equal length.

Parameters:

  • entities (Array<ModraUp::Entity>)
  • vectors (Array<Geom::Vector3d, Array<Numeric>>)

Returns:

  • (ModraUp::Entities)

Raises:

  • [ArgumentError] Lengths do not match

Examples:

ents = ModraUp.active_model.entities
e = ents.add_line([0, 0, 0], [1, 0, 0])
ents.transform_by_vectors([e], [[0, 0, 2]])

entities.erase_entities(*entities) ⇒ nilentities.erase_entities(array) ⇒ nilentities.erase_entities(selection) ⇒ nil

Removes drawing elements from their owning collections within the same model, including entities inside nested groups and definitions. The host validates the entire batch before removing anything. Removals across collections form one undo step.

Parameters:

  • entities (ModraUp::Drawingelement, Array<ModraUp::Drawingelement>, ModraUp::Selection)

Returns:

  • (nil)

Raises:

  • [ArgumentError] The target comes from another model, or references a definition used by the current edit path.

Examples:

ents = ModraUp.active_model.entities
edge = ents.add_line([0, 0, 0], [1, 0, 0])
ents.erase_entities(edge)
edge.deleted?  #=> true

Unopened group

panel = ModraUp.active_model.entities.add_group
hole = panel.entities.add_group
ModraUp.active_model.entities.erase_entities(hole)
hole.deleted?  #=> true

entities.each {|entity| } ⇒ selfentities.each ⇒ Enumerator

Iterates over live faces, edges, groups, component instances, linear dimensions, construction points, and construction lines. each, grep, and to_a return the model's live entities. Enumerating the same entity twice returns objects for which equal? is true. Changing their properties or calling erase! modifies the model.

Returns:

  • (self, Enumerator)

Yields:

  • @yieldparam entity [ModraUp::Face, ModraUp::Edge, ModraUp::Group, ModraUp::ComponentInstance, ModraUp::DimensionLinear, ModraUp::ConstructionPoint, ModraUp::ConstructionLine]

Examples:

ents = ModraUp.active_model.entities
edge = ents.add_line([0, 0, 0], [1, 0, 0])
edge.equal?(ents.grep(ModraUp::Edge)[0])  #=> true
edge.equal?(ents.to_a.grep(ModraUp::Edge)[0])  #=> true

entities.grep(klass) ⇒ Arrayentities.grep(klass) {|e| ... } ⇒ Array

Fast path: when klass is a known entity class (Face, Edge, Group, ComponentInstance, …), iterates only that type's slot array, skipping Ruby object allocation for all other entity types. Falls back to Enumerable#grep for non-class patterns.

Parameters:

  • klass [Class] entity class to match

Returns:

  • (Array)

Examples:

faces = ents.grep(ModraUp::Face)

entities.length ⇒ Integer

Number of undeleted elements (faces + edges + groups + component instances).

Returns:

  • (Integer)

Examples:

ModraUp.active_model.entities.add_line([0, 0, 0], [1, 0, 0])
ModraUp.active_model.entities.length

entities.size ⇒ Integer

Alias for #length.

Returns:

  • (Integer)

Examples:

ModraUp.active_model.entities.size

entities[index] ⇒ Entity, nil

Access elements by index, with the order matching that of #each. Out-of-bounds access returns nil.

Parameters:

  • index (Integer)

Returns:

  • (ModraUp::Face, ModraUp::Edge, ModraUp::Group, ModraUp::ComponentInstance, nil)

Examples:

ents = ModraUp.active_model.entities
ents.add_line([0, 0, 0], [1, 0, 0])
ents[0].typename  #=> "Edge"

entities.at(index) ⇒ Entity, nil

Alias for #[].

Parameters:

  • index (Integer)

Returns:

  • (ModraUp::Face, ModraUp::Edge, ModraUp::Group, ModraUp::ComponentInstance, nil)

Examples:

ModraUp.active_model.entities.at(0)

entities.parent ⇒ ModraUp::Model, ModraUp::ComponentDefinition

The owner of this drawing context: root is ModraUp::Model, otherwise it is the ModraUp::ComponentDefinition containing it.

Returns:

  • (ModraUp::Model, ModraUp::ComponentDefinition)

Examples:

ModraUp.active_model.entities.parent == ModraUp.active_model

entities.model ⇒ ModraUp::Model

The model it belongs to.

Returns:

  • (ModraUp::Model)

Examples:

ModraUp.active_model.entities.model.equal?(ModraUp.active_model)

entities.clear! ⇒ true

Clear the edges, faces, groups, instances, and dimensions in the current context.

Returns:

  • (true)

Examples:

ents = ModraUp.active_model.entities.add_group.entities
ents.add_line([0, 0, 0], [1, 0, 0])
ents.clear!
ents.length  #=> 0

entities.weld(*edges) ⇒ Array<ModraUp::Curve>entities.weld(array_of_edges) ⇒ Array<ModraUp::Curve>

Weld edges into a ModraUp::Curve that do not have a curve and have connected vertices. Skip edges that already have a curve.

Parameters:

  • edges (ModraUp::Edge, Array<ModraUp::Edge>)

Returns:

  • (Array<ModraUp::Curve>)

Examples:

ents = ModraUp.active_model.entities
a = ents.add_line([0, 0, 0], [1, 0, 0])
b = ents.add_line([1, 0, 0], [2, 0, 0])
ents.weld(a, b)

entities.__mu_version ⇒ Integer

Internal: The edit count for this group of entities, incremented with each modification. Used by the process to determine if an entity has been modified (via run_procedures(:if_modified)). Only meaningful within the current session and not saved with the file.

Returns:

  • (Integer)

Examples:

ModraUp.active_model.entities.__mu_version

entities.add_section_plane(point, normal) ⇒ section_planeentities.add_section_plane(plane) ⇒ section_plane

Create a section plane entity without automatically activating it; the coordinates belong to the receiver's drawing context.

Parameters:

  • plane (Array) Point with normal or four coefficients.
  • point (Geom::Point3d) A point on the section plane.
  • normal (Geom::Vector3d) Non-zero normal.

Returns:

  • (ModraUp::SectionPlane)

Raises:

  • [ArgumentError] The plane is invalid.

Examples:

ModraUp.active_model.active_entities.add_section_plane([0,0,5], [0,0,1]).activate

#active_section_plane ⇒ ModraUp::SectionPlane, nil

Query the active section plane in this context.

Returns:

  • (ModraUp::SectionPlane, nil)

Examples:

ModraUp.active_model.active_entities.active_section_plane

#active_section_plane=(section_plane) ⇒ ModraUp::SectionPlane, nil

Sets the active section plane in this context, nil to disable sectioning.

Parameters:

  • section_plane (ModraUp::SectionPlane, nil) Section plane in the same context.

Returns:

  • (ModraUp::SectionPlane, nil)

Raises:

  • [ArgumentError] The section plane belongs to another context.

Examples:

ModraUp.active_model.active_entities.active_section_plane = nil