I said difficult, but not impossible…
First: as Rhino.EnableHistoryRecording() is implemented in vb Rhinoscript, below is a vb Rhinoscript that will turn History on (if it’s not already on) and then return it to its previous state when done. There is a small bug currently in Rhino.EnableHistoryRecording() but I was able to work around it.
Then there is a REAL kludge Python version which works around the non-implementation of rs.EnableHistoryRecording() by first executing the command History and then parsing the command line result. (I told you it was a kludge, just want to see if I could make it work). This will only work on English-speaking Rhinos, however… FWIW, just for fun…
'Script written by Mitch Heynick
'Version January 14, 2014
msg = "Pick a pair of curves to loft, or press Enter to exit"
commOpts = " _Type=_Normal _Simplify=_None _Closed=_No _Enter"
'check history state, turn on
prevHState = Rhino.EnableHistoryRecording(True)
'the following line is a bug workaround
If IsEmpty(prevHState) Then prevHState = False
'turn on history
crvs = Rhino.GetObjects(msg, 4,, True,,, 2, 2)
If Not IsArray(crvs) Then Exit Do
If Rhino.IsCurveClosed(crvs(0)) And Rhino.IsCurveClosed(crvs(1)) Then
Call Rhino.Command("-Loft _Enter" + commOpts, False)
ElseIf Not Rhino.IsCurveClosed(crvs(0)) And Not Rhino.IsCurveClosed(crvs(1)) Then
Call Rhino.Command("-Loft" + commOpts, False)
Call Rhino.Print("Cannot loft an open curve with a closed curve")
'return history to previous state
import rhinoscriptsyntax as rs
#parse the command line result
if ans=="Yes": return True
msg="Pick a pair of curves to loft, or press Enter to exit"
commOpts=" _Type=_Normal _Simplify=_None _Closed=_No _Enter"
if not histState: setHistFlag=False
if not crvs: break
#turn on history
if not setHistFlag:
rs.Command("_History _Record=_Yes _Enter",False)
if rs.IsCurveClosed(crvs) and rs.IsCurveClosed(crvs):
elif not rs.IsCurveClosed(crvs) and not rs.IsCurveClosed(crvs):
print "Cannot loft an open curve with a closed curve"
if not setHistFlag:
#turn history back off
rs.Command("_History _Record=_No _Enter",False)