Attribute dictionary is not holding the data

Hi there,

I am trying to store some data into an attribute dictionary, adding the items to it, and trying to retrieve the data back but I am getting nil values. Below is the sample code describing what I am trying to do.

module Test

def initialize()
  @@groups_dictionary  = Sketchup.active_model.attribute_dictionary('groups_dictionary', true)
  @@groups_dictionary["groups"] = []

def add_new_group(group_name)
      new_group = { :value => group_name, :text => group_name }
      groups = @@groups_dictionary["groups"]
      groups << new_group
      @@groups_dictionary["groups"] = groups #@@groups_dictionary["groups"]  seems to be immutiable so I am gettting the current values and rewriting

def get_all_groups()
    groups = @@groups_dictionary["groups"] # here @@groups_dictionary["groups"]  is returning [nil]


What am I doing wrong, any points to achieve this?

adding @tt_su and @DanRathbun

You might wanna check aerilus Attribute inspector, available in the extension warehouse.
It might already do what you are trying to do.
And you could examine if the data is attached to the model, Definition or instance.

1 Like

I second this, I would check the data stored. The SU team also have a helper extension for that: Extension | SketchUp Extension Warehouse

Can you include in your snipped logic on how you use these methods.

Btw, I see you have a def initialize in a module. initialize is a special method when used in classes. Did you intend for this to be a class instead of a module?

module Test this clashes with Ruby’s own Test name. I’d recommend using module Example to ensure no clashes.

1 Like

Also, use @variables unless you totally understand the quirks of @@variables.

1 Like