Jump to content

Recommended Posts

Posted

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)
)
 

Posted

First use the <> on the toolbar to post code.

Second always save a link to where you got the code, if you ever have an issue with it that should be the best place to get support from whoever the code belongs to.

Google search for your command name didn't find anything but a quick search of "send Wipeout To Back Block AutoCAD Lisp" did including:

Send Wipeout to Back of Draworder within Block Definition: 

 

Posted
27 minutes ago, tombu said:

Second always save a link to where you got the code, if you ever have an issue with it that should be the best place to get support from whoever the code belongs to.

 

ChatGPT is computer generated code, so no source location to post... and I bet if you asked the computer why it isn't working it will just go "?"

 

 

If you were to go through the code and do 2 things, first off mark the end of each if, progn, repeat for example

 

....
(if (= count 2)
  (progn
.... do somew stuff
  ) ; end progn
  (progn
... do some other stuff
  ) ; end progm
) ; end if

 

This can help a lot. Syntax error might be that an if statement has more then 2 parts after it (which is a kind of hint) and might be missing a (progn    .... ) part

Second is to comment out all the lines with a ; leaving in something like the last (princ) - lisp doesn't like empty routines.... and remove the commented out parts section by section till you find where the problem is.

 

So for example I did this and got to the first half up to ' (setq ss (ssget "_X" '((0 . "WIPEOUT"))))' is good, problem is after then, also noting the end points of the if statements, '(if (cdr (assoc 330 ent))' has too many parts, might be missing a progn somewhere?

 

It might be quite satisfying working out the issue from a couple of hints?

 

Posted

ChatGP was featured on TV last night as the new way to learn, unfortunately it still has a way to go for CAD lisp.

 

We will see more and more incorrect code I dont know if there is contact ChatGP so more updates can be made to make code more robust.

 

Get a copy of Notepad++ it has bracket checking built in so can at least correct some errors.

 

Here is my version of bracket check you can see where a bracket opens and look for a corresponding close.

CHKBRK.LSP

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...