ChatGPT Autolisp Routine Syntax Error

ChatGPT Autolisp Routine Syntax Error

richard
Participant Participant
781 Views
6 Replies
Message 1 of 7

ChatGPT Autolisp Routine Syntax Error

richard
Participant
Participant

Hi,

 

I got this code from ChatGPT. Its a routine that sends all the wipeouts in all blocks to the back.

 

I am getting an error however when I try to upload it using appload (error: syntax error)

 

Can anyone see what's wrong with it please, thanks.

 

(I know its from an AI so it might not be all correct but I tested it with another lisp I asked it to create and that one works)

 

(defun c:WipeoutBlocksToBack (/ blkname blk ss enx ent i j)
  (setq blkname (getvar "blkname"))
  (foreach blk (mapcar 'cdr (tblnext "block" T))
    (if (not (tblsearch "block" blk))
      (setq blk (strcase blk))
      (progn
        (setq blk (strcase blk))
        (if (not (equal blk blkname))
          (progn
            (command "_-insert" blk "0,0" "1" "1" "0")
            (setq ss (ssget "_X" '((0 . "WIPEOUT"))))
            (if ss
              (repeat (setq i (sslength ss))
                (setq i (1- i) ent (ssname ss i) enx (entget ent))
                (setq enx (subst (cons 62 0) (assoc 62 enx) enx))
                (entmod enx)
              )
            )
            (command "_undo" "_end")
          )
        )
      )
    )
  )
  (setq ss (ssget "_X" '((0 . "WIPEOUT"))))
  (if ss
    (repeat (setq i (sslength ss))
      (setq i (1- i) ent (ssname ss i) enx (entget ent))
      (if (cdr (assoc 330 ent))
        (progn
          (command "_undo" "_end")
          (setq blkname (cdr (assoc 330 ent)))
          (command "_-insert" blkname "0,0" "1" "1" "0")
          (setq ss (ssget "_X" '((0 . "WIPEOUT"))))
          (if ss
            (repeat (setq j (sslength ss))
              (setq j (1- j) ent (ssname ss j) enx (entget ent))
              (setq enx (subst (cons 62 0) (assoc 62 enx) enx))
              (entmod enx)
            )
          )
          (command "_undo" "_end")
        )
        (setq enx (subst (cons 62 0) (assoc 62 enx) enx))
        (entmod enx)
      )
    )
    (princ "\nNo wipeouts found.")
  )
  (princ)
)
 

0 Likes
Accepted solutions (1)
782 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

Kindly ask ChatGpt to start over and do better. It's not even close.

0 Likes
Message 3 of 7

richard
Participant
Participant

i changed the style of my input for ChatGPT but still getting the same error.

 

Would you say this is closer or worse?

 

(defun c:WipeoutInBlocksToBack (/ blk ss enx ent i)
(setq ss (ssget "_X" '((0 . "WIPEOUT"))))
(if ss
(progn
(repeat (setq i (sslength ss))
(setq i (1- i) ent (ssname ss i))
(setq enx (entget ent))
(if (cdr (assoc 330 enx))
(progn
(setq blk (cdr (assoc 330 enx)))
(command "_-insert" blk "0,0" "1" "1" "0")
(setq ss (ssget "_X" '((0 . "WIPEOUT"))))
(if ss
(repeat (setq i (sslength ss))
(setq i (1- i) ent (ssname ss i) enx (entget ent))
(setq enx (subst (cons 62 0) (assoc 62 enx) enx))
(entmod enx)
)
)
(command "_undo" "_end")
)
(setq enx (subst (cons 62 0) (assoc 62 enx) enx))
(entmod enx)
)
)
(princ "\nAll wipeouts in blocks sent to back.")
)
(princ "\nNo wipeouts found.")
)
(princ)
)

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

It's very similar. It's trying to change the color of all wipeouts that are not in blocks. 

 

Try THIS for a start.

Message 5 of 7

richard
Participant
Participant
Hopefully someone will make one for all blocks if it's possible but that code you linked is very useful, thank you!
0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this. 

0 Likes
Message 7 of 7

richard
Participant
Participant
This is it, thank you for all the help! this will save so much time producing drawings while editing in place
0 Likes