DC component loading skp file, hidden problem


#1

Hello folks,

I have this component:

The number of the doors is changed between 2 and 3 in “component options” of DC. Everything is OK with that.

What I’m trying to do is a Tool that change the handle to another, imported from a skp file. To become something like this (The new handle is just to test the import of skp file):

But my code is generating a weird behavior about hidden formula.
If I have 2 doors all handles become hidden = true. But with 3 doors they become hidden = false.

What I’ve notice is, SU always assume the configuration of the last handle for all other ones.
My code:

module Gdm
  class Change
    def initialize(model)
      @model = model
      @file = File.dirname(__FILE__) + "/skp/puxador_barra_teste_naked.skp"
    end

    def activate
      @model.selection.each do |element|
        element.definition.entities.each do |ent|
          if ent.definition.name.start_with? 'puxador_perfil'
            new_definition = @model.definitions.load @file
            new_definition.set_attribute 'dynamic_attributes', '_lenx_formula',   ent.definition.get_attribute('dynamic_attributes', '_lenx_formula').to_s
            new_definition.set_attribute 'dynamic_attributes', '_leny_formula',   ent.definition.get_attribute('dynamic_attributes', '_leny_formula').to_s
            new_definition.set_attribute 'dynamic_attributes', '_lenz_formula',   ent.definition.get_attribute('dynamic_attributes', '_lenz_formula').to_s
            new_definition.set_attribute 'dynamic_attributes', 'copies',          ent.definition.get_attribute('dynamic_attributes', 'copies')
            new_definition.set_attribute 'dynamic_attributes', '_copies_formula', ent.definition.get_attribute('dynamic_attributes', '_copies_formula').to_s
            new_definition.set_attribute 'dynamic_attributes', '_hidden_formula', ent.definition.get_attribute('dynamic_attributes', '_hidden_formula').to_s
            ent.definition = new_definition
          end
        end
        $dc_observers.get_latest_class.redraw_with_undo element
      end
      @model.tools.pop_tool
    end
  end

  def self.change
    model = Sketchup.active_model
    tool = Change.new(model)
    model.tools.push_tool(tool)
  end
end

After applying this code all handles assume the same “dynamic_attributes”. And become like this:

The middle handles have a formula to become hidden when have 2 doors. Don’t know why the same formula is now in all handles, I was thinking about the reference’s variable, but doesn’t make sense for this code (or do?).

PS: ‘puxador_perfil’ in portuguese it’s like ‘handle’ in english. puxador = handle and ‘perfil’ it’s the model of the handle.