Class: ModraUp::Entities
- Inherits:
-
Object
- Object
- ModraUp::Entities
- 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.
Instance Method Summary # collapse
-
#add_face(point, point, point, ...) ⇒ ModraUp::Face, nil
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.
-
#add_line(start_pt, end_pt) ⇒ ModraUp::Edge, nil
Add an edge between two points and split any existing coplanar faces. Airborne wireframes must call ModraUp::Edge#find_faces to form faces.
-
#add_dimension_linear(start_pt_or_entity, end_pt_or_entity, offset_vector) ⇒ ModraUp::DimensionLinear, nil
Add a linear dimension. The offset_vector is the parallel offset from the start point to the dimension line.
-
#add_text(text, point, vector = nil) ⇒ ModraUp::Text, nil
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.
-
#add_cpoint(point) ⇒ ModraUp::ConstructionPoint
Add an auxiliary point. Not a vertex, does not weld or create an edge.
-
#add_cline(start_point, end_point) ⇒ ModraUp::ConstructionLine, nil
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.
-
#add_3d_text(string, alignment, font, is_bold = false, is_italic = false,) ⇒ Object
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.
-
#add_circle(center, normal, radius) ⇒ Array<ModraUp::Edge>, nil
Add a circle on a plane (create a closed ModraUp::ArcCurve and add a face).
-
#add_edges(point, point, ...) ⇒ 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.
-
#add_arc(center, xaxis, normal, radius, start_angle, end_angle) ⇒ Array<ModraUp::Edge>, nil
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.
-
#add_ngon(center, normal, radius, numsides) ⇒ Array<ModraUp::Edge>, nil
Add a regular polygon, where the is_polygon? method returns true.
-
#add_curve(point, point, ...) ⇒ Array<ModraUp::Edge>
Create a ModraUp::Curve by adding a polyline from a list of points and weld it together.
-
#add_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.
-
#add_instance(definition) ⇒ 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.
-
#add_faces_from_mesh(mesh) ⇒ Integer
Add faces from a Geom::PolygonMesh as polygons. Returns the number of faces successfully added.
-
#fill_from_mesh(mesh) ⇒ 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.
-
#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.
-
#remove_observer(observer) ⇒ Boolean
Remove the observer from the entity collection.
-
#transform_entities(transformation, *entities) ⇒ 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.
-
#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.
-
#transform_by_vectors(entities, vectors) ⇒ ModraUp::Entities
Applies corresponding translation vectors to each vertex or entity simultaneously. The two arrays must be of equal length.
-
#erase_entities(*entities) ⇒ 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.
-
#each ⇒ self, 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.
-
#grep(klass) ⇒ Array
Fast path: when klass is a known entity class (Face, Edge, Group,
-
#length ⇒ Integer
Number of undeleted elements (faces + edges + groups + component instances).
-
#size ⇒ Integer
Alias for #length.
-
#[] ⇒ ModraUp::Face, ModraUp::Edge, ModraUp::Group, ModraUp::ComponentInstance, nil
Access elements by index, with the order matching that of #each. Out-of-bounds access returns nil.
-
#at(index) ⇒ ModraUp::Face, ModraUp::Edge, ModraUp::Group, ModraUp::ComponentInstance, nil
Alias for #[].
-
#parent ⇒ ModraUp::Model, ModraUp::ComponentDefinition
The owner of this drawing context: root is ModraUp::Model, otherwise it is the ModraUp::ComponentDefinition containing it.
-
#model ⇒ ModraUp::Model
The model it belongs to.
-
#clear! ⇒ true
Clear the edges, faces, groups, instances, and dimensions in the current context.
-
#weld(*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.
-
#__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.
-
#add_section_plane(point, normal) ⇒ ModraUp::SectionPlane
Create a section plane entity without automatically activating it; the coordinates belong to the receiver's drawing context.
-
#active_section_plane ⇒ ModraUp::SectionPlane, nil
Query the active section plane in this context.
-
#active_section_plane=(section_plane) ⇒ ModraUp::SectionPlane, nil
Sets the active section plane in this context, nil to disable sectioning.
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.
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.
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.
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.
entities.add_cpoint(point) ⇒ ModraUp::ConstructionPoint
Add an auxiliary point. Not a vertex, does not weld or create an edge.
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.
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.
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).
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.
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.
entities.add_ngon(center, normal, radius, numsides) ⇒ Array<ModraUp::Edge>
Add a regular polygon, where the is_polygon? method returns true.
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.
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.
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.
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.
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.
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.
entities.remove_observer(observer) ⇒ Boolean
Remove the observer from the entity collection.
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.
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.
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.
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.
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.
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.
entities.length ⇒ Integer
Number of undeleted elements (faces + edges + groups + component instances).
entities.size ⇒ Integer
Alias for #length.
entities[index] ⇒ Entity, nil
Access elements by index, with the order matching that of #each. Out-of-bounds access returns nil.
entities.at(index) ⇒ Entity, nil
Alias for #[].
entities.parent ⇒ ModraUp::Model, ModraUp::ComponentDefinition
The owner of this drawing context: root is ModraUp::Model, otherwise it is the ModraUp::ComponentDefinition containing it.
entities.model ⇒ ModraUp::Model
The model it belongs to.
entities.clear! ⇒ true
Clear the edges, faces, groups, instances, and dimensions in the current context.
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.
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.
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.
#active_section_plane ⇒ ModraUp::SectionPlane, nil
Query the active section plane in this context.
#active_section_plane=(section_plane) ⇒ ModraUp::SectionPlane, nil
Sets the active section plane in this context, nil to disable sectioning.