ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::AttributeDictionary

Inherits:
ModraUp::Entity show all
Includes:
Enumerable

Overview

A set of key-value pairs. Values are written with their Ruby type preserved. The Hash must be converted to a string using JSON.generate in Ruby before writing. DC data is typically found under "dynamic_attributes".

Examples:

defn = ModraUp.active_model.definitions.add("DC")
inst = ModraUp.active_model.entities.add_instance(defn)
inst.set_attribute("dynamic_attributes", "lenx", "10")
inst.attribute_dictionaries.each { |d| d.each { |k, v| puts "#{k}=#{v}" } }

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.
  • #add_observer(observer) ⇒ Boolean
    Register a ModraUp::EntityObserver. Adding the same object a second time returns false. Locking, property, and material changes will dispatch an onChangeEntity event.
  • #remove_observer(observer) ⇒ Boolean
    Remove the entity observer.
  • #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_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

dictionary.name ⇒ String

Dictionary name.

Returns:

  • (String)

Examples:

defn = ModraUp.active_model.definitions.add("DC")
inst = ModraUp.active_model.entities.add_instance(defn)
inst.set_attribute("dynamic_attributes", "a", "1")
inst.attribute_dictionaries.each { |d| d.name }

dictionary.each {|key, value| } ⇒ selfdictionary.each ⇒ Enumerator

Iterate through keys and values. Value types are the same as when written.

Returns:

  • (self, Enumerator)

Yields:

  • @yieldparam key [String]
  • @yieldparam value [Object]

Examples:

defn = ModraUp.active_model.definitions.add("DC")
inst = ModraUp.active_model.entities.add_instance(defn)
inst.set_attribute("dynamic_attributes", "lenx", "10")
inst.attribute_dictionaries.each { |d| d.each { |k, v| } }

dictionary.each_pair {|key, value| } ⇒ selfdictionary.each_pair ⇒ Enumerator

An alias for each.

Returns:

  • (self, Enumerator)

Yields:

  • @yieldparam key [String]
  • @yieldparam value [Object]

Examples:

defn = ModraUp.active_model.definitions.add("DC")
inst = ModraUp.active_model.entities.add_instance(defn)
inst.set_attribute("dynamic_attributes", "lenx", "10")
inst.attribute_dictionaries["dynamic_attributes"].each_pair { |k, v| }

dictionary.attribute_dictionaries ⇒ ModraUp::AttributeDictionaries, nil

A collection of nested dictionaries. It is nil when there are no nested dictionaries. Nested dictionaries are currently not persistent.

Returns:

  • (ModraUp::AttributeDictionaries, nil)
Note: ModraUp extension. Nested dictionaries have not been saved; always nil.

Examples:

defn = ModraUp.active_model.definitions.add("DC")
inst = ModraUp.active_model.entities.add_instance(defn)
inst.set_attribute("dynamic_attributes", "lenx", "10")
inst.attribute_dictionaries["dynamic_attributes"].attribute_dictionaries  #=> nil

dictionary[key] ⇒ Object, nil

Retrieve the value by key. The type will be the same as when it was written.

Parameters:

  • key (String)

Returns:

  • (Object, nil)

Examples:

defn = ModraUp.active_model.definitions.add("DC")
inst = ModraUp.active_model.entities.add_instance(defn)
inst.set_attribute("dynamic_attributes", "lenx", "10")
inst.attribute_dictionaries["dynamic_attributes"]["lenx"]  #=> "10"

dictionary[key] = value ⇒ value

Write the key-value pair. The type written will be the type read back.

Structural data should be passed as a string after generating it with JSON.generate.

Parameters:

  • key (String)
  • value (Boolean, Integer, Float, Length, String, Time, Array, Geom::Point3d, Geom::Vector3d, nil)

Returns:

  • (Object)

Raises:

  • [TypeError] Hash, Symbol values, entities, etc., are unsupported types

Examples:

defn = ModraUp.active_model.definitions.add("DC")
inst = ModraUp.active_model.entities.add_instance(defn)
inst.set_attribute("dynamic_attributes", "a", "1")
inst.attribute_dictionaries["dynamic_attributes"]["a"] = "2"

dictionary.keys ⇒ Array<String>

All keys.

Returns:

  • (Array<String>)

Examples:

defn = ModraUp.active_model.definitions.add("DC")
inst = ModraUp.active_model.entities.add_instance(defn)
inst.set_attribute("dynamic_attributes", "lenx", "10")
inst.attribute_dictionaries["dynamic_attributes"].keys