I want set custom attribute(string) with active model and save it but after close and reopen model this attribute not persist with model

  1. I am attempting to set attributes, for example, a string with a key-value pair, using the method “model.set_attribute()”. This way, I can retrieve that value when the active session is running.
  2. However, when I close the model and reopen it, the value does not persist with the saved model.
    3.After setting the property once, I would like to be able to retrieve the property whenever needed, even if the model is closed and reopened.

here is ruby script :

require 'sketchup'

module SketchUpDataLoad
  def self.set_string(input_string)
    # Get the current model
    model = Sketchup.active_model

    # Set a custom attribute with the input string
    model.set_attribute('SketchUpDataLoad', 'ModelInfo', input_string)
  end

  def self.get_string
    # Get the current model
    model = Sketchup.active_model

    # Retrieve the custom attribute
    return_string = model.get_attribute('SketchUpDataLoad', 'ModelInfo')

    # Return the result
    return_string 
  end
end

Thank you in advance for help

maybe an obvious question or two - but based on the example you provided

  • did you manually check attributes to see it was set?
  • is there an attribute type that needs to be used? text vs JSON etc
  • are you saving the model? :slight_smile:

Please correct your profile, there is no ‘free’ version of 23
Assuming you have a Pro version, then what you propose should work…
I just tried it and it works fine !
You need to use:

SketchUpDataLoad.set_string("abc")

to set it, then use:

SketchUpDataLoad.get_string

to get it later… it works if the model is saved and reopened later…
[provided that the module has been loaded]

Also remember to nest your module if your own name-space module so it’s separated from other code.

4 Likes

Thank you @TIG its working now.