• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Adding dynamic attributes to multiple objects

Scheduled Pinned Locked Moved Developers' Forum
19 Posts 4 Posters 1.1k Views
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.
  • N Offline
    NewGuy
    last edited by 4 Jun 2010, 18:03

    Is there a way to add attributes to a group's "dynamic_attributes" dictionary? I am try this concept below:

    selection[0].attribute_dictionary("dynamic_attributes").keys.push "attributename"

    I am trying to do this because I want to add the same attribute and sometimes the same value to multiple groups and the component attributes interface only lets you do one object at a time.

    Thanks,
    NewGuy

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 4 Jun 2010, 18:19

      You want to add an attribute to all instances of a definition?

      Then you can add the attribute to the definition instead of the instances. Just make sure to remember to check the definition whenever you access it.

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • N Offline
        NewGuy
        last edited by 4 Jun 2010, 18:26

        I think set_attribute is what I was looking for.

        1 Reply Last reply Reply Quote 0
        • N Offline
          NewGuy
          last edited by 4 Jun 2010, 20:55

          Is there a way to toggle the attribute so that "Users can edit as a textbox" in the Component Attributes panel?

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by 4 Jun 2010, 21:01

            That's all controlled by specially named attributes in the "dynamic_attributes" dictionary. If you have Pro, you can edit them in the Attributes Editor, so I'm assuming you are using the Free version?

            Hi

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by 4 Jun 2010, 21:04

              Here is a DC with a single editable Textbox for an attribute named Color. Maybe it'll help


              lemon_box.skp

              Hi

              1 Reply Last reply Reply Quote 0
              • N Offline
                NewGuy
                last edited by 7 Jun 2010, 15:25

                I am using Pro but I am more interested in mass dumping attributes to objects that users using Pro can see. I am able to add the attributes using set_attribute but they show up as "User cannot see this attribute". How can I add an attribute so a user can see it or edit it?

                Thanks,

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Jim
                  last edited by 7 Jun 2010, 15:32

                  You need to inspect the "dynamic_attributes" dictionary. It uses meta-attributes that begin with an underscore to store meta-data about other attributes, such as if it has an entry in the Options dialog.

                  So for the model I attached previously, there is an attribute named "color", but also several that begin with "_color". These are what control how it appears in the Options dialog. I don't know the details of what all the meta-attributes are or do. You probably will need to reverse engineer them.

                  Hi

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by 7 Jun 2010, 15:38

                    So I was able to add a "Quantity" textbox to the user options dialog with the following code:

                    ad = selection[0].definition.attribute_dictionaries["dynamic_attributes"]
                    
                    ad["quantity"] = "1"
                    ad["_quantity_access"] = "TEXTBOX"
                    ad["_quantity_formlabel"] =  "Quantity"
                    

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      thomthom
                      last edited by 7 Jun 2010, 15:39

                      Didn't realise one could set attributes like that.

                      Thomas Thomassen — SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        Jim
                        last edited by 7 Jun 2010, 15:41

                        Yeah, it wouldn't actually be too hard to create a DC editor for non-pro users.

                        I was considering doing a specialized one just for animating doors and windows.

                        Hi

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          thomthom
                          last edited by 7 Jun 2010, 15:48

                          I meant the way you added items to AttributeDictionaries. I've always used the explicit set_attribute method.

                          Thomas Thomassen — SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          1 Reply Last reply Reply Quote 0
                          • J Offline
                            Jim
                            last edited by 7 Jun 2010, 15:53

                            set_attribute and get_attribute are probably better to use in the long run, if changes were ever made internally they would likely still work.

                            Hi

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              thomthom
                              last edited by 7 Jun 2010, 15:54

                              heeeey? where was that comment of being able to remove attributs using set_attribute? mind trixies!

                              Thomas Thomassen — SketchUp Monkey & Coding addict
                              List of my plugins and link to the CookieWare fund

                              1 Reply Last reply Reply Quote 0
                              • J Offline
                                Jim
                                last edited by 7 Jun 2010, 15:57

                                It was wrong! I was thinking of something else. There was what I thought an odd way to delete an attribute, but I think it was an odd way to delete the entire dictionary.

                                Hi

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  thomthom
                                  last edited by 7 Jun 2010, 15:59

                                  set_attribute can potentially kill the whole dictionary??

                                  Thomas Thomassen — SketchUp Monkey & Coding addict
                                  List of my plugins and link to the CookieWare fund

                                  1 Reply Last reply Reply Quote 0
                                  • J Offline
                                    Jim
                                    last edited by 7 Jun 2010, 16:02

                                    Ok, this is what I was remembering:

                                    delete_attribute can delete the entire dictionary if the value param is not used.

                                    http://code.google.com/apis/sketchup/docs/ourdoc/entity.html#delete_attribute

                                    @unknownuser said:

                                    Entity.delete_attributeSketchUp 6.0+

                                    The delete_attribute method is used to delete an attribute from an entity.
                                    
                                    If only the dictionary_name is given, then it deletes the entire AttributeDictionary. Otherwise, delete_attribute deletes the attribute with the given key from the given dictionary.
                                    

                                    Hi

                                    1 Reply Last reply Reply Quote 0
                                    • D Offline
                                      Dan Rathbun
                                      last edited by 7 Jun 2010, 23:58

                                      @jim said:

                                      Ok, this is what I was remembering:

                                      Entity.delete_attribute can delete the entire dictionary if the value param is not used.

                                      AGREED !

                                      There should have been (should be,) an explicit Entity.delete_dictionary method (even if it calls the other one with 'secret' parameters. Of course the safest way is to rename and then override the delete_attribute method, so only a call to a delete_dictionary method would do the deletion.
                                      Which may actually be how things work with delete_attribute, ie if num args == 1 then it calls the Entity.attribute_dictionaries.delete(arg) method. )

                                      I'm not here much anymore.

                                      1 Reply Last reply Reply Quote 0
                                      • N Offline
                                        NewGuy
                                        last edited by 8 Jun 2010, 14:46

                                        Guys,
                                        Thanks for your help! Great insight.

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

                                        Advertisement