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

    Attribute dictionary in callback

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 2 Posters 328 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.
    • K Offline
      kdasilva
      last edited by

      Hello I had hopefully a quick question that I cant seem to find the answer,

      I am having trouble getting information from an attribute dictionary i created in a different callback, for example:

      
      elsif diagnosis_selection.definition == comp_def_R
      	new_R_dictionary = model.set_attribute "repairdictionary", diagnosis_selection.to_s, description
      	print_R_dictionary = model.get_attribute "repairdictionary", diagnosis_selection.to_s
      	js_update_command = "UpDateDiagnosis(\""+ print_R_dictionary +"\")"
      	web_dialog.execute_script(js_update_command)
      
      

      (description is text passed through the webdialog, assigned as an attribute to a instance where its name being the key)

      However when trying to access the same attribute dictionary in a separate callback:

      
      print_R_dictionary = model.get_attribute "repairdictionary", diagnosis_selection.to_s
      puts print_R_dictionary
      
      

      I keep getting nil, when having the same instance selected. how I can I make two seperate callback read the same attributes. I have done it in other parts of my app, however there the attributes is initialized outside of the callbacks...but here I cant create them until I have the keys and this happens in the first callback....

      any help appreciated...I I'm presenting at a conference across the country on the project and urban design visualization so i'm hopping to have as much working as I can.

      Cheers~
      Korbin

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        It's
        model.set_attribute("DictionaryName", "keyname", value)
        and
        model.get_attribute("DictionaryName", "keyname", default)

        The 'dictionary' name should be a simple string, so 'repairdictionary' is fine [I'd usually start with an uppercase letter though]
        The 'key' name should again be a simple string starting with a lowercase letter - NOT as you might have - so try diagnosisselection=diagnosis_selection.to_s.downcase.gsub(/[^a-z0-9]/,'') etc etc - as can you really be sure is it always returning a suitable string? do it outside of the ...set_attrib... with a test to only do the ...set_attrib... if it's OK like - .....set_attrib... if diagnosisselection.class==String and diagnosisselection.length>0
        The 'value' can be an integer, a decimal-number, a string, a boolean [true/false] or an array of any of these.
        What is 'description' ? a string ??

        You speak of assigning things to an instance - currently your code is adding the key/value to a model attribute-dictionary ? No instances are involved 😕

        Perhaps to need to explain it better is 'words' rather than code snippets that don't tell the whole story.

        TIG

        1 Reply Last reply Reply Quote 0
        • K Offline
          kdasilva
          last edited by

          @tig said:

          Perhaps to need to explain it better is 'words' rather than code snippets that don't tell the whole story.

          sure~

          Basically the user starts by using a icon to place and size instances around the map, [this part works good]

          then they are supposed to be able to select an instance write a description of (ie why it was placed their etc) and then push a button in the webdialog that takes the selection, and the text in the (the description variable you asked about) and should then store the description as an attribute, so later you can select a instance, push "view" and the description can be read in the webdialog GUI. There are four different component definitions, so the code takes the selection, checks which definition it has, and then should add or replace the attribute assigned to the the key (the particular instance)

          should I perhaps be making the dictionary for the definitions themselves?? But how do I create a dictionary without first having a key->attribute to initialize it with.....hmm I think I just confused myself more...so I dont know if that description helped

          thanks!
          Korbin

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            You CAN set/get attributes for the model, a definition, an instance or any other 'entity' for that matter...

            So you need to decide the best way to do what you want...

            If the user is selecting an instance and giving it a 'description' you can set that as an attribute for the instance itself. To get the values later set up something that does this type of thing model.definitions.each{|defs|d.instances.each{|i|###code to check the type and attributes etc###}}
            IF certain things are true you can then add those as variables /a to an array etc...
            OR if you know the few components that you want to check then just limit your check to those... by name compo1="myCompoA" etc... and the collection is insts=[] [compo1,copmo2,compo3,compo4].each{|cname| arr=[]; model.definitions[cname].instances.each{|i| arr << i if i.get_attribute==???}; insts << arr}
            Now 'insts' contains all of the matching instances...

            TIG

            1 Reply Last reply Reply Quote 0
            • K Offline
              kdasilva
              last edited by

              @tig said:

              You CAN set/get attributes for the model, a definition, an instance or any other 'entity' for that matter...

              So you need to decide the best way to do what you want...

              If the user is selecting an instance and giving it a 'description' you can set that as an attribute for the instance itself. To get the values later set up something that does this type of thing model.definitions.each{|defs|d.instances.each{|i|###code to check the type and attributes etc###}}
              IF certain things are true you can then add those as variables /a to an array etc...
              OR if you know the few components that you want to check then just limit your check to those... by name compo1="myCompoA" etc... and the collection is insts=[] [compo1,copmo2,compo3,compo4].each{|cname| arr=[]; model.definitions[cname].instances.each{|i| arr << i if i.get_attribute==???}; insts << arr}
              Now 'insts' contains all of the matching instances...

              I dont understand why I need all of these arrays etc...I was thinking I just needed a dictionary I can save to the model, or that particular layer...which inside simply has a key (the instance unique identifier, ie name) and an associated attribute (the description), from this if I wanted all of the descriptions I can just grab the whole dictionary and iterate through it....

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                @kdasilva said:

                @tig said:

                You CAN set/get attributes for the model, a definition, an instance or any other 'entity' for that matter...

                So you need to decide the best way to do what you want...

                If the user is selecting an instance and giving it a 'description' you can set that as an attribute for the instance itself. To get the values later set up something that does this type of thing model.definitions.each{|defs|d.instances.each{|i|###code to check the type and attributes etc###}}
                IF certain things are true you can then add those as variables /a to an array etc...
                OR if you know the few components that you want to check then just limit your check to those... by name compo1="myCompoA" etc... and the collection is insts=[] [compo1,copmo2,compo3,compo4].each{|cname| arr=[]; model.definitions[cname].instances.each{|i| arr << i if i.get_attribute==???}; insts << arr}
                Now 'insts' contains all of the matching instances...

                I dont understand why I need all of these arrays etc...I was thinking I just needed a dictionary I can save to the model, or that particular layer...which inside simply has a key (the instance unique identifier, ie name) and an associated attribute (the description), from this if I wanted all of the descriptions I can just grab the whole dictionary and iterate through it....

                Of course you can... I don't now how often you want to interrogate things etc... saving things to an array is just one way of getting lists of things to use later... if you have a simpler or quicker way use that...
                I was really trying to show you how to iterate collections of things and get values in a form to use later.

                TIG

                1 Reply Last reply Reply Quote 0
                • K Offline
                  kdasilva
                  last edited by

                  I appreciate all your help, but I am still unsure on why my get get_attribute method would return nil in a different call back? is there a scope issue I am not accounting for? the get_attribute works within the same callback so I am lead to believe that the instance name is working as a key...

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    @kdasilva said:

                    I appreciate all your help, but I am still unsure on why my get get_attribute method would return nil in a different call back? is there a scope issue I am not accounting for? the get_attribute works within the same callback so I am lead to believe that the instance name is working as a key...

                    Did you check that the 'key' was acceptable ?
                    You were setting the attribute for the model etc ?
                    Rather that try an do it directly in the call_back make a method and run it with self.callback1() etc...
                    What you are trying to do is relatively straightforward ... just break it into logical steps......

                    TIG

                    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