Using Python script, how to delete all shapes in a layer without deleting text

I tried these two: layout.clear_layer(idx) and cell.clear(layer).

Both of these commands remove everything in a layer, including text.

Comments

  • Hi, Pascal!

    I'm not sure if there are better ways to do so, but you could create new layer and copy only text shapes there, than remove old layer and set proper layer/datatype to new one.

  • Thanks for reply, Eugene. I solved this problem by selecting all shapes -> filtering out all text -> deleting shapes. Problem solved now.

  • That's what I was thinking, but the question was how to, in Python.
    Did you find that command-series? Or just did it interactive?

    I'll repeat a recent question, which is: "Is there a logfile which shows
    applied commands in sequence, perhaps even Python / Ruby form,
    that "someone" could clip and package up as a script at minimum
    effort (like, how I could grab a series of SKILL commands from the
    CIW, re-paste them there and see the result repeat in Brand X?)?".

  • I replied to the other post: https://www.klayout.de/forum/discussion/2295/using-python-script-how-to-delete-all-shapes-in-a-layer-without-deleting-text#latest

    An @dick_freebird, no there still isn't because the commands are not routed through some script interpreter, hence they cannot be logged .. :(

  • OK, that's understandable I guess.

    Let me suggest some things.

    Seems to me that whatever sits there looking at
    keyboard & mouse, could be told to yip something
    out to a logfile every time it finds a "terminator"
    (valid command is satisfied, or an error). That goes
    as far as, at least, a historical record.

    But the second part would want a mapping from
    the foreground command (menu / keybinding, +
    args) to an equivalent Python command entered
    (where? there's no interpreter?).

    So maybe there needs to be a "skinny pipe" from
    the "keyboard catcher" to something inhabiting the
    script edit / execute environment, that substitutes
    the proper Python and then executes. If the plan
    was for everything klayout can do, to be doable by
    script. Thus making "what I just did" a front door to
    script generation. Like how you can "record macro"
    in MS Excel, and edit it if you like.

    So that's another thing, if you have the history thing
    enabled - a "Pythonized Macro Recorder"? If what
    would come from the "history catcher" is not actually
    executable as-caught, then maybe it's a two-pass-
    assembler, like. Catch, then clean.

    Now I am also curious about klayout as a purely
    pipe-driven (but with live display) engine. I have the
    same interest with simulators and schematics, with
    the end goal a fully integrated, front-back OSEDA
    (my mind still goes back to the happy days of SDA2.0.
    Before the dark times. Before the Empire). When men
    were men and menus were editable top to bottom
    and executable script lay in the CIW hopper, for the
    taking.

    But I have no knowledge whether "regular klayout"
    menu and key-bound commands "go through a
    Python grinder" on their way to Doing Stuff, or all the
    menus are some other code-base. Which would then
    be mondo rip-up.

Sign In or Register to comment.