Rhino8中grasshopper的python脚本执行后,返回grasshopper界面即无响应

各位大神,如下脚本在rhino 8中的grasshopper新的python 3编辑器里执行,程序功能实现正常,但执行后返回grasshopper,grasshopper界面就无法拖动,也无法重新点击进入编辑器,请问如何解决?
test.gh (16.3 KB)

‘’'python

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
from Rhino import RhinoDoc as rr
import Grasshopper.Kernel as gk
import Grasshopper
import Rhino.DocObjects as rd
import System.Drawing as sd

def initalize_object():
    sc.doc = Rhino.RhinoDoc.ActiveDoc
    
    if not rs.IsLayer(layer): # 新增图层
        rs.AddLayer(layer)
        rs.LayerColor(layer,(255,0,0))
    
    # 提示用户选择图元
    objects = rs.GetObjects("请选择要拾取的图元(曲线或Brep)", preselect=True, select=True)
    if not objects:
        print("没有选择任何图元")
        return

    for geo in objects:
        # 检查图元是否是坏对象
        if rs.IsObject(geo):
            if rs.ObjectName(geo) == None or ("Invalid" not in rs.ObjectName(geo)):
                if rs.IsCurve(geo) ==True and rs.IsCurveClosed(geo) == False:
                    print ("This curve is open!",type(geo))
                    # closed_curve = rs.CloseCurve(geo)
                    # closed_curve = Rhino.Geometry.Curve.MakeClosed(rs.coercecurve(geo),0.01)
                    # print (closed_curve)
                    # sc.doc.Objects.Replace(geo, closed_curve)
                # 图元正常,改变图元图层、颜色、名称
                doc_object = rr.ActiveDoc.Objects.Find(geo)
                sc.doc = rr.ActiveDoc
                print(geo)
                rs.ObjectLayer(geo, layer)
                rs.ObjectColor(geo,color)
                rs.ObjectName(geo,str(geo))                
                # 图元正常,为图元添加用户自定义属性
                for i in range(len(user_key)):                    
                    rs.SetUserText(geo, user_key[i], default_value[i])
                print("This object initalized successfully!")
            
            elif "Invalid" in rs.ObjectName(geo):
                # 图元无效或坏对象,进行炸开和重组操作
                print ("This object is Invalid !")
                exploded_objects = rs.ExplodeCurves(geo,True)
                print (type(exploded_objects))
                if exploded_objects:
                    joined_object = rs.JoinCurves(exploded_objects,True) if rs.IsCurve(exploded_objects[0]) else rs.JoinSurfaces(exploded_objects, delete_input=True)
                    print (type(joined_object))
                    if joined_object[0]:
                        doc_object = rr.ActiveDoc.Objects.Find(joined_object[0])               
                        rs.ObjectLayer(joined_object[0], layer)
                        rs.ObjectColor(joined_object[0],color)
                        rs.ObjectName(joined_object[0],str(joined_object[0]))
                        # 为新图元添加用户自定义属性
                        for i in range(len(user_key)):
                            rs.SetUserText(joined_object, user_key[i], default_value[i])                       
                    else:
                        print("无法重新组合图元")
                else:
                    print("无法炸开图元")

        else:
            print("无效的选择")
    sc.doc = ghdoc

# 调用主函数
if Switch:
    initalize_object()

请在 Rhino 指令行执行 SystemInfo, 然后把弹出内容拷贝后粘贴回帖。
另外请私信回复一下你当前 Rhino 的授权码 (以 RH70或 RH80开头的一组字串)