How Python scripts can be added to historical constructs

I’ve written a lot of small scripts in my work with py, but I don’t add history to them. There’s a simple example of adding history to a script plugin in c # on the website, but I don’t understand c # , can you give me a simple example of python, not one where Command calls the Rhino’s own Command, like how to add history to this little script

import rhinoscriptsyntax as rs
def jichuxian():
    curve= rs.GetObjects("Select curve", rs.filter.curve,True,True)
    if curve is None:
        return
    redraw = rs.EnableRedraw(False)
    if curve and len(curve)==1:
        if rs.IsCurveInPlane(curve)and rs.IsCurveClosed( curve):
            mt1=rs.CurveAreaCentroid(curve)
            mt=mt1[0]
        else:
            box=rs.BoundingBox(curve)
            line1=rs.AddLine(box[0],box[6])
            mt=rs.CurveMidPoint(line1)
            rs.DeleteObject(line1)
        surfers=rs.ExtrudeCurvePoint( curve, mt )
jichuxian()

Hi @cainiaocaib,

Rhino’s History history is command-based. That is, History-enabled commands store the connection between a command’s input geometry and the result so that when the input geometry changes, the result updates accordingly.

Being that History is command-based, it is not possible for a script to participate in History (other than to enable or disable its recording). You’ll need to write a Rhino command in a plug-in, in either C++ or C#.

Hope this helps.

– Dale

2 Likes