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

Adding Solid Volume to Attributes

Scheduled Pinned Locked Moved Dynamic Components
sketchup
18 Posts 6 Posters 16.4k 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.
  • O Offline
    Omarian
    last edited by 24 Mar 2013, 18:43

    Hi everyone, I am a new Sketchup user in Jamaica. I am trying to figure out how to add the volume display of a solid in the entity info dialogue box to a component attribute. Can anyone help?

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 24 Mar 2013, 19:02

      It needs to be a solid.
      [ xxx.manifold? == true]
      Why do you want to add it as an attribute ?
      You need to get a reference to it to get/set an attribute...
      When you will have the reference then you have easy access to its current volume anyway ?

      Let's say you select the instance... then
      instance = Sketchup.active_model.selection[0]
      Now to get its volume use
      volume = instance.volume
      This is always returned in cubic inches, so you will need to apply a 'factor' to convert it into your desired units if they are not that...

      Adding an attribute to an instance like this could be dangerous, because if it's edited later and its volume changes, the earlier attribute will remain as it was set earlier on giving the wrong data...

      TIG

      1 Reply Last reply Reply Quote 0
      • O Offline
        Omarian
        last edited by 24 Mar 2013, 19:57

        Thx TIG,

        I am trying to work out the cubic yards of concrete necessary to pour a walls and the associated cost. I have made the walls floor slabs solid components. As these components are adjusted I want the volume to adjust automatically using SU's internally generated volume calculations. Just as how I could use lenx to generate the length of a shape is there a way to call the volume calculation of a solid into an attribute calculation or formula?

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 25 Mar 2013, 09:27

          @omarian said:

          Thx TIG,

          I am trying to work out the cubic yards of concrete necessary to pour a walls and the associated cost. I have made the walls floor slabs solid components. As these components are adjusted I want the volume to adjust automatically using SU's internally generated volume calculations. Just as how I could use lenx to generate the length of a shape is there a way to call the volume calculation of a solid into an attribute calculation or formula?
          Copy paste this code into a file in the Plugins folder named something like add_DC_functions.rb, after a restart your DCs have an additional function available named 'volume'...
          Other users of your DC will get errors unless they also have that same .rb file loading...

          # add_DC_function.rb
          # extends DCs functions
          require('sketchup')
          require('dynamiccomponents.rb')
          if defined?($dc_observers)
            # Open SketchUp's Dynamic Component Functions (V1) class.
            # BUT only if DC extension is active...
            class DCFunctionsV1
              protected
              # DC Function Usage; =volume()
              # returns the instance's volume [cu"]
              if not DCFunctionsV1.method_defined?(;volume)
                def volume(a)
                  return @source_entity.volume
                end
              end
            end#class
          end#if
          

          You can any various additional customized functions to a DC in this manner... You must set an attribute that uses the =xxx() function as you would any other...

          TIG

          1 Reply Last reply Reply Quote 0
          • A Offline
            ArCAD-UK
            last edited by 25 Mar 2013, 11:02

            I have been looking at something similar for reporting areas. As TIG points out if you open and edit the shape without stretching the DC variables fail to update. The work around I found was to use "Interact" with the "on click" function carrying out one of the calculations e.g. SET( "myvariable", FACEAREA ("material")) which also seems to force an update of the other affected variables. Not sure if would work on TIG's volume but it might be worth a try.

            I still find I'm looking at the Entity Info window to double check the results πŸ˜•

            1 Reply Last reply Reply Quote 0
            • D Offline
              DareDevil
              last edited by 25 Mar 2013, 14:10

              πŸ‘ πŸ‘ πŸ‘ πŸ‘ TIG

              I think I know many on DC, but now you prove I need explore SU Ruby to go further in DC !

              1 Reply Last reply Reply Quote 0
              • O Offline
                Omarian
                last edited by 26 Mar 2013, 14:45

                TIG,

                This programming stuff is way above my head. I can't find the "add_DC_functions.rb" in the plugins folder. I am using SU8pro. Do I need a specific programme editor to open and write into ruby scripts? Can this be done from inside Sketchup?

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 26 Mar 2013, 17:47

                  There is not a file of that name. πŸ˜•
                  You must make a new file with that name in the Plugins folder.
                  Use Notepad.exe or another plain-text editor like Notepad++ to make the file.
                  A .rb file is just a .txt file with a different file-suffix.
                  You can set its associations to open with that application, it is not 'opened' by SketchUp, it's just 'read'...
                  SketchUp recognizes any .rb files within the Plugins folder by this suffix, and loads their contents automatically...
                  Once you have pasted the code-text into the file and saved the file into the Plugins folder, and you have restarted SketchUp, it should then auto-load the code and make that additional function available in your DCs thereafter...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • O Offline
                    Omarian
                    last edited by 27 Mar 2013, 05:16

                    TIG, I did as instructed.

                    1. Create a text file called "add_DC_functions.rb"
                    2. Copy code above
                    3. Change file extension to .rb
                    4. place file plugin folder (Should this be place in the Dynamic Component folder instead
                    5. Restart SU

                    After restart I cannot find the new function. Where and how is the new function accessed. Is it now part of the list of functions in SU attributes such as FACEAREA, or is it in the list where you find Lenz? How do I call this new "volume function" in a calculation.

                    All i want to do is to be able to manipulate/vary the thickness of walls and slabs to analyse the impact on overall cost. As I increase the volume of a component wall the cost of that component should adjust automatically. I really need help.

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      DareDevil
                      last edited by 27 Mar 2013, 07:36

                      You can use volume() function in an atribute calculation just like facearea(), but it's not in the list, you must write it.

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        TIG Moderator
                        last edited by 27 Mar 2013, 09:29

                        As DareDevil says...
                        The new .rb file you have made containing the function's code [that goes into the Plugins folder as instructed!] adds an additional function to the DC tool.
                        The new function does NOT appear in the list of standard functions, but if you use it as the instructions in the code block say... type in the function - =volume() that will be used and return the selected DC-instance's volume in cu". You simply need to apply conversion factor to it to convert into other units...
                        As explained the 'volume' function is only available to users of the DC who have the .rb loading, so if you want to pass on your DC to others you must also supply the .rb file...

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • O Offline
                          Omarian
                          last edited by 28 Mar 2013, 02:42

                          Ok guys, it worked beautifully. Thanks a million!

                          NEXT PROBLEM

                          I pay carpenters by running (lineal) feet to install form ply for pouring concrete walls. I want to calculate running feet along wall components and have them adjust dynamically as I vary walls. Lenx or leny does not work as walls bend and curve. I would have to make each wall a regularly shaped rectanglar component and then add all the length of the base lines in the wall. Is there a script that could do this or a plugin already built.

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            ArCAD-UK
                            last edited by 28 Mar 2013, 15:02

                            Simple maths, if you have the volume and divide by a constant dimension that gives the area, so assuming your curves are in a single direction divide the volume by the base area will give the linear dimension. This is where my reference to facearea() came from. The presence of holes will affect the calculation!

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              TIG Moderator
                              last edited by 28 Mar 2013, 15:25

                              Are you saying you have 'curved' DC walls ?
                              If so you must be doing some math-ca;cs to make them, from those the inside/outside radius and swept arc are knowable and their partial circumferences can be got - these are the linear lengths of curved shuttering etc for the two faces...
                              You are only supplying partial info, being more specific and perhaps providing some images etc would help us help you so much more easily...

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • O Offline
                                Omarian
                                last edited by 28 Mar 2013, 21:46

                                TIG,

                                I have attached the file with the first floor concrete walls for which I need to obtain running foot. I presently would have to dimension each wall inside and outside and manually add them to come up with total running foot. Is there a way the SU could report the total dimension of a component as distinct from lenx and leny dimensions. Could SU report the length of selected edges at the base running paralell or at an angle to zor y? Could it report the maximum length of every face it recognizes?


                                Concrete wall running foot problem.skp

                                1 Reply Last reply Reply Quote 0
                                • O Offline
                                  Omarian
                                  last edited by 30 Mar 2013, 02:23

                                  I was thinking, wouldn't it be so much easier in doing lineal measurement to "material" or colour an edge/line and have a function return the length of all coloured edges/lines,in much the same way the the FACEAREA command does? That would be so helpful. I could get the inner and outter running feet by merely colouring the walling footing edges. As I adjust the walls so would the measurements and all the calculations that reference them.

                                  1 Reply Last reply Reply Quote 0
                                  • P Offline
                                    pibuz
                                    last edited by 2 Feb 2021, 10:55

                                    Hi guys! I needed exactly this feature and I found this great tip from master TIG! Wonderful! Thanks!

                                    Now in 2021 you only have to update a tiny detail: in the script you have to point to "su_dynamiccomponents.rb" instead of "dynamiccomponents.rb", and it works great!

                                    WEB (ita) - https://filipposcarso.wixsite.com/ordinentropico

                                    1 Reply Last reply Reply Quote 0
                                    • simjoubertS Offline
                                      simjoubert
                                      last edited by 18 Mar 2021, 16:07

                                      Hello
                                      Thank you for this code which opens up nice perspectives for me, especially if I manage to debug the following situation!

                                      Sketchup does not offer the function to count the number of occurrences of a text string in a text.

                                      I have checked in the ruby window the following code and I get the expected result

                                      string = 'hello world'
                                      string.count('l')
                                      # This returns the integer 3 
                                      

                                      I want to implement a new function but I have the following error

                                      [wrong number of arguments (given 1, expected 2)]
                                      

                                      Here is my code that I added after the one from TIG

                                      # add_DC_function.rb
                                      # extends DCs functions
                                      require('sketchup')
                                      require('su_dynamiccomponents.rb')
                                      if defined?($dc_observers)
                                        # Open SketchUp's Dynamic Component Functions (V1) class.
                                        # BUT only if DC extension is active...
                                        class DCFunctionsV1
                                          protected
                                          # DC Function Usage; =volume()
                                          # returns the instance's volume [cu"]
                                          if not DCFunctionsV1.method_defined?(;volume)
                                            def volume(a)
                                              return @source_entity.volume
                                            end
                                          end
                                      	
                                      	    # DC Function Usage; =occurence(texte,texte recherche)
                                          # returns the number of the occurency of the string
                                          if not DCFunctionsV1.method_defined?(;occurence)
                                            def occurence(a, b)
                                              return a.count(b)
                                            end
                                          end
                                        end#class
                                      end#if
                                      

                                      Thank you for your help
                                      Simon

                                      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