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.
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 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…
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
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.
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…
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.
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 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))
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)