Adding Solid Volume to Attributes
-
@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 likeadd_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...
-
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
-
TIG
I think I know many on DC, but now you prove I need explore SU Ruby to go further in DC !
-
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?
-
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, I did as instructed.
- Create a text file called "add_DC_functions.rb"
- Copy code above
- Change file extension to .rb
- place file plugin folder (Should this be place in the Dynamic Component folder instead
- 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.
-
You can use volume() function in an atribute calculation just like facearea(), but it's not in the list, you must write it.
-
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... -
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.
-
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!
-
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,
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?
-
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.
-
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!
-
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
Advertisement