Class: ModraUp::ComponentDefinition
- Inherits:
-
ModraUp::Drawingelement
- Object
- ModraUp::Entity
- ModraUp::Drawingelement
- ModraUp::ComponentDefinition
Overview
Component Definition: A dictionary of name and definition-level properties. Inherits from ModraUp::Drawingelement.
Instance Method Summary # collapse
-
#name ⇒ String
Name.
-
#name= ⇒ String
Set the definition name. An empty string will raise an error; if it conflicts with other definitions, an automatic suffix of #2 will be added.
-
#description ⇒ String
Definition description. Will be an empty string if not filled.
-
#description= ⇒ String
Set the definition description.
-
#typename ⇒ String
Fixes to ComponentDefinition.
-
#entityID ⇒ Integer
The definition ID within the current session, see ModraUp::Entity#entityID.
-
#guid ⇒ String
Define the GUID. Leave it as an empty string if it is not present when imported.
-
#valid? ⇒ Boolean
Returns true if the definition is still in the model.
-
#deleted? ⇒ Boolean
Opposite of #valid?.
-
#entities ⇒ ModraUp::Entities
Define the internal drawing context.
-
#instances ⇒ Array<ModraUp::ComponentInstance, ModraUp::Group>
All instances of ModraUp::ComponentInstance / ModraUp::Group that reference this definition, including those embedded in other definitions.
-
#count_instances ⇒ Integer
Returns the number of placed instances referencing this definition, equal to #instances.length. Includes instances that use the definition but are not currently placed.
-
#count_used_instances ⇒ Integer
Counts the actual occurrences from the model root. When a child definition is placed multiple times under a parent definition, the counts are multiplied by level.
-
#attribute_dictionaries ⇒ ModraUp::AttributeDictionaries, nil
Attribute dictionary at the definition level. Returns nil if none is defined.
-
#attribute_dictionary(name) ⇒ ModraUp::AttributeDictionary, nil
Retrieve the definition-level attribute dictionary by name. Returns nil if the attribute dictionary does not exist; creates an empty dictionary if create is true.
-
#set_attribute(dict_name, key, value) ⇒ Object
Write a definition-level attribute. The type written is the type read back.
-
#get_attribute(dict_name, key, default = nil) ⇒ Object
Read the definition-level attribute. When dict_name and key are Symbols, convert them to strings.
-
#delete_attribute(dict_name) ⇒ Boolean
Delete attribute keys or an entire dictionary at the definition level.
-
#save_thumbnail(path) ⇒ Boolean
Write the definition thumbnail to path (PNG). Render with the same set of faces and edges coloring as #thumbnail_camera (if not set, bound the definition bounding box); bake with no geometry, no UI, or if writing to disk fails, return false.
-
#refresh_thumbnail ⇒ nil
Request to refresh the component browser thumbnail (invalidate dirty memory cache; re-bake next time it is displayed).
-
#bounds ⇒ Geom::BoundingBox
Define the axis-aligned bounding box in local coordinates (excluding instance transformations).
-
#invalidate_bounds ⇒ Boolean
Drop the definition bounds cache. This implementation recalculates #bounds on every call, invalidating the viewport tessellation.
-
#behavior ⇒ ModraUp::Behavior
The definition's ModraUp::Behavior.
-
#group? ⇒ Boolean
Returns true if the component definition is a group (as opposed to a regular component).
-
#hidden? ⇒ Boolean
Hides the component in the component browser.
-
#image? ⇒ Boolean
Returns whether this is an image definition. Currently always returns false.
-
#internal? ⇒ Boolean
Is an internal definition within the model (not loaded from a file). Currently, this is always true.
-
#live_component? ⇒ Boolean
Returns whether the component is a Live Component. Currently, this always returns false.
-
#manifold? ⇒ Boolean
Is a closed solid: each live edge is exactly shared by two live faces, equivalent to the manifold determination within ModraUp::Entities.
-
#path ⇒ String
Returns the file path of the loaded definition. An in-memory definition is an empty string.
-
#insertion_point ⇒ Geom::Point3d
Insertion point. Fixed at the origin since SketchUp 2020.
-
#insertion_point= ⇒ Object
Set the insertion point. No operation in SketchUp 2020 and later.
-
#load_time ⇒ Time
Define load time (in Unix seconds). New definitions in memory have an epoch time.
-
#save_as(path) ⇒ Boolean
Save the definition as a SketchUp .skp file. The root entity is the geometry of this definition; nested definitions are included.
- #save_copy(path) ⇒ Boolean
-
#add_classification(schema_name, schema_type) ⇒ Boolean
Add a schema/type classification to the definition. An empty name returns false; adding the same schema will replace the type.
-
#remove_classification(schema_name, schema_type) ⇒ Boolean
Remove the added schema/type. If not found, return false, and clear the classification values under that schema.
-
#get_classification_value(path) ⇒ String, nil
Read classification attributes along a path. The path's first item is the schema name; otherwise, it returns nil.
-
#set_classification_value(path, value) ⇒ Boolean
Write the classification attribute along the path. The schema must be #add_classification; otherwise, it returns false.
-
#add_observer(observer) ⇒ Boolean
Register a ModraUp::DefinitionObserver. Adding the same object a second time returns false. ModraUp::Entities#add_instance dispatches an onComponentInstanceAdded event.
-
#remove_observer(observer) ⇒ Boolean
Remove the observer from the definition.
-
#model ⇒ ModraUp::Model
The model it belongs to.
-
#parent ⇒ ModraUp::Model
The parent object of the definition is the model.
-
#persistent_id ⇒ Integer
The definition ID that persists with the model, see ModraUp::Entity#persistent_id.
-
#thumbnail_camera ⇒ ModraUp::Camera
Thumbnail camera. Unset when it bounds the definition bounding box.
-
#thumbnail_camera= ⇒ ModraUp::Camera
Set the thumbnail camera. Afterward, #thumbnail_camera read back the same viewpoint.
-
#== ⇒ Boolean
The same slot in the same model returns true.
-
#<=> ⇒ Integer
Compare by #name for use with sort.
-
#casts_shadows? ⇒ Boolean
The definition does not cast shadows. Always returns false.
-
#casts_shadows= ⇒ Object
Defines the projection switch for the definition level. Current storage is not supported.
-
#receives_shadows? ⇒ Boolean
The definition does not receive shadows. Always returns false.
-
#receives_shadows= ⇒ Object
Defines the shadow reception switch for the component definition. The setting is not currently stored.
-
#visible? ⇒ Boolean
Determines if the definition is visible in the component browser. Opposite of #hidden?.
-
#visible= ⇒ Object
Set the component browser visibility to true. Equivalent to #hidden= with a value of false.
-
#hidden= ⇒ Object
Sets the component browser hidden flag.
-
#erase! ⇒ nil
Delete this definition from the definition table. Throws an error if there are instances remaining.
-
#layer ⇒ ModraUp::Layer
Returns the default Layer0 if the definition has no layer.
-
#layer= ⇒ Object
Define without a layer, write it as ignored.
-
#material ⇒ nil
Inherits from Drawingelement#material. The definition itself does not define a drawing material and is always nil.
-
#material=(material) ⇒ Object
Inherits from Drawingelement#material=. The definition itself cannot be colored; the assignment is ignored.
-
#locked? ⇒ Boolean
Definitions cannot be locked.
-
#locked= ⇒ Object
Definitions cannot be locked, writes are ignored.
-
#attach_procedure(procedure, parameters) ⇒ nil
Converts the definition to a procedural component. Existing entities become control entities in a hidden inputs group, and #entities exposes the output. Specify a registered procedure or its ID in procedure. Keys in parameters must be declared by the procedure. Omitted parameters use their declared default. If validation or execution fails, the operation is rolled back and raises ArgumentError.
-
#procedural? ⇒ Boolean
Added Ruby procedures, or generated by native process tools. Parameters components (node graphs) do not count.
-
#control_entities ⇒ ModraUp::Entities
Input entities for a process component.
-
#get_procedure_parameters ⇒ Hash{Symbol => Integer, Float, String, Boolean}
Current parameters (Symbol keys). An empty Hash when the process is not registered in this session.
-
#set_procedure_parameters(parameters) ⇒ ModraUp::ComponentDefinition
Merge parameters and regenerate the output in one step. Undo on failure, rolling back the entire step and raising an ArgumentError.
-
#run_procedures(mode = :if_modified) ⇒ nil
:if_modified runs the procedure only if the control entity has been modified;:force runs the procedure regardless. If no procedures are registered, nothing happens.
-
#make_non_procedural(retained_geometry) ⇒ nil
Remove Procedural: :keep_output Keep Output (keep input when output is empty), :keep_input Keep Control Entity. One undo step.
Inherited from ModraUp::Entity
-
#to_s ⇒ String
String form. Returns "#<Deleted Entity>” when the entity has been deleted.
-
#inspect ⇒ String
Same as #to_s.
Instance Method Details
definition.name ⇒ String
Name.
definition.name = name ⇒ String
Set the definition name. An empty string will raise an error; if it conflicts with other definitions, an automatic suffix of #2 will be added.
definition.description ⇒ String
Definition description. Will be an empty string if not filled.
definition.description = text ⇒ String
Set the definition description.
definition.typename ⇒ String
Fixes to ComponentDefinition.
definition.entityID ⇒ Integer
The definition ID within the current session, see ModraUp::Entity#entityID.
definition.guid ⇒ String
Define the GUID. Leave it as an empty string if it is not present when imported.
definition.valid? ⇒ Boolean
Returns true if the definition is still in the model.
definition.deleted? ⇒ Boolean
Opposite of #valid?.
definition.entities ⇒ ModraUp::Entities
Define the internal drawing context.
definition.instances ⇒ Array
All instances of ModraUp::ComponentInstance / ModraUp::Group that reference this definition, including those embedded in other definitions.
definition.count_instances ⇒ Integer
Returns the number of placed instances referencing this definition, equal to #instances.length. Includes instances that use the definition but are not currently placed.
definition.count_used_instances ⇒ Integer
Counts the actual occurrences from the model root. When a child definition is placed multiple times under a parent definition, the counts are multiplied by level.
definition.attribute_dictionaries ⇒ ModraUp::AttributeDictionaries, nil
Attribute dictionary at the definition level. Returns nil if none is defined.
definition.attribute_dictionary(name) ⇒ ModraUp::AttributeDictionary, nildefinition.attribute_dictionary(name, create) ⇒ ModraUp::AttributeDictionary, nil
Retrieve the definition-level attribute dictionary by name. Returns nil if the attribute dictionary does not exist; creates an empty dictionary if create is true.
definition.set_attribute(dict_name, key, value) ⇒ value
Write a definition-level attribute. The type written is the type read back.
Structural data should be passed as a string after being generated with JSON.generate.
definition.get_attribute(dict_name, key, default = nil) ⇒ Object
Read the definition-level attribute. When dict_name and key are Symbols, convert them to strings.
definition.delete_attribute(dict_name) ⇒ Booleandefinition.delete_attribute(dict_name, key) ⇒ Boolean
Delete attribute keys or an entire dictionary at the definition level.
definition.save_thumbnail(path) ⇒ Boolean
Write the definition thumbnail to path (PNG). Render with the same set of faces and edges coloring as #thumbnail_camera (if not set, bound the definition bounding box); bake with no geometry, no UI, or if writing to disk fails, return false.
definition.refresh_thumbnail ⇒ nil
Request to refresh the component browser thumbnail (invalidate dirty memory cache; re-bake next time it is displayed).
definition.bounds ⇒ Geom::BoundingBox
Define the axis-aligned bounding box in local coordinates (excluding instance transformations).
definition.invalidate_bounds ⇒ true
Drop the definition bounds cache. This implementation recalculates #bounds on every call, invalidating the viewport tessellation.
definition.behavior ⇒ ModraUp::Behavior
The definition's ModraUp::Behavior.
definition.group? ⇒ Boolean
Returns true if the component definition is a group (as opposed to a regular component).
definition.image? ⇒ Boolean
Returns whether this is an image definition. Currently always returns false.
definition.internal? ⇒ Boolean
Is an internal definition within the model (not loaded from a file). Currently, this is always true.
definition.live_component? ⇒ Boolean
Returns whether the component is a Live Component. Currently, this always returns false.
definition.manifold? ⇒ Boolean
Is a closed solid: each live edge is exactly shared by two live faces, equivalent to the manifold determination within ModraUp::Entities.
definition.path ⇒ String
Returns the file path of the loaded definition. An in-memory definition is an empty string.
definition.insertion_point ⇒ Geom::Point3d
Insertion point. Fixed at the origin since SketchUp 2020.
definition.insertion_point = point ⇒ point
Set the insertion point. No operation in SketchUp 2020 and later.
definition.load_time ⇒ Time
Define load time (in Unix seconds). New definitions in memory have an epoch time.
definition.save_as(path) ⇒ Booleandefinition.save_as(path, version) ⇒ Boolean
Save the definition as a SketchUp .skp file. The root entity is the geometry of this definition; nested definitions are included. After success, #path becomes path. version is currently ignored (always writes legacy v17).
definition.save_copy(path) ⇒ Booleandefinition.save_copy(path, version) ⇒ Boolean
definition.add_classification(schema_name, schema_type) ⇒ Boolean
Add a schema/type classification to the definition. An empty name returns false; adding the same schema will replace the type.
definition.remove_classification(schema_name, schema_type) ⇒ Boolean
Remove the added schema/type. If not found, return false, and clear the classification values under that schema.
definition.get_classification_value(path) ⇒ Object, nil
Read classification attributes along a path. The path's first item is the schema name; otherwise, it returns nil.
definition.set_classification_value(path, value) ⇒ Boolean
Write the classification attribute along the path. The schema must be #add_classification; otherwise, it returns false.
definition.add_observer(observer) ⇒ Boolean
Register a ModraUp::DefinitionObserver. Adding the same object a second time returns false. ModraUp::Entities#add_instance dispatches an onComponentInstanceAdded event.
definition.remove_observer(observer) ⇒ true
Remove the observer from the definition.
definition.model ⇒ ModraUp::Model
The model it belongs to.
definition.parent ⇒ ModraUp::Model
The parent object of the definition is the model.
definition.persistent_id ⇒ Integer
The definition ID that persists with the model, see ModraUp::Entity#persistent_id.
definition.thumbnail_camera ⇒ ModraUp::Camera
Thumbnail camera. Unset when it bounds the definition bounding box.
definition.thumbnail_camera = camera ⇒ camera
Set the thumbnail camera. Afterward, #thumbnail_camera read back the same viewpoint.
definition == other ⇒ Boolean
The same slot in the same model returns true.
definition <=> other ⇒ Integer
Compare by #name for use with sort.
definition.casts_shadows? ⇒ Boolean
The definition does not cast shadows. Always returns false.
definition.casts_shadows = value ⇒ value
Defines the projection switch for the definition level. Current storage is not supported.
definition.receives_shadows? ⇒ Boolean
The definition does not receive shadows. Always returns false.
definition.receives_shadows = value ⇒ value
Defines the shadow reception switch for the component definition. The setting is not currently stored.
definition.visible? ⇒ Boolean
Determines if the definition is visible in the component browser. Opposite of #hidden?.
definition.visible = value ⇒ value
Set the component browser visibility to true. Equivalent to #hidden= with a value of false.
definition.erase! ⇒ nil
Delete this definition from the definition table. Throws an error if there are instances remaining.
definition.layer ⇒ ModraUp::Layer
Returns the default Layer0 if the definition has no layer.
definition.layer = layer ⇒ layer
Define without a layer, write it as ignored.
definition.material ⇒ nil
Inherits from Drawingelement#material. The definition itself does not define a drawing material and is always nil. The instance material is defined in ModraUp::ComponentInstance#material / ModraUp::Group#material.
definition.material=(material) ⇒ material
Inherits from Drawingelement#material=. The definition itself cannot be colored; the assignment is ignored.
definition.locked? ⇒ false
Definitions cannot be locked.
definition.locked = setting ⇒ setting
Definitions cannot be locked, writes are ignored.
definition.attach_procedure(procedure, parameters) ⇒ nil
Converts the definition to a procedural component. Existing entities become control entities in a hidden inputs group, and #entities exposes the output. Specify a registered procedure or its ID in procedure. Keys in parameters must be declared by the procedure. Omitted parameters use their declared default. If validation or execution fails, the operation is rolled back and raises ArgumentError.
definition.procedural? ⇒ Boolean
Added Ruby procedures, or generated by native process tools. Parameters components (node graphs) do not count.
definition.control_entities ⇒ ModraUp::Entities
Input entities for a process component.
definition.get_procedure_parameters ⇒ Hash
Current parameters (Symbol keys). An empty Hash when the process is not registered in this session.
definition.set_procedure_parameters(parameters) ⇒ ModraUp::ComponentDefinition
Merge parameters and regenerate the output in one step. Undo on failure, rolling back the entire step and raising an ArgumentError.
definition.run_procedures(mode = :if_modified) ⇒ nil
:if_modified runs the procedure only if the control entity has been modified;:force runs the procedure regardless. If no procedures are registered, nothing happens.
definition.make_non_procedural(retained_geometry) ⇒ nil
Remove Procedural: :keep_output Keep Output (keep input when output is empty), :keep_input Keep Control Entity. One undo step.