Any way to see more command history?

I am running multiple Rhinoscripts which are very long in order to automate CNC toolpath generation using madCAM.

It would be very useful to me to be able to see a lot more command history than I’m currently seeing. Is there any way to change the command history limit?

Any hidden defaults for this?

I’ve taken the time to write good error checking feedback into my scripts, some of which take 30 to 40 minutes to execute, but I’m only able to see less than half of the command history I need in the command history window.

Hello - F2 will open the command history window, and you can in your script, from time to time spit out the current command history as well

(rs.CommandHistory() for example)

But if you are relying on lots of Rhino commands in a script, there may be more efficient ways to write the code as well.

-Pascal

1 Like

Thanks very much for your reply Pascal.

Can you confirm that there is no possible way to change the ~400 line limit in the command history window?

Otherwise I can try adding multiple rs.CommandHistory() and writing them to a text file.

Currently the only Rhino commands in my scripts are the madCAM commands, which are also the reason why the scripts take so long to execute. I can’t think of any way around this short of writing my own CAM system, which I’d rather not attempt at this point.

A big part of the problem is that each madCAM command has so many parameters that it uses about 30 lines of command history.

You could save the command history periodically to a file -
-CommandHistory _File "Filename" etc…

1 Like

Hi Leo - none that I know of, no.

-Pascal

1 Like

Ok too bad. Thanks for confirming.

I’ll experiment with saving the command history to a text file as you and Helvetosaur have suggested.

You can also use native Rhinoscript or rs.CommandHistory() to get the string periodically, keep a text file open and keep appending the strings to that…

1 Like

Well I am trying to write the command history to a text file but without success.

I suspect there is something very basic which I’m not understanding.

Here is my code which does everything correctly except append the command history string to the text file.

Call Main()
Sub Main()
	Call RecordCommandHistory()
End Sub


Function RecordCommandHistory()
	Dim strCommandHistory
	strCommandHistory = Rhino.CommandHistory()
	
	Dim arrCommandHistory(0)
	arrCommandHistory(0) = strCommandHistory
	
	'testing arrCommandHistory(0) shows that the command history string is being assigned correctly
	Rhino.MessageBox(arrCommandHistory(0))

	' note sstrCommandHistoryDocument has already been defined as a global string and is working correctly
	' however the command history is not being appended to this document as it should
	If IsNull(Rhino.WriteTextFile(sstrCommandHistoryDocument, arrCommandHistory, True)) Then
		'Return Error
		Rhino.Print "Rhino.WriteTextFile(sstrCommandHistoryDocument, arrCommandHistory, True) failed."
		RecordCommandHistory = False
		Exit Function
	End If
	
	'Return Success
	RecordCommandHistory = True
End Function

Can anyone tell me where I’m going wrong?

Hi Leo - It looks like the location on C is not writable on all cases - this seems to work (file exists on the desktop)


Dim sstrCommandHistoryDocument
sstrCommandHistoryDocument = "C:\Users\Pascal\Desktop\History.txt"


Call Main()
Sub Main()
	Call RecordCommandHistory()
End Sub


Function RecordCommandHistory()
	
	Dim arrCommandHistory
	arrCommandHistory = array(Rhino.CommandHistory() & vbCrLf & vbCrlf)
	
		If Not Rhino.WriteTextFile(sstrCommandHistoryDocument, arrCommandHistory, True) Then
		   'Return Error
		   Rhino.Print "Rhino.WriteTextFile(sstrCommandHistoryDocument, arrCommandHistory, True) failed."
		   RecordCommandHistory = False
		   Exit Function
	       End If
	
	'Return Success
	RecordCommandHistory = True
End Function

BTW, you might want to Rhino.ClearCommandHistory() after writing to the file so that you make sure to only get new stuff appended.

-Pascal

1 Like

Hi Pascal - Thanks very much for your reply.

I’ve tried copy/pasting your code and only changing the file path in sstrCommandHistoryDocument to an existing text file on my desktop.

Still not working, yet still the arrCommandHistory shows up correctly in a message box when I add Rhino.MessagBox(arrCommandHistory(0)) as an error checking mechanism.

Also in another part of my script I’m successfully appending text to a text file list of CNC cutter depths, so the WriteTextFile method is working correctly there, just not here where I’m trying to record the command history.

Hi Leo - I make a new, empty text document called History.txt, indeed the writing fails. However, if I type one character and save the document, subsequent runs of the script correctly add the command history…

-Pascal

1 Like

Hmm that’s strange. I’ve tried that and it’s still not working for me.

I also have an initialization script which creates the new text file automatically and saves the title of the Rhino file as the first line, after which the command history is supposed to be saved, but this doesn’t work either.

The strangest thing to me is that I’m using the same WriteTextFile method to append other strings in another text file and all of that is working perfectly.

It’s only when I try to append the Rhino.CommandHistory string using the WriteTextFile method that it fails.

Hi Leo - is this:

Closing the file when it’s done?

-Pascal

1 Like

Yes the text file is being closed after initialization.

In fact several of my tests have been able to append short strings to the text file correctly, just not the command history string.

For example: I’ve added a string “before test” to the array before the command history string, then another string “after test” after it.

Each time I run the scirpt the string “before test” is correctly appended to the text file, however neither the command history string nor the “after test” string are appended.

Function RecordCommandHistory()
	Dim arrCommandHistory(2)
	arrCommandHistory(0) = "before test"
	arrCommandHistory(1) = Rhino.CommandHistory()
	arrCommandHistory(2) = "after test"
	
	Rhino.Print "RecordCommandHistory:arrCommandHistory:Len = " & Cstr(Len(arrCommandHistory(1)))
	
	If IsNull(Rhino.WriteTextFile(sstrCommandHistoryDocument, arrCommandHistory, True)) Then
		'Return Error
		Rhino.Print "Rhino.WriteTextFile(sstrCommandHistoryDocument, arrCommandHistory, True) failed."
		RecordCommandHistory = False
		Exit Function
	End If
	
	'Return Success
	RecordCommandHistory = True
End Function

Could the length of the command history string be causing any problems? It is currently 4083 characters when I measure it with the Len() function. I thought the limit for string lengths is huge.

Ok I think I’m onto something. I just tried applying the Left() function to the command history string and just taking the first 25 characters.

Now the output being appended to the command history text file is behaving correctly.
Each run appends:

before test
(the first 25 characters of the command history string)
after test

So why is my script choking on the longer command history string?

When I search for the limit of string lengths in vbScript I find websites that say the limit is in the billions of characters.

Ok further testing reveals that the length limit for a string in this situation is 2046 characters.

Everything from 2047 characters and up results in the failure to append that array element and any following elements to the text file.

Is this a bug in the Rhino.WriteTextFile() command?

Do I now have to write code to split up the command history string into smaller chunks and add them to the array?

It would be great to parse the long command history string for newline characters and then have each line be its own array element. Not sure how to code that though.

Hi Leo - try splitting the command history into an array (per line) and feed that whole array into Rhino.WriteTextFile(). (instead of as one giant string)

Dim arrCommandHistory: arrCommandHistory = split(Rhino.CommandHistory(), chr(13))

-Pascal

1 Like

Yes!
That works perfectly.

Thanks so much for all of your help Pascal, and on a weekend too!

That’s fantastic customer service! :):+1:

Perhaps you want to try this grasshopper , you need to update by hand but you can publish to grasshopper panel the boolean button
(i don’t know ho to make the script refresh by itself)

command history text.gh (15.0 KB)

1 Like

Hello,
Is there a way to get the command history update in continuity, without having to click the button (no trigger component)?

Thank you