sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    DC / Dictionary Interaction

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 2 Posters 270 Views 2 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by Dan Rathbun

      Split off from: http://forums.sketchucation.com/viewtopic.php?f=180&t=25386

      @pauline01 said:

      up

      up??

      I don't think you have solved your problem.
      [REVISED - 28 JAN 2010]

      You can use:
      %(#BF0000)[*object*.get_attribute('*MyDico*', *numfriend*)] %(#BF0000)[*object*.set_attribute('*MyDico*', *numfriend*, *namefriend*)]

      OR also:
      %(#BF0000)[*mod* = Sketchup.active_model *obj* = *mod*.selection[0] *dict* = *obj*.attribute_dictionary('*MyDico*')] %(#008000)[# to get attribute values] %(#BF0000)[*namefriend* = *dict*[*numfriend*]] %(#008000)[# to set attribute values] %(#BF0000)[*dict*[*numfriend*]=*namefriend*]

      To deletedictionary key/value pairs, DO NOT USE:
      %(#BF0000)[*object*.set_attribute('*MyDico*',*numfriend*,nil)]

      instead USE:
      %(#BF0000)[*object*.delete_attribute('*MyDico*',*numfriend*)]
      OR:
      %(#BF0000)[*dict*.delete_key(*numfriend*)]

      To load your menu from a dictionary, DO NOT write your own loop.
      This can result in a 'fencepost error', and other errors
      _(where iterator vars are off by 1 ..etc.)
      USE the built-in AttributeDictionary iterator methods .each, .each_key and .each_pair, like this:

      %(#BF0000)[*dict*.each_pair do |*numfriend*, *namefriend*|] %(#F0F0F0)[_]%(#BF0000)[*menu*.add_item("Delete a Friend(#{*namefriend*.to_s})"){ *dict*.delete_key(*numfriend*) } end]%(#008000)[# dict iterate]
      __

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        @dan rathbun said:

        DO NOT USE:
        object.get_attribute
        object.set_attribute
        THEY ARE BUGGED AND DO NOT WORK

        Don't see where you got that from. I use them often and have no issues with them.

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

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          @thomthom said:

          @dan rathbun said:

          DO NOT USE:
          object.get_attribute
          object.set_attribute
          THEY ARE BUGGED AND DO NOT WORK

          Don't see where you got that from. I use them often and have no issues with them.

          They 'seem' to work. You can set a value, and then get it back. Which means it's saved 'someplace' in memory. But if you at the same time try to get a value, that was set thru the object.set_attribute, using the dict['key'] it's not in the dictionary. And dict.size returns 0. So there's some kind of 'break in the link' there.

          I'll do more testing tomarrow, perhaps if I save the file, and reopen it, things will get 'linked' back up.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            ` model = Sketchup.active_model

            #Sketchup::Model:0x84e3900
            model.set_attribute('test', 'foo', 'bar')
            bar
            model.get_attribute('test', 'foo')
            bar
            d = model.attribute_dictionaries['test']
            #Sketchup::AttributeDictionary:0xb66c360
            d.each { |k,v| puts "#{k} - #{v}" }
            foo - bar
            nil
            d.length
            1
            d['foo']
            bar`
            I'm not seeing that behaviour.

            Mind you, what is the object type of the value you try to set. The dictionaries doesn't handle all types. Strings, Numerics and Booleans etc. Not custom classes or Sketchup Classes.

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

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @dan rathbun said:

              turned off the DC extension (which WILL make all the dictionary methods no longer work except .name)

              ?
              but the attribute methods existed in SU6 as well, right? then there was no DC... ❓

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

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @dan rathbun said:

                @thomthom said:

                @dan rathbun said:

                DO NOT USE:
                object.get_attribute
                object.set_attribute
                THEY ARE BUGGED AND DO NOT WORK

                Don't see where you got that from. I use them often and have no issues with them.

                They 'seem' to work. You can set a value, and then get it back. Which means it's saved 'someplace' in memory. But if you at the same time try to get a value, that was set thru the object.set_attribute, using the dict['key'] it's not in the dictionary. And dict.size returns 0. So there's some kind of 'break in the link' there.

                I'll do more testing tomarrow, perhaps if I save the file, and reopen it, things will get 'linked' back up.

                OK the test you wrote is the same one I had done at the console. I did it again and everything is fine.

                So I'm happy to say it was just my own confusion. Either I corrupted SU memory testing a plugin or had turned off the DC extension (which WILL make all the dictionary methods no longer work except .name)

                .. my Bad ! (OK, I revised my previous post.)
                _

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @thomthom said:

                  @dan rathbun said:

                  turned off the DC extension (which WILL make all the dictionary methods no longer work except .name)

                  ?
                  but the attribute methods existed in SU6 as well, right? then there was no DC... ❓

                  I dunno, Thom, but that's what happens.

                  Perhaps the way they wrote the DC it's so integrated now that, it's really part of the program, not really an extension. (I have a mind to comment out all the Extension code in the DC registration script, and just make it load always. That way I won't ever accidentely ever turn it off again.)

                  It happened because, I was tracking down the source of JJ's eval warnings the day before I posted here. See:
                  (eval): warnings are caused by Dynamic Components extension!
                  and I guess I forgot to turn the DC back on.

                  I'm happy to be wrong, and not have more bugs in the API to deal with!
                  _

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • thomthomT Offline
                    thomthom
                    last edited by

                    hm... I need to look into this. Check what happens with my scripts under SU6...

                    Pauline: sorry for going a bit off topic. Maybe it's best if I split these last couple of posts into a new thread? Ok, Pauline & Dan?

                    Edit: Now split of - as you can see.

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

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

                    Advertisement