Class: ModraUp::Model
- Inherits:
-
Object
- Object
- ModraUp::Model
Overview
An open model document. Obtain it from ModraUp.active_model. Direct construction with Model.new is unsupported.
Constants # collapse
- ModraUp::Model::VERSION_3
The target format constants for #save and #save_copy. The current SKP writer only supports VERSION_2017.
- ModraUp::Model::VERSION_4
See VERSION_3.
- ModraUp::Model::VERSION_5
See VERSION_3.
- ModraUp::Model::VERSION_6
See VERSION_3.
- ModraUp::Model::VERSION_7
See VERSION_3.
- ModraUp::Model::VERSION_8
See VERSION_3.
- ModraUp::Model::VERSION_2013
See VERSION_3.
- ModraUp::Model::VERSION_2014
See VERSION_3.
- ModraUp::Model::VERSION_2015
See VERSION_3.
- ModraUp::Model::VERSION_2016
See VERSION_3.
- ModraUp::Model::VERSION_2017
See VERSION_3.
- ModraUp::Model::VERSION_2018
See VERSION_3.
- ModraUp::Model::VERSION_2019
See VERSION_3.
- ModraUp::Model::VERSION_2020
See VERSION_3.
- ModraUp::Model::VERSION_2021
See VERSION_3.
- ModraUp::Model::ProTrial
One of the values returned by #get_product_family.
- ModraUp::Model::ProLicensed
One possible return value of #get_product_family. Currently agrees with ModraUp.is_pro?.
- ModraUp::Model::MakeTrial
One of the values returned by #get_product_family.
- ModraUp::Model::Make
One of the values returned by #get_product_family.
- ModraUp::Model::LOAD_STATUS_SUCCESS
Loading the model was successful. The current ModraUp.open_file does not return this status to Ruby.
- ModraUp::Model::LOAD_STATUS_SUCCESS_MORE_RECENT
Opened a file that is more recent than the current program version. Currently not in use.
Instance Method Summary # collapse
-
#hatch_patterns ⇒ ModraUp::HatchPatterns
Returns the collection of hatch patterns in the model.
-
#entities ⇒ ModraUp::Entities
Root drawing context of the model.
-
#active_entities ⇒ ModraUp::Entities
The current editing context (different from #entities after grouping).
-
#active_view ⇒ ModraUp::View
Current viewport. Repeated calls return a new wrapper pointing to the same camera and overlay state within the same model.
-
#axes ⇒ ModraUp::Axes
The current drawing coordinate axis changes with the group or component being edited.
-
#active_path ⇒ Array<ModraUp::Group, ModraUp::ComponentInstance>, nil
The active path in the group or component. Returns nil when editing at the root context.
-
#active_path=(path) ⇒ ModraUp::Model
Open a group/component path for editing. nil or an empty array returns to the root context. The path must be a layer-by-layer sequence of live ModraUp::Group / ModraUp::ComponentInstance starting from the model root.
-
#close_active ⇒ Boolean
Exit the currently active group/component layer. Returns false if already at the root context.
-
#close(ignore_changes = false) ⇒ nil
Close the document tab containing the model (not necessarily the current document). If ignore_changes is false and the model has unsaved modifications, prompt to save; canceling keeps the document open. Closing the last document creates a new host document based on a template. After closing, the old Model and its entity objects are no longer accessible. Closing the current model without a host is equivalent to File > New.
-
#selection ⇒ ModraUp::Selection
Current selection set. Repeatedly calling it on the same model returns the same wrapper object.
-
#tools ⇒ ModraUp::Tools
The tool manager for the current model.
-
#select_tool(tool = nil) ⇒ ModraUp::Model
Activates a custom Ruby tool; nil returns to the select tool. Protocol follows ModraUp::Tool: any object that implements event methods, without needing to inherit. It will call activate, deactivate(view), and onSetCursor (if present). Re-selecting the same object will first call ModraUp::Tool#onCancel(1) and then activate. The viewport will then forward mouse, keyboard, VCB, getMenu, and draw events.
-
#add_observer(observer) ⇒ Boolean
Register a ModraUp::ModelObserver. Adding the same object a second time returns false. Transactions, group paths, saving, and component placement will dispatch corresponding callbacks.
-
#remove_observer(observer) ⇒ Boolean
Remove the model observer.
-
#start_operation(op_name) ⇒ true
Start a reversible operation. Should be paired with #commit_operation or #abort_operation. disable_ui disables refreshing; next_transparent / transparent merge adjacent operations into a single undo step.
-
#commit_operation ⇒ Boolean
Commit the current operation.
-
#abort_operation ⇒ Boolean
Abort the current operation and rollback.
-
#definitions ⇒ ModraUp::DefinitionList
Component definition table.
-
#line_styles ⇒ ModraUp::LineStyles
Built-in line styles (12 named styles).
-
#materials ⇒ ModraUp::Materials
Materials table of the model.
-
#rendering_options ⇒ ModraUp::RenderingOptions
The display style options for the model (edges, surfaces, background, X-ray, etc.), with key names matching SketchUp.
-
#shadow_info ⇒ ModraUp::ShadowInfo
model.shadow_info -> ModraUp::ShadowInfo
-
#layers ⇒ ModraUp::Layers
Layer (Tag) table. Index 0 is the default `Layer0`.
-
#active_layer ⇒ ModraUp::Layer
The current layer. Newly drawn edges and faces appear on this layer.
-
#active_layer=(layer) ⇒ ModraUp::Layer
Sets the current layer. Passing nil will revert to the default layer Layer0.
-
#pages ⇒ ModraUp::Pages
Scene page table (called scenes in the interface).
-
#attribute_dictionaries ⇒ ModraUp::AttributeDictionaries, nil
Collection of model-level attribute dictionaries. Returns nil if no dictionary exists.
-
#attribute_dictionary(name) ⇒ ModraUp::AttributeDictionary, nil
Retrieve the model-level dictionary by name. Return nil if it does not exist and the create flag is false.
-
#set_attribute(dict_name, key, value) ⇒ Object
Writes a model-level attribute. An empty dictionary name or key raises an error. Inside #start_operation, the write is committed or aborted with geometry changes. Otherwise it creates a separate history entry. Values retain their type when read back. For structured data, use JSON.generate in Ruby and pass the resulting string.
-
#get_attribute(dict_name, key, default = nil) ⇒ Object
Read the model-level attribute. If dict_name and key are Symbols, convert them to strings. Return default if the dictionary or key is missing. The return value type is the same as that written by #set_attribute.
-
#delete_attribute(dict_name) ⇒ nil
Delete the entire model-level dictionary, or delete a specific key.
-
#path ⇒ String
Path to the saved file. Returns an empty string if the file has never been saved.
-
#name ⇒ String
The name of the Model Info, independent of the file path and #title; it is an empty string if not set.
-
#entityID ⇒ String
Like SketchUp, the model does not have a numeric ID; it returns a string "Model". The entities within the model use ModraUp::Entity#entityID (an integer starting from 1).
-
#find_entity_by_id(id_or_guid) ⇒ ModraUp::Entity, nil, Array<ModraUp::Entity, nil>
Find an entity by its ModraUp::Entity#entityID; a string parameter finds a group/component instance by GUID. Pass a single parameter to return an entity or nil, pass multiple or an array to return an array of the same order (with nil at positions where no entity is found). entityID is valid only for the current session.
-
#find_entity_by_persistent_id(pid) ⇒ ModraUp::Entity, nil, Array<ModraUp::Entity, nil>
Find by ModraUp::Entity#persistent_id. The persistent_id is saved with the model and remains unchanged upon reopening.
-
#valid? ⇒ Boolean
Returns true if the associated model is not yet closed; models opened in the background remain valid.
-
#deleted? ⇒ Boolean
Opposite of #valid?.
-
#typename ⇒ String
Fixed as "Model".
-
#guid ⇒ String
Model version GUID. It will be updated and saved with the file upon successful modification.
-
#title ⇒ String
Not saved as a string null value, saved as a filename (without extension).
-
#bounds ⇒ Geom::BoundingBox
The world bounding box of the model content.
-
#edit_transform ⇒ Geom::Transformation
Returns the transformation from the current editing context to world coordinates. At the model root it is the identity transformation.
-
#modified? ⇒ Boolean
Has the model been modified since the last save.
-
#number_faces ⇒ Integer
The number of live faces in the model.
-
#raytest(ray) ⇒ Array(Geom::Point3d, Array<ModraUp::Drawingelement>), nil
Find the first hit along the ray (face or edge, including coplanar boundaries). The ray is given as [point, vector]; the second item is a Point3d when specifying two points to determine the direction; a numerical array is interpreted as a vector, and if normalization is not possible, the second item is treated as a point. On hit, returns [Geom::Point3d, Array] (point and instance path), and if no hit, returns nil. The wysiwyg_flag is default true; set to false to also query hidden entities and geometry within hidden instances.
-
#save ⇒ Boolean
Save the model. If no path is specified and it has not been saved before, raise an ArgumentError (no dialog). The SKP writer currently only supports the 2017 format; explicitly specifying another version will return false.
-
#save_copy(path) ⇒ Boolean
Save a copy, preserving the path, dirty state, and original model GUID. Explicitly specified versions are currently supported only up to VERSION_2017.
-
#export(path) ⇒ Boolean
Exports the model without changing #path. The desktop host uses its CAD plugin for 3D DWG and DXF. Other supported formats include .skp, .osk3d, GLB, OBJ, and STL. The host accepts and ignores show_summary or an options Hash.
-
#get_product_family ⇒ Integer
Product line. Returns ProLicensed consistent with ModraUp.is_pro?.
-
#options ⇒ ModraUp::OptionsManager
Model options tree. Plugins read units by options["UnitsOptions"]["LengthUnit"], with values such as Length::Inches.
-
#add_note(note, x, y) ⇒ ModraUp::Text
Adds a text note (annotation) to the model at the given screen-space position.
- #behavior ⇒ ModraUp::Behavior
- #name=(name) ⇒ String
- #description ⇒ String
- #description=(description) ⇒ String
- #tags ⇒ String
- #tags=(tags) ⇒ String
- #active_section_planes ⇒ Array<ModraUp::SectionPlane>
- #instance_path_from_pid_path(pid_path) ⇒ ModraUp::InstancePath
- #drawing_element_visible?(instance_path) ⇒ Boolean
- #georeferenced? ⇒ Boolean
- #mipmapping? ⇒ Boolean
- #mipmapping=(enabled) ⇒ Boolean
- #save_thumbnail(filename) ⇒ Boolean
- #place_component(componentdef, repeat) ⇒ ModraUp::Model, nil
-
#import(path) ⇒ Boolean
Import files into the current model by file extension. DWG/DXF files are automatically placed, while SKP/OSK3D files enter the component placement tool.
-
#inspect ⇒ String
Returns a string of the form #<Sketchup::Model:0x...>, omitting instance variables.
-
#overlays ⇒ ModraUp::OverlaysManager
The layer manager for overlay layers in this model.
-
#__mu_operation_open? ⇒ Boolean
Internal: Is there an uncommitted operation currently open (between start_operation and commit_operation)? The process runs within the open operation without creating a new one.
-
#layout_document ⇒ Layout::Document
A model's embedded drawing sheet document. Returns the same object each time within the same model; accessing it after the model is closed throws a TypeError.
Instance Method Details
#hatch_patterns ⇒ ModraUp::HatchPatterns
Returns the collection of hatch patterns in the model.
model.entities ⇒ ModraUp::Entities
Root drawing context of the model.
model.active_entities ⇒ ModraUp::Entities
The current editing context (different from #entities after grouping).
model.active_view ⇒ ModraUp::View
Current viewport. Repeated calls return a new wrapper pointing to the same camera and overlay state within the same model.
model.axes ⇒ ModraUp::Axes
The current drawing coordinate axis changes with the group or component being edited.
model.active_path ⇒ Array, nil
The active path in the group or component. Returns nil when editing at the root context. Returns a copy, so modifying the array with pop will not exit the edit mode.
model.active_path=(path) ⇒ model
Open a group/component path for editing. nil or an empty array returns to the root context. The path must be a layer-by-layer sequence of live ModraUp::Group / ModraUp::ComponentInstance starting from the model root.
model.close_active ⇒ Boolean
Exit the currently active group/component layer. Returns false if already at the root context.
model.close(ignore_changes = false) ⇒ nil
Close the document tab containing the model (not necessarily the current document). If ignore_changes is false and the model has unsaved modifications, prompt to save; canceling keeps the document open. Closing the last document creates a new host document based on a template. After closing, the old Model and its entity objects are no longer accessible. Closing the current model without a host is equivalent to File > New.
model.selection ⇒ ModraUp::Selection
Current selection set. Repeatedly calling it on the same model returns the same wrapper object.
model.tools ⇒ ModraUp::Tools
The tool manager for the current model.
model.select_tool(tool = nil) ⇒ model
Activates a custom Ruby tool; nil returns to the select tool. Protocol follows ModraUp::Tool: any object that implements event methods, without needing to inherit. It will call activate, deactivate(view), and onSetCursor (if present). Re-selecting the same object will first call ModraUp::Tool#onCancel(1) and then activate. The viewport will then forward mouse, keyboard, VCB, getMenu, and draw events.
model.add_observer(observer) ⇒ Boolean
Register a ModraUp::ModelObserver. Adding the same object a second time returns false. Transactions, group paths, saving, and component placement will dispatch corresponding callbacks.
model.remove_observer(observer) ⇒ Boolean
Remove the model observer.
model.start_operation(op_name) ⇒ truemodel.start_operation(op_name, disable_ui, next_transparent, transparent) ⇒ true
Start a reversible operation. Should be paired with #commit_operation or #abort_operation. disable_ui disables refreshing; next_transparent / transparent merge adjacent operations into a single undo step.
model.commit_operation ⇒ Boolean
Commit the current operation.
model.abort_operation ⇒ Boolean
Abort the current operation and rollback.
model.definitions ⇒ ModraUp::DefinitionList
Component definition table.
model.line_styles ⇒ ModraUp::LineStyles
Built-in line styles (12 named styles).
model.materials ⇒ ModraUp::Materials
Materials table of the model.
model.rendering_options ⇒ ModraUp::RenderingOptions
The display style options for the model (edges, surfaces, background, X-ray, etc.), with key names matching SketchUp.
#shadow_info ⇒ ModraUp::ShadowInfo
model.shadow_info -> ModraUp::ShadowInfo Model shadow parameters, local time, geographical location, and derived sun direction; modifications only redraw the viewport.
model.layers ⇒ ModraUp::Layers
Layer (Tag) table. Index 0 is the default `Layer0`.
model.active_layer ⇒ ModraUp::Layer
The current layer. Newly drawn edges and faces appear on this layer.
model.active_layer=(layer) ⇒ ModraUp::Layer
Sets the current layer. Passing nil will revert to the default layer Layer0. Dispatches ModraUp::LayersObserver#onCurrentLayerChanged when the current layer changes.
model.pages ⇒ ModraUp::Pages
Scene page table (called scenes in the interface).
model.attribute_dictionaries ⇒ ModraUp::AttributeDictionaries, nil
Collection of model-level attribute dictionaries. Returns nil if no dictionary exists.
model.attribute_dictionary(name) ⇒ ModraUp::AttributeDictionary, nilmodel.attribute_dictionary(name, create) ⇒ ModraUp::AttributeDictionary, nil
Retrieve the model-level dictionary by name. Return nil if it does not exist and the create flag is false.
model.set_attribute(dict_name, key, value) ⇒ value
Writes a model-level attribute. An empty dictionary name or key raises an error. Inside #start_operation, the write is committed or aborted with geometry changes. Otherwise it creates a separate history entry. Values retain their type when read back. For structured data, use JSON.generate in Ruby and pass the resulting string.
model.get_attribute(dict_name, key, default = nil) ⇒ Object
Read the model-level attribute. If dict_name and key are Symbols, convert them to strings. Return default if the dictionary or key is missing. The return value type is the same as that written by #set_attribute.
model.delete_attribute(dict_name) ⇒ nilmodel.delete_attribute(dict_name, key) ⇒ nil
Delete the entire model-level dictionary, or delete a specific key.
model.path ⇒ String
Path to the saved file. Returns an empty string if the file has never been saved.
model.name ⇒ String
The name of the Model Info, independent of the file path and #title; it is an empty string if not set.
model.entityID ⇒ String
Like SketchUp, the model does not have a numeric ID; it returns a string "Model". The entities within the model use ModraUp::Entity#entityID (an integer starting from 1).
model.find_entity_by_id(id_or_guid) ⇒ ModraUp::Entity or nilmodel.find_entity_by_id(*ids_or_guids) ⇒ Arraymodel.find_entity_by_id([ids_or_guids]) ⇒ Array
Find an entity by its ModraUp::Entity#entityID; a string parameter finds a group/component instance by GUID. Pass a single parameter to return an entity or nil, pass multiple or an array to return an array of the same order (with nil at positions where no entity is found). entityID is valid only for the current session.
model.find_entity_by_persistent_id(pid) ⇒ ModraUp::Entity or nilmodel.find_entity_by_persistent_id(*pids, **scope) ⇒ Arraymodel.find_entity_by_persistent_id([pids], **scope) ⇒ Array
Find by ModraUp::Entity#persistent_id. The persistent_id is saved with the model and remains unchanged upon reopening. Use boolean keywords to limit the scope: entities, definitions, layers, layer_folders, materials, pages (when any range is given, only search within the ranges set to true).
model.valid? ⇒ Boolean
Returns true if the associated model is not yet closed; models opened in the background remain valid.
model.deleted? ⇒ Boolean
Opposite of #valid?.
model.typename ⇒ String
Fixed as "Model".
model.guid ⇒ String
Model version GUID. It will be updated and saved with the file upon successful modification.
model.title ⇒ String
Not saved as a string null value, saved as a filename (without extension).
model.bounds ⇒ Geom::BoundingBox
The world bounding box of the model content.
model.edit_transform ⇒ Geom::Transformation
Returns the transformation from the current editing context to world coordinates. At the model root it is the identity transformation.
model.modified? ⇒ Boolean
Has the model been modified since the last save.
model.number_faces ⇒ Integer
The number of live faces in the model.
model.raytest(ray) ⇒ Array, nilmodel.raytest(ray, wysiwyg_flag) ⇒ Array, nil
Find the first hit along the ray (face or edge, including coplanar boundaries). The ray is given as [point, vector]; the second item is a Point3d when specifying two points to determine the direction; a numerical array is interpreted as a vector, and if normalization is not possible, the second item is treated as a point. On hit, returns [Geom::Point3d, Array] (point and instance path), and if no hit, returns nil. The wysiwyg_flag is default true; set to false to also query hidden entities and geometry within hidden instances.
model.save ⇒ Booleanmodel.save(path) ⇒ Booleanmodel.save(path, version) ⇒ Boolean
Save the model. If no path is specified and it has not been saved before, raise an ArgumentError (no dialog). The SKP writer currently only supports the 2017 format; explicitly specifying another version will return false.
model.save_copy(path) ⇒ Booleanmodel.save_copy(path, version) ⇒ Boolean
Save a copy, preserving the path, dirty state, and original model GUID. Explicitly specified versions are currently supported only up to VERSION_2017.
model.export(path) ⇒ Booleanmodel.export(path, show_summary) ⇒ Boolean
Exports the model without changing #path. The desktop host uses its CAD plugin for 3D DWG and DXF. Other supported formats include .skp, .osk3d, GLB, OBJ, and STL. The host accepts and ignores show_summary or an options Hash.
model.get_product_family ⇒ Integer
Product line. Returns ProLicensed consistent with ModraUp.is_pro?.
model.options ⇒ ModraUp::OptionsManager
Model options tree. Plugins read units by options["UnitsOptions"]["LengthUnit"], with values such as Length::Inches.
model.add_note(note, x, y) ⇒ ModraUp::Text
Adds a text note (annotation) to the model at the given screen-space position. Coordinates are normalised window positions: 0.0 is the top-left, 1.0 is the bottom-right.
#behavior ⇒ ModraUp::Behavior
#name=(name) ⇒ String
#description ⇒ String
#description=(description) ⇒ String
#tags ⇒ String
#tags=(tags) ⇒ String
#active_section_planes ⇒ Array<ModraUp::SectionPlane>
#instance_path_from_pid_path(pid_path) ⇒ ModraUp::InstancePath
#drawing_element_visible?(instance_path) ⇒ Boolean
#georeferenced? ⇒ Boolean
#mipmapping? ⇒ Boolean
#mipmapping=(enabled) ⇒ Boolean
#save_thumbnail(filename) ⇒ Boolean
#place_component(componentdef, repeat) ⇒ ModraUp::Model, nil
model.import(path) ⇒ Booleanmodel.import(path, show_summary) ⇒ Booleanmodel.import(path, options) ⇒ Boolean
Import files into the current model by file extension. DWG/DXF files are automatically placed, while SKP/OSK3D files enter the component placement tool.
model.inspect ⇒ String
Returns a string of the form #<Sketchup::Model:0x...>, omitting instance variables.
model.overlays ⇒ ModraUp::OverlaysManager
The layer manager for overlay layers in this model.
model.__mu_operation_open? ⇒ Boolean
Internal: Is there an uncommitted operation currently open (between start_operation and commit_operation)? The process runs within the open operation without creating a new one.
model.layout_document ⇒ Layout::Document
A model's embedded drawing sheet document. Returns the same object each time within the same model; accessing it after the model is closed throws a TypeError.