Write File Python script freezes Grasshopper

Hello Everyone,

I am working on a Python script in Rhino 8 Grasshopper that exports objects from a list of specific layers into a separate .3dm file.
However, the current implementation freezes Grasshopper.

Here is the code I’m currently using:

import Rhino
import rhinoscriptsyntax      as rs
import scriptcontext          as sc
import os


if Start:
    sc.doc = Rhino.RhinoDoc.ActiveDoc
    f_path  = hely
    if not os.path.exists(f_path):
        os.makedirs(f_path)
        
    os.chdir(f_path)
    a_d = os.getcwd()

    rs.ZoomExtents()
    rs.UnselectAllObjects()
    fnit     = ""
    extt     = ".3dm"
    csendt   = " _Enter"

    lns  = rs.LayerNames()
    objs = list()
    for li in Layers:
        rs.LayerVisible(li,True)
        layobjs = rs.ObjectsByLayer(li)
        objs.extend(layobjs)
    rs.SelectObjects(objs)

    fnit = hely+fn
    cs="_-Export "+chr(34)+fnit+chr(34)+csendt

    siker = rs.Command(cs,False)
    if siker:
        print (fnit+" írása megtörtént")
    else:
        print (" HIBA az "+fn+" írásnál!")

    rs.UnselectAllObjects()
    sc.doc = ghdoc

Does anyone have an idea how to fix this issue?
Any suggestions or corrections would be greatly appreciated!

Thanks in advance for your help!
Frank

Put an early return half way through, and bisect the program from there until you find the bit that freezes. I have my suspicions about the rs.Command but maybe the Rhino script context is not supported for one of the other functions in rs.

@Ferenc_Schell Which part of this script requires Grasshopper? Could this be run by itself in the main script editor in Rhino?

Here is your corrected text in English:

I am working in Grasshopper. This is the content of a Python node, whose goal was to export the generated objects that I baked to Rhino before this node was started.

The main goal is to be able to export the objects directly from Grasshopper, with the attached User Text attributes, to the layer that is also a property of each Grasshopper object."

I would be very grateful if I could find or receive a solution for this. I don’t understand why the Grasshopper Rhino tab doesn’t include this function.

Best regards:
Frank