# Module: EnfEditor::UserPropertyUtils

Included in:
  EEBrepEdge, EEBrepFace, EEBrepVertex, EEBrepVolume, EEComponent

Defined in:
  lib/enfeditor/core_ext/property_utils.rb

## Overview

Mixin module to handle user property

## Instance Method Summary collapse

- #create_user_property(key, value, type, subtype = "") ⇒ Object

  Create user property.

- #overwrite_user_property(key, new_value, new_type, new_subtype = "") ⇒ Object

  Overwrite user property.

- #user_properties ⇒ Array<EEUserProperty>

  Returns user properties of element.

## Instance Method Details

### #create_user_property(key, value, type, subtype = "") ⇒ `Object`

Create user property

Examples:

    # Create user property
    element.create_user_property('USER_KEY', '1',    :bool)          # 0 or 1
    element.create_user_property('USER_KEY', 'a',    :boolchar)      # one character string
    element.create_user_property('USER_KEY', '123',  :integer)       # integer string
    element.create_user_property('USER_KEY', '4.56', :real)          # double string
    element.create_user_property('USER_KEY', 'hoge', :text)          # text string
    element.create_user_property('USER_KEY', 'hoge', :text, 'hoge2') # text string

Parameters:

- key (`String`) —

  User property key

- value (`String`) —

  User property value

- type (`Symbol`) —

  Specify user property type from :bool, :boolchar, :integer, :real or :text.

- subtype (`String`) (defaults to: `""`) —

  User property subType (optional)

Since:

- 0.1.0.0

    222
    223
    224
    # File 'lib/enfeditor/core_ext/property_utils.rb', line 222

    def create_user_property(key, value, type, subtype = "")
      _create_user_property(key, value, type, subtype)
    end

### #overwrite_user_property(key, new_value, new_type, new_subtype = "") ⇒ `Object`

Overwrite user property. New property is created if user property with same key does not exist.

Examples:

    # Overwrite user property
    element.overwrite_user_property('PART_NO',   '123', :integer)
    element.overwrite_user_property('PART_NAME', 'hoge', :text)

Parameters:

- key (`String`) —

  User property key

- new_value (`String`) —

  Specify new user property value

- new_type (`Symbol`) —

  Specify new user property type from :bool, :boolchar, :integer, :real or :text.

- new_subtype (`String`) (defaults to: `""`) —

  Specify new user property subType (optional)

Since:

- 1.0.0.0

    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    # File 'lib/enfeditor/core_ext/property_utils.rb', line 243

    def overwrite_user_property(key, new_value, new_type, new_subtype = "")
      found = false
      self.user_properties.each do |prop|
        next unless prop.key == key
        found = true
        if prop._separate_element(self, true) # separate shared attributes
          self.create_user_property(key, new_value, new_type, new_subtype)
        else
          prop.value = new_value
          prop.type = new_type
          prop.sub_type = new_subtype if new_subtype != ""
        end
      end
      unless found
        self.create_user_property(key, new_value, new_type, new_subtype)
      end
    end

### #user_properties ⇒ `Array<EEUserProperty>`

Returns user properties of element

Examples:

    # Modify user property key, value and type
    element.user_properties.each do |user_prop|
      key   = user_prop.key      # => USER_KEY
      value = user_prop.value    # => 100
      type  = user_prop.type     # => :integer
    end

Returns:

- (`Array<EEUserProperty>`) —

  Returns user properties of element

Since:

- 0.1.0.0

    # File 'lib/enfeditor/core_ext/property_utils.rb', line 195