I am passing a Volume command to Rhino from a Rhino Python console. This is a sample code:
This results in a volume result being printed in the Rhino command line:
‘Volume = 4018.98077 (+/- 1e-06) cubic millimeters’
How to get the above message returned to the python code? I need to reuse it within the code. I have already tried doing it with the rs.SurfaceVolume() command, but it fails due to the surface being open, not closed. I have 2 naked edges in my geometry which I cannot get rid of and so I cannot close the surface. Increasing absolute tolerance did not help. For this reason, I must run rs.Command() rather than rs.SurfaceVolume.
Any thoughts much appreciated.
First of all be aware that the Volume command likely will not yield correct results with non-solid input.
below is a quick setup in python to get the combined volume of all (poly)surfaces
import rhinoscriptsyntax as rs
ids = rs.SelectedObjects()
total_volume = 0
for id in ids:
result = rs.SurfaceVolume(id)
if result: total_volume += result
You could also add code to collect if the result is None so you know how much and for what objects no Volume is calculated.
Does this help?
Thank you very much for your reply. I am aware that the Volume command result may not be valid. In my case, the opening in the surface is tiny, and the error tends not to be too big. I am double checking my results at a later stage so that is not a problem.
I only have one polysurface in my project so the method you proposed does not solve my problem. It is a nice way of getting a feedback but after all I do need the volume to be calculated for that open polysurface.
Is there any way to return the Volume command message back to the python code?
Why would you not fix the surface?
It seems like
RhinoApp.CommandHistoryWindowText should contain the information you need…
RhinoApp.CommandHistoryWindowText worked well for me and solved the issue. Thank you for your help.