Volume in liters?

Hi McNeel’ies
OK, so I know it’s an easy conversion, but it’s kinda strange that decimeters (and thus cubic decimeters, aka liters) isn’t available as a unit. Would it worth/hard adding dm³/liters to Volume (I ask, as I sit here designing water pitchers)? :slight_smile:
TIA, Jakob

Hi Jakob - decimeter is available as a unit here on Rhino 7 WIP:


-wim

Hi @wim
Ah, yes… it’s even in V6! I didn’t get that far down the list (since it should be in there between centimeters and meters!). But it still doesn’t show up as an option in Volume (unless you change the model units). I think it should!
-Jakob

2 Likes

Hi Jakob,
it is on youtrack for a while:
https://mcneel.myjetbrains.com/youtrack/issue/RH-32177

I guess that’s not completely identical, Jess, and I’ve added RH-58062.

[And I suppose RH-32177 is some sort of duplicate of the older RH-19658 (not visible to the public) that mentions volume units such as “Gallons, buckets, butts, drachms, firkins, gills, kilderkins, puncheons, scruples, milliliters, decaliters, or cups, pints, quarts, etc.”]
-wim

1 Like

:rofl:

I made this for you, maybe it fits the bill.
It calculates to Liters IF your unit system is mm, cm, dm or M.
And selects objects if they are not closed. It supports surfaces, polysurfaces and meshes. (not blocks etc… that can probably be added if needed)

### mm to liter calculation
### by Holo 2020

import rhinoscriptsyntax as rs

def volumecalculation(objs):
    vol = 0
    warning = ""
    isOpen = False
    for obj in objs:
        xVol = False
        if rs.IsMesh(obj):
            if rs.IsMeshClosed(obj):
                xVol = rs.MeshVolume(obj)
            else:
                rs.SelectObject(obj)
                isOpen = True
        elif rs.IsPolysurface(obj) or rs.IsSurface(obj):
            if rs.IsPolysurfaceClosed(obj) or rs.IsSurfaceClosed(obj):
                xVol = rs.SurfaceVolume(obj)
            else:
                rs.SelectObject(obj)
                isOpen = True
                
            
        else:
            rs.Sleep(0)
            
        if xVol:
            vol += xVol[0]
    
    if vol>0:
        units = rs.UnitSystem()
        if units == 2: ### mm
            vol = vol/1000000
        elif units == 3: ### cm
           vol = vol/1000
        elif units == 4: ### M
           vol = vol*1000
        elif units == 14: ### dm
           vol = vol ### do noting
        else:
            warning += " WARNING: - Unitsystem is not mm, cm, dm or M - "
    
    if isOpen:
        warning += " - Selected object(s) are not closed objects and were excluded - "
    
    
    print str(warning)+" - Total volume is "+str(vol)+" liter(s)"

objs = rs.GetObjects("Select objects for volume calculation",rs.filter.surface + rs.filter.polysurface + rs.filter.mesh, preselect=True)

if objs:
    volumecalculation(objs)

2 Likes

Funny, the subject of this post is Volume in liters?
but that’s the difference of practical and pragmatical :wink:

Hi Jørgen :slight_smile:
That’s really cool - Thanks a lot! Looking though this, makes programming seem so simple, although I know it’s not; but the logic is so wonderfully obvious.
Thanks again!
-Jakob

1 Like

Great, feel free to ask for adjustments. (It’s easy to recalculate to ml cl and dl if vol<L :slight_smile: )

Hi @Holo
I’m getting this error. I know it’s a tall order, but can you spot the error?
image

TIA, Jakob

Hi Jakob, there was a bug in the python coding here on discourse where the " ``` " was visible.
Just delete those from the code.
(I updated the text in the link above. We use those to be able to show a python script correctly)

1 Like