• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Attribute dictionnary

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 4 Posters 571 Views 4 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    Matt666
    last edited by 25 Jul 2008, 13:08

    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 !

    Frenglish at its best !
    My scripts

    1 Reply Last reply Reply Quote 0
    • F Offline
      fredo6
      last edited by 25 Jul 2008, 15:11

      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

      1 Reply Last reply Reply Quote 0
      • M Offline
        Matt666
        last edited by 25 Jul 2008, 16:11

        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 !

        Frenglish at its best !
        My scripts

        1 Reply Last reply Reply Quote 0
        • A Offline
          Al Hart
          last edited by 25 Jul 2008, 16:24

          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}
          
          

          Al Hart

          http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
          IRender nXt from Render Plus

          1 Reply Last reply Reply Quote 0
          • F Offline
            fredo6
            last edited by 25 Jul 2008, 17:01

            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
            
            
            1 Reply Last reply Reply Quote 0
            • D Offline
              Didier Bur
              last edited by 25 Jul 2008, 21:53

              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.

              DB

              1 Reply Last reply Reply Quote 0
              • M Offline
                Matt666
                last edited by 29 Jul 2008, 11:48

                Ok thank you all for your excellent answers !

                Frenglish at its best !
                My scripts

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                1 / 1
                • First post
                  2/7
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement