Access command history from python

Dear,

How can I access the command history from python?

Does the command history contain all informations of then command (not only the name
of the command)?

Kind regards

Hi,

Does this give you what you want?

import rhinoscriptsyntax as rs
txt = rs.CommandWindow()

It’s a string that you’ll need to parse.
Alain

No, if you’re looking to reproduce the result of a command for example, you will not see anything in the command history like a mouse pick of a point, what objects were selected, etc. All it will give you is what the command line has reported back to you in serial order. It should more properly be called “CommandLineHistory”.

–Mitch

What I need is to get all necessary information to re-create the objects:

if I create a cylinder, and create a box than I do a union, I would like to get the 3 commands: cylinder,
box, and union along with the details (radius, position, height, length, …) to be able to recreate the
object.

Taoufik

When I run the python script I get an error: module object has no attribute CommandWindow

I am using Atom and Rhino5 on Mac

Taoufik

Yeah, it is rs.CommandHistory()

import rhinoscriptsyntax as rs
txt = rs.CommandHistory()
print txt

should work.

-Pascal

Hi

Where do I see the result of print? does Rhino has a console?

Taoufik

You can actually show the command history in Mac Rhino in the right sidebar as one of the panels. --Mitch

But the command history does not show the result of ‘print txt’, where do I find
the result of ‘print txt’?

Taoufik

With Python, any print statement will print to the “command line”. On Mac Rhino, that will only be one line to the tiny little lower left hand status bar, as Mac Rhino does not have a real command line per se. Therefore the last line is all you will see in that tiny space - unless you do something else. In order to see all of it you will either need to:

  1. Call the command CommandHistory to have the text in a separate window, or
  2. Open the command history panel in the right hand sidebar, or
  3. Save the text to a file in the script and open that.

–Mitch

I wrote the following but the out.txt file is empty:

import rhinoscriptsyntax as rs
txt = rs.CommandHistory()
f=open(‘out.txt’, ‘w’)
f.write(txt)
f.close()

Taoufik

Looks like you actually need a full path to the file for f.write() to work. --Mitch

Is this still applicable? Experiencing trouble trying to do this using Rhino 7 on Big Sur.

rs.CommandHistory()

Seems to return nothing, but due to poor interface on Mac it’s difficult to figure out whether it’s returning ‘’ or None. Have tried exactly how was written above, as well as this to just print directly:

print rs.CommandHistory()

Any help would be greatly appreciated, thanks!

It does indeed look like it is still broken/not implemented on Mac… I’ll see if we can fix that.
RH-62435 Command history : Not on mac

-Pascal

1 Like