Smart way to rename Attribute Dictionaries?

I want to rename an attribute dictionary (ad), but I have observed that the method #name can be used only for retrieving the name of the ad, and cannot be updated in the following way:

  model_ads = Sketchup.active_model.attribute_dictionaries
  ad = Sketchup.active_model.attribute_dictionary( "old_name" )
  ad.name = "new_name" # Code Breaks Here

The solution I’ve been using so far is retrieveng all the data related to the ad, deleting it, and adding a new one with a new name and same data, in the following way:

  data1 = ad['data1']
  data2 = ad['data2']
  data3 = ad['data3']
  model_ads.delete( ad )
  ad = Sketchup.active_model.attribute_dictionary( "new_name", true )
  ad['data1'] = data1
  ad['data2'] = data2
  ad['data3'] = data3

Is this the only way to perform it, or is there anything that I am missing?

Known issue I believe. Likely earlier threads on this in this category.
(When you’re in a forum category, the quick search menu will have a checkbox to limit the search to that category.)

Use Ruby iterator methods:

def rename_dict(dict,newname)
  copy = dict.parent.attribute_dictionary(newname,true)
  dict.each {|key,val| copy[key]= val }
  dict.parent.attribute_dictionaries.delete(dict)
  return copy
end

So in your module (or class) you could do:

new_dict = rename_dict(ad,"newname")

Did not find anything related in a quick search, sorry.

Because we had discussed this over at the SketchUcation forum, like 6 years ago:

http://sketchucation.com/forums/viewtopic.php?f=180&t=35474&hilit=rename+dictionary#p313000

This topic was automatically closed after 91 days. New replies are no longer allowed.