Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

ChatGPT Autolisp Routine Syntax Error

richard
Participant

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
Reply
Accepted solutions (1)
507 Views
6 Replies
Replies (6)

ВeekeeCZ
Consultant
Consultant

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

0 Likes

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

В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.

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

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this. 

0 Likes

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