ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::Materials

Inherits:
ModraUp::Entity show all
Includes:
Enumerable

Overview

Collection of model materials. Obtain from ModraUp::Model#materials.

Examples:

ModraUp.active_model.materials.add("Joe")

Instance Method Summary # collapse

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

materials.add ⇒ ModraUp::Materialmaterials.add(name) ⇒ ModraUp::Material

Add materials. When a name is duplicated, append a number (e.g., Joe / Joe1). If no name is provided, use Material / Material1.

Parameters:

  • name (String)

Returns:

  • (ModraUp::Material)

Examples:

ModraUp.active_model.materials.add("Joe").name  #=> "Joe"

materials[name] ⇒ ModraUp::Material, nilmaterials[index] ⇒ ModraUp::Material, nil

Retrieve a material by name or its 0-based index. If not found, return nil.

Parameters:

  • arg (String, Integer)

Returns:

  • (ModraUp::Material, nil)

Examples:

mats = ModraUp.active_model.materials
mats.add("Joe")
mats["Joe"].name  #=> "Joe"

materials.at(name) ⇒ ModraUp::Material, nilmaterials.at(index) ⇒ ModraUp::Material, nil

Alias for #[].

Parameters:

  • arg (String, Integer)

Returns:

  • (ModraUp::Material, nil)

Examples:

ModraUp.active_model.materials.at("Joe")

materials.size ⇒ Integer

The number of materials that have not been deleted.

Returns:

  • (Integer)

Examples:

ModraUp.active_model.materials.size

materials.length ⇒ Integer

Alias for #size.

Returns:

  • (Integer)

Examples:

ModraUp.active_model.materials.length

materials.each {|material| } ⇒ ModraUp::Materialsmaterials.each ⇒ Enumerator

Iterate over the undeleted materials.

Returns:

  • (ModraUp::Materials, Enumerator)

Yields:

  • @yieldparam material [ModraUp::Material]

Examples:

ModraUp.active_model.materials.each { |m| m.name }

materials.unique_name(name) ⇒ String

Returns a unique name that is not yet in use. If the base name is already in use, it appends a number to it.

Parameters:

  • name (String)

Returns:

  • (String)

Examples:

ModraUp.active_model.materials.unique_name("Joe")

materials.remove(material) ⇒ Boolean

Remove the material and clear any references from the geometry.

Parameters:

  • material (ModraUp::Material)

Returns:

  • (Boolean)

Examples:

mats = ModraUp.active_model.materials
mat = mats.add("Temp")
mats.remove(mat)

materials.purge_unused ⇒ ModraUp::Materials

Remove materials unused by live geometry and retained definitions.

Returns:

  • (ModraUp::Materials) self

materials.current ⇒ ModraUp::Material, nil

The current paint bucket material. Returns nil if no material is selected.

Returns:

  • (ModraUp::Material, nil)
Note: ModraUp extension. The official material dialog box often has default materials; here, it is nil when there is no current material.

Examples:

ModraUp.active_model.materials.current

materials.current=(material) ⇒ material

Sets the material used by the paint bucket. Use nil for the default material.

Parameters:

  • material (ModraUp::Material, nil)

Returns:

  • (ModraUp::Material, nil)

Examples:

mats = ModraUp.active_model.materials
mats.current = mats.add("Joe")

materials.add_observer(observer) ⇒ Boolean

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

Parameters:

  • observer (ModraUp::MaterialsObserver)

Returns:

  • (Boolean)

Examples:

ModraUp.active_model.materials.add_observer(ModraUp::MaterialsObserver.new)

materials.remove_observer(observer) ⇒ Boolean

Remove material table observers.

Parameters:

  • observer (ModraUp::MaterialsObserver)

Returns:

  • (Boolean)

Examples:

mats = ModraUp.active_model.materials
obs = ModraUp::MaterialsObserver.new
mats.add_observer(obs)
mats.remove_observer(obs)