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

    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.
    • 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