Jump to content

whats wrong with my lisp?


mohammadreza

Recommended Posts

hello friends
after i run my code. this sign apeared, whts problem

(defun c:zoo ()
  (if (setq a (entlast))			       
    (while
      (setq b (entnext a))			      
       (setq a b)
						       
    )
  )
  (setq ent (entget a))
  (setq po (assoc 10 ent))
  (setq pt (cdr po))
  (command "zoom" "c" pt 50 "")

)						      

 

lispcode.png

Link to comment
Share on other sites

(defun c:zoo () ;; also, you can localized the all variables from code (/ pt) to be set as default (nil) before next execution.
  ;; (if (setq a (entlast)) 	       
  ;; (while
  ;;   (setq b (entnext a))			      
  ;;    (setq a b)				       
  ;; )
  ;;)
  ;;(setq ent (entget a))
  ;;(setq po (assoc 10 ent))
  ;;(setq pt (cdr po))
  (setq pt (cdr (assoc 10 (entget (entlast))))) ;; this line substitue the 9 lines of code from above.
  ;;(command "zoom" "c" pt 50 "") --> delete the last "" after 50, because you are calling again "zoo" command
  (command "zoom" "c" pt 50)
)

 I put a some description in your code, hope it will be helpful.

 

  • Like 1
Link to comment
Share on other sites

I made some comments on your code. It does work but could be made more efficient. However the main point it does work, and I'll often leave things at that rather than spending hours optimising code to save milliseconds. 

 

The 'nil' report is just the LISP telling you that there is no result from the LISP. You could put this at the end (princ) which makes the LISP exit quietly. You could see the LISP reporting something by putting  for example 'a' as the last line.

 

So some comments I'd make: 

 

(defun c:zoo ()                 ;; I'd use (defun c:zoo ( / ) - easier to check if you have localised variables
  (if (setq a (entlast))        ;; OK, check there is a Last Entity
    (while
      (setq b (entnext a))      ;; after (entlast) there should be no entnext
       (setq a b)
    )                           ;; Add comment here "End While" - longer codes makes modification easier
                                ;; Add here what happens if there is no 'entlast'
  )                             ;; Add comment here "End if" - as above
  (setq ent (entget a))
  (setq po (assoc 10 ent))
  (setq pt (cdr po))            ;; Could combine this line to the po line above (setq po (cdr (assoc 10.... )))
  (command "zoom" "c" pt 50 "")
                                ;; Add here (princ) to exit quietly (no 'nil' after ending the code)
)

 

 

Following your code format I'd do something like this

 

(defun c:zoo ( / a pt)                      ;; Localise variables in case other LISPS use the same (especially common ones like pt)
  (if (setq a (entlast))
    (progn   ; If 'a' found
      (setq pt (cdr (assoc 10 (entget a)))) ;; Get point
      (command "zoom" "c" pt 50)            ;; Zoom to point
    )        ; end progn
    (progn   ; if 'a' not found             ;; If 'a' not found
      (princ "\nNo entity found")           ;; Report that 'a' not found
    )        ; end progn
  )          ; end if
  (princ)    ; exit quietly                ;;change this to pt to see effect of LISP reporting something (zooming point)
)

 

 

  • Like 3
Link to comment
Share on other sites

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