Write results (in this case volume) into an external text file

Command: _Box
First corner of base ( Diagonal 3Point Vertical Center ): 0,0,0
Other corner of base or length ( 3Point ):
Height. Press Enter to use width:
1 extrusion added to selection.
Command: Volume
Calculating volume… Press Esc to cancel
Volume = 41787.7356 (+/- 1e-05) cubic inches

I need to write the volume in the sample above to an external text file and then close the file. The file will be read later by a C++ program. If it’s easier to just write the whole line that’s fine, the volume can be stripped out in C++.

Many thanks for any advice!

Bo Gehring

Hi Bo - do you need to get a box volume only or select existing objects, or?

If it’s just a box that you want to set up interactively, then maybe it’s this simple, in a Python:

import Rhino

def test():

    rc,box = Rhino.Input.RhinoGet.GetBox(Rhino.Input.GetBoxMode.All, Rhino.Geometry.Point3d.Unset, 'one','two', 'three')

    if rc == Rhino.Commands.Result.Success:
        file = rs.SaveFileName('Export Volume', '*.txt|Text files||', extension = '.txt' )
    mFile= open(file,"w+")
    mFile.write (str(box.Volume))


Hi Pascal,

I use C++ to generate Rhino command scripts. The idea is to get the volume from a single object my program has already selected and put it where the C code can see it. The simple-minded way seemed to be write it into a file in Rhino and open that later in C.

Thanks for the quick response.


Hi Bo - you should be able to query the geometry directly - Rhino.Geometry.Brep.GetVolume(), for example.