Troublesome Block Entmod(ing)

Discussion in 'AutoCAD' started by rapidcad, Jul 7, 2004.

  1. rapidcad

    rapidcad Guest

    Hi guys,
    It's time for me to put on my LISP hat again (it's been awhile and I'm rusty). I've cobbled together a program (from chunks of code some of you will recognize) to satisfy a request from a structural engineer to move all text objects in an architectural background (except those on the column buble layer) to a brand new layer (and freeze it) and then change all the objects in the drawing to display "bylayer" - for our x-referencing ease. The difficulties come with blocks with nested text, attributes and mtext. I've been able to get quite a lot of it to work, however I seem to be maxing out autolisp (if that's possible). I get about 1700 blocks modified, but then I get the following message..

    Command: Hard error occurred ***
    internal stack limit reached (simulated)

    Here is my hacked together program. Does anyone have any suggestions as to what the trouble is and how it might be corrected? I really appreciate you guys helping me out when i hit these walls!

    ;;; ADAPTED FROM TxTRot by Jason Piercey 12-12-01 AND TABLE by Michael Puckett MODIFIED by Ron Powell 07-02-04
    ; This routine moves all text (except column buble text on layer "s-grid-text1-32") to layer "ALLTEXT".
    (defun C:pREP (/ ss1 B1 ss2 SE1 i EBLK Ent EntLst ELAY SET1 SUBENTLST KIND RPT)
    (COMMAND "-PURGE" "B" "" "N")
    (command "-layer" "M" "ALLTEXT" "S" "0" "F" "ALLTEXT" "")

    (setq ss1 (ssget "x" '((-4 . "<OR")
    (0 . "TEXT")
    (0 . "MTEXT")
    (0 . "ATTDEF")
    (-4 . "OR>")
    )
    )
    i 0
    )
    (repeat (sslength ss1)

    (setq Ent (ssname ss1 i)
    EntLst (entget Ent)
    ELAY (cdr (assoc 08 EntLst))
    )
    (IF
    (/= (STRCASE "S-GRID-TEXT1-32") ELAY )
    (PROGN
    (setq EntLst (subst (cons 08 "ALLTEXT") (assoc 08 EntLst) EntLst)
    )
    (entmod EntLst)
    (ENTUPD Ent)
    )
    )
    (setq i (1+ i))
    )
    ;;;------------------------------------------------
    ;;;

    (defun table (x / d r);;michael puckett
    (if (member (read x) '(appid block dimstyle layer ltype style ucs view vport))
    (reverse
    (while (setq d (tblnext x (null d)))
    (setq r (cons (cdr (assoc 2 d)) r))
    )
    )
    )
    )
    (SETQ RPT (- (LENGTH (TABLE "BLOCK")) 1))


    (setq B1 (TBLNEXT "BLOCK" T))
    (SETQ SE1 (CDR (ASSOC -2 B1)))
    (SETQ KIND (CDR (ASSOC 0 (ENTGET SE1))))

    (DEFUN CRUNCH ()
    (COND
    ((OR
    (equal "TEXT" KIND)
    (equal "MTEXT" KIND)
    (equal "ATTDEF" KIND))
    (SETQ SUBENTLST (ENTGET SE1))
    (setq SUBEntLst (subst (cons 08 "ALLTEXT") (assoc 08 SUBEntLst) SUBEntLst)
    )
    (entmod SUBEntLst)
    (ENTUPD B1)
    )
    ((SETQ SE1 (ENTNEXT))
    (SETQ KIND (CDR (ASSOC 0 (ENTGET SE1))))
    (CRUNCH)
    )
    )
    )
    (CRUNCH)
    (REPEAT RPT
    (TBLNEXT "BLOCK")
    (CRUNCH)
    )
    ;;;------------------------------------------------
    (setq SET1 (ssget "x"))
    (command "change" SET1 "" "P" "C" "BYLAYER" "p" "lt" "bylayer" "p" "lw" "bylayer" "")
    (PRINC)
    )
     
    rapidcad, Jul 7, 2004
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.