Attribute dictionnary
-
Hi all !
Juste one little question : How can I find name of a dictionary in ruby ?
I tried that :ent.attribute_dictionary
But 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, create
This 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 end
Dicts 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 !
Advertisement