Attribute dictionnary
-
Hi all !
Juste one little question : How can I find name of a dictionary in ruby ?
I tried that :ent.attribute_dictionaryBut a name is required... And I don't know dictionnary name...
Thank you !
-
Matt,
You can get the dictionnary, via the model (either existing or to create a new one)
model = Sketchup.active_model attributedictionary = model.attribute_dictionary name, createThis is described in the Ruby doc.
Be careful to choose your own name to avoid interfering with other dictionaries used by some scripts.
Fredo
-
Salut Fredo !
Ce que je veux c'est regarder les dictionnaires existants, par en créer un...

I just want to get information from an existing dictionary, not to create it !Et pour regarder, il faut connaitre le nom....
Merci à toi !
-
If you want to see what dictionaries are already on an entity use:
model = Sketchup.active_model entity = model.selection[0] # get selected entity entity.attribute_dictionaries.each { |dict| puts dict.name}If you want to see what attributes are stored on a component definition, use:
model = Sketchup.active_model entity = model.selection[0] entity.definition.attribute_dictionaries.each { |dict| puts dict.name} -
Matt,
Then, you just need to loop through the collection of dictionaries of the model
model = Sketchup.active_model list_dico = model.attribute_dictionaries # List of all dictionaries list_dico.each do |dico| dico.each_pair do |key, value| #do what you want with the key and value end end -
Salut,
Attr dictionaries list (attached to model, not to a particular entity), along with keys and corresponding values, output in the console:
def list_ad ads=Sketchup.active_model.attribute_dictionaries if ads ads.each do |ad| puts "Dict; " + ad.name + "\n" puts ad.keys puts ad.values end else UI.messagebox("No dicts in model") end endDicts are hash, thus Hash.methods can be used.
Les dicts sont des Hash. Les méthodes de Hash peuvent donc être utilisées. -
Ok thank you all for your excellent answers !
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement