sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Report just one attribute

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 3 Posters 402 Views 3 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.
    • A Offline
      artofseeing
      last edited by artofseeing

      hi all,
      i'm working on the following script:


      require 'sketchup.rb'
      #----------------
      
      
      #---------------------
      def gewicht
         
        
      
       
        model = Sketchup.active_model
        selection=model.selection
        entity=selection.first
        entities=selection[1]
       
      
      attdict=entity.attribute_dictionary "dynamic_attributes"
      
       definitions = model.definitions
       
       component = definitions[0]
      
       
      #value = model.get_attribute "dynamic_attributes", "gewicht", 0
        
        
       keys=attdict.keys[-4]
      value=attdict.values[-4]
       
      
      #UI.messagebox [keys, "; ", value]
       UI.messagebox [component.name, " ;", "Einzel-Gewicht;", value, " ", "kg"]
       
      
       
       end
      
      
      
      
      
      
      #--------------------------------
      
      
      if( not file_loaded?("SINUS-gewichte.rb") )
        
        toolbar = UI;;Toolbar.new "SINUS"
        cmd = UI;;Command.new("SINUS") { 
           gewicht
           }
           cmd.small_icon = "weight.gif"
           cmd.large_icon = "weight.gif"
           cmd.tooltip = "Gewicht"
           cmd.status_bar_text = "Gewicht"
           cmd.menu_text = "Gewicht"
           toolbar = toolbar.add_item cmd
           toolbar.show
           
         end
      

      i set the key index to -4 because "gewicht" is the one key i need.
      any better way to retrieve a key by its name?

      but the script doesnt quite work yet the way i want it to.

      i want to do the following:

      selct one or more components i draged and dropped from my library.
      (they already have a "gewicht" key with corresponding value attached to them under the dictionary "dynamic_attributes"!)
      "gewicht" means weight by the way.

      now:

      i want a messagebox to show me the following:

      the single weight of each selected component
      the sum of weights of all selected.

      that's practically it.

      any suggestions?

      thanks πŸ˜„

      cheers.

      as long as there is a voyage away, there's always a journey back...

      http://artofseeing.carbonmade.com

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

        
        model=Sketchup.active_model
        ss=model.selection
        gewicht=0
        ss.each{|e|
          if e.class==Sketchup;;ComponentInstance
            gewicht=gewicht + e.definition.get_attribute("dynamic_attributes","gewicht",0)
          end#if
          # If the component definition has no gewicht then its gewicht = 0
          # Wenn die Komponente Definition hat keine gewicht dann seine gewicht = 0
        }
        UI.messagebox("Gesamtgewicht = " + gewicht.to_s + " kg")
        
        

        This should work?
        Diese Arbeit sollte?

        TIG

        1 Reply Last reply Reply Quote 0
        • A Offline
          artofseeing
          last edited by

          wow thanks for the qucik and helpful reply.

          when i select nothing its okay.

          iget this error in the console when i have a component selected:

          Error: #<TypeError: String can't be coerced into Fixnum>
          C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:13:in +' C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:13:in gewicht'
          C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:11:in each' C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:11:in gewicht'
          C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:30
          C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/SINUS-gewichte.rb:29:in `call'

          any suggestions?

          again, thanks πŸ˜„

          as long as there is a voyage away, there's always a journey back...

          http://artofseeing.carbonmade.com

          1 Reply Last reply Reply Quote 0
          • C Offline
            cjthompson
            last edited by

            I haven't actually tested this, but I'm guessing this should work

            @tig said:

            
            >     gewicht=gewicht + e.definition.get_attribute("dynamic_attributes","gewicht",0)
            > 
            

            to:
            gewicht=gewicht + e.definition.get_attribute("dynamic_attributes","gewicht",0).to_f

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

              If 'gewicht' is always a number it should add OK to the earlier version of itself...

              Maybe initially set gewicht=0.0 so it's a float rather than an integer ?
              Then use cjt's gewicht=gewicht + e.definition.get_attribute("dynamic_attributes","gewicht",0.0).to_f

              Try puts e.definition.get_attribute("dynamic_attributes","gewicht",0.0) inside the {} so that you see in the ruby console what it's doing...

              TIG

              1 Reply Last reply Reply Quote 0
              • C Offline
                cjthompson
                last edited by

                @artofseeing said:

                i want a messagebox to show me the following:

                the single weight of each selected component
                the sum of weights of all selected.

                that's practically it.

                do you want one messagebox with each weight and one with the sum, or do you want one with both the sum of the weights and each weight?

                1 Reply Last reply Reply Quote 0
                • A Offline
                  artofseeing
                  last edited by

                  actually, i need one messagebox with all weiths shown(sum and single),
                  as a checkup if it got all the data right.

                  then im gonna take what the messagebox has shown and save it first as a simple text file,
                  in the end even paste the data into cells of a scalc file where i can
                  estimate the final loads at certain points.
                  i.e.:
                  i have 10 lamps and 2 beamers and 4 loudspeakers hanging on a line of truss,
                  so i get all the weights of each part, and the sum.
                  this truss is i.e. hanging at 2 points, so i estimate half the final load to each point.

                  so in the end, its a load calculation, which, up to now, i always had to do by hand.

                  πŸ˜„

                  as long as there is a voyage away, there's always a journey back...

                  http://artofseeing.carbonmade.com

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    artofseeing
                    last edited by

                    got it!

                    the guess was right.

                    make all values and variables floats, and it works out.

                    i selected none> weight=0
                    i selected one> weight=6
                    i selected 2> weight=12

                    thanks guys:)

                    now to get also the single weights...

                    but i can do that.

                    as long as there is a voyage away, there's always a journey back...

                    http://artofseeing.carbonmade.com

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      artofseeing
                      last edited by

                      one more strange happening yet:
                      ijust found out that
                      the sum of weights i get is a rounded value.
                      for example:

                      a lamp has the value "15,4" for the key "gewicht".
                      if i report on that i get "15.0"

                      cant seem to figure out just why... πŸ˜•

                      as long as there is a voyage away, there's always a journey back...

                      http://artofseeing.carbonmade.com

                      1 Reply Last reply Reply Quote 0
                      • A Offline
                        artofseeing
                        last edited by

                        got it1
                        it was my error writing "15,4" instead of "15.4" into the value

                        πŸ˜„

                        as long as there is a voyage away, there's always a journey back...

                        http://artofseeing.carbonmade.com

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

                          @artofseeing said:

                          got it1
                          it was my error writing "15,4" instead of "15.4" into the value

                          πŸ˜„

                          German decimal points 1,2 == 1.2 !!! πŸ˜‰

                          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