Author Topic: RESTART LISP WHEN CANCELED ON FINDING ERROR  (Read 1787 times)

0 Members and 1 Guest are viewing this topic.

eduardoceliz

  • Mosquito
  • Posts: 5
RESTART LISP WHEN CANCELED ON FINDING ERROR
« on: June 07, 2020, 08:38:14 AM »
hello, I am generating this code to insert texts to a civil 3d surface it works ok, my problem is when the peak outside the surface is automatically canceled, what I am looking for is that the lisp when it detects that error automatically restarts asking me to insert the point again or failing to insert the text but with a value of "0" or "---" or "", I hope you can help me

(defun c:test ()
(setq sup (vlax-ename->vla-object (car (entsel "\nSurface:"))))
(WHILE
(setq pt1 (getpoint "\nPoint: "))
(setq ele(vlax-invoke sup 'FindElevationAtXY (car pt1) (cadr pt1)))
(command "text" "j" "mc" pt1 2.5 0 (rtos ele 2 2))
);fin while
);fin defun

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: RESTART LISP WHEN CANCELED ON FINDING ERROR
« Reply #1 on: June 07, 2020, 03:04:23 PM »
Hi,
I don't have Civil 3D to test the codes out but you can try it yourself and let me know how it works for you.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ text_ sel pt ele)
  2.   (defun text_ (p v)
  3.     (entmake (list '(0 . "TEXT")
  4.                    (cons 10 p)
  5.                    (cons 11 p)
  6.                    '(40 . 2.5)
  7.                    (cons 1 v)
  8.                    '(71 . 0)
  9.                    '(72 . 1)
  10.                    '(73 . 2)
  11.              )
  12.     )
  13.   )
  14.   (if (setq sel (car (entsel "\nSurface: ")))
  15.     (while (setq pt (getpoint "\nSpecify a Point < Enter to exit safely >: "))
  16.       (if (setq ele (vlax-invoke
  17.                       (vlax-ename->vla-object sel)
  18.                       'FindElevationAtXY
  19.                       (car pt)
  20.                       (cadr pt)
  21.                     )
  22.           )
  23.         (text_ pt (rtos ele 2 2))
  24.         (princ "\nInvalid point !. Try again.")
  25.       )
  26.     )
  27.   )
  28.   (princ)
  29.  

eduardoceliz

  • Mosquito
  • Posts: 5
Re: RESTART LISP WHEN CANCELED ON FINDING ERROR
« Reply #2 on: June 07, 2020, 03:43:41 PM »
I just tried it but it throws the following error "; error: Civil 3D API: Triangle is deleted" and the lisp stops, what I am looking for is that the lisp does not stop

Dilan

  • Newt
  • Posts: 23
Re: RESTART LISP WHEN CANCELED ON FINDING ERROR
« Reply #3 on: June 07, 2020, 05:29:00 PM »
I just tried it but it throws the following error "; error: Civil 3D API: Triangle is deleted" and the lisp stops, what I am looking for is that the lisp does not stop
Try this:
Code: [Select]
(defun c:test ( / sup sup_name pt1 ele lavelTin )
(vl-load-com)
(if
(setq sup (car (entsel "\nSurface ->> ")))
(progn
(setq sup_name (vlax-ename->vla-object sup))
(while (setq pt1 (getpoint "\nSpecify a Point ->> "))
            (setq ele (if (vl-catch-all-error-p (setq lavelTin (vl-catch-all-apply 'vlax-invoke (list sup_name 'FindElevationAtXY (car pt1) (cadr pt1)))))
             "" ; if out of Surface
            (rtos lavelTin 2 3)
    ))
(entmake
    (list
      (cons 0 "TEXT")
      (cons 8 "TIN_point")
      (cons 10 pt1)
  (cons 40 1); Text height <<--
      (cons 1 ele)
      (cons 50 0)
      (cons 7 (getvar 'textstyle))
      (cons 62 150)
      )
)
);fin while
); end of progn
(princ "\nInvalid Surface. Try again.")
); end of if
(princ)
);fin defun

Dilan

  • Newt
  • Posts: 23
Re: RESTART LISP WHEN CANCELED ON FINDING ERROR
« Reply #4 on: June 07, 2020, 05:33:25 PM »
I just tried it but it throws the following error "; error: Civil 3D API: Triangle is deleted" and the lisp stops, what I am looking for is that the lisp does not stop
Or this version:
Code: [Select]
(defun c:test ( / get-entsel-no-error sup sup_name pt1 ele lavelTin )
(vl-load-com)
;-----
(defun get-entsel-no-error (message / ent)
  (setvar "errno" 0)
  (while
    (and
      (not (setq ent (entsel (strcat "\n" message))))
      (equal 7 (getvar "errno"))
     
    )
     (setvar "errno" 0)
  )
  (cond
    ((equal (getvar "errno") 52)
     
     nil
    )
    (t
     (list (car ent) (trans (cadr ent) 1 0))
    )
  )
)
;-----
(if
(setq sup (car (get-entsel-no-error "\nSurface ->> ")))
(progn
(setq sup_name (vlax-ename->vla-object sup))
(while (setq pt1 (getpoint "\nSpecify a Point ->> "))
            (setq ele (if (vl-catch-all-error-p (setq lavelTin (vl-catch-all-apply 'vlax-invoke (list sup_name 'FindElevationAtXY (car pt1) (cadr pt1)))))
             "" ; if out of Surface
            (rtos lavelTin 2 3)
    ))
(entmake
    (list
      (cons 0 "TEXT")
      (cons 8 "TIN_point")
      (cons 10 pt1)
  (cons 40 1); Text height <<--
      (cons 1 ele)
      (cons 50 0)
      (cons 7 (getvar 'textstyle))
      (cons 62 150)
      )
)
);fin while
); end of progn
(princ "\nInvalid Surface. Try again.")
); end of if
(princ)
);fin defun

Dilan

  • Newt
  • Posts: 23
Re: RESTART LISP WHEN CANCELED ON FINDING ERROR
« Reply #5 on: June 07, 2020, 10:21:23 PM »
I just tried it but it throws the following error "; error: Civil 3D API: Triangle is deleted" and the lisp stops, what I am looking for is that the lisp does not stop
Here is the version with filter when choosing for surface:

Code: [Select]
(defun c:test ( / mip:entsel sup sup_name pt1 ele lavelTin )
(vl-load-com)
;-----
(defun mip:entsel (promt filter entlist / key n newentlist ent_point promt)
(setq key T n 0 newentlist nil)
  (if (eq (type entlist) 'PICKSET)
    (progn
    (while (setq a (ssname entlist n)) (setq newentlist (append newentlist (list a)) n (1+ n)))
    (setq entlist newentlist)
    );progn
   );if
    (while key
    (if (or (setq ent_point (entsel promt)) (= (getvar "ERRNO") 7))
  (if (or (eq (type ent_point) 'LIST) (not ent_point))
  (if ent_point
    (if (member (setq ent (car ent_point)) entlist)
      (princ "\nObject already selected")
      (if filter
      (if (not (member (cdr (assoc 0 (entget ent))) filter))
(progn (setq str "\nWrong choice, specify: ")
  (princ (substr (setq str (foreach n filter (setq str (strcat str n ", ")))) 1 (- (strlen str) 2)))
);progn
(setq key nil)
      );if
(setq key nil)
);if
    );if
    (setq key T)
  );if
    (setq key nil)
    );if
  (setq key nil)
      );if
     );while
  (if (eq (type ent_point) 'LIST)
    (progn (setvar "LASTPOINT" (cadr ent_point)) ent)
    ent_point
  );if
)
;-----
(if
(setq sup (mip:entsel "\nSpecify a Surface ->> " '("AECC_TIN_SURFACE") nil))
(progn
(setq sup_name (vlax-ename->vla-object sup))
(while (setq pt1 (getpoint "\nSpecify a Point ->> "))
            (setq ele (if (vl-catch-all-error-p (setq lavelTin (vl-catch-all-apply 'vlax-invoke (list sup_name 'FindElevationAtXY (car pt1) (cadr pt1)))))
             "" ; if out of Surface
            (rtos lavelTin 2 3)
    ))
(entmake
    (list
      (cons 0 "TEXT")
      (cons 8 "TIN_point")
      (cons 10 pt1)
  (cons 40 1); Text height <<--
      (cons 1 ele)
      (cons 50 0)
      (cons 7 (getvar 'textstyle))
      (cons 62 150)
      )
)
);fin while
); end of progn
(princ "\nInvalid Surface. Try again.")
); end of if
(princ)
);fin defun
« Last Edit: June 07, 2020, 10:27:33 PM by Dilan »

eduardoceliz

  • Mosquito
  • Posts: 5
Re: RESTART LISP WHEN CANCELED ON FINDING ERROR
« Reply #6 on: June 08, 2020, 12:32:41 AM »

thanks it works perfect

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: RESTART LISP WHEN CANCELED ON FINDING ERROR
« Reply #7 on: June 08, 2020, 02:07:01 AM »
Answer over at cadtutor as well re choose surface option.
A man who never made a mistake never made anything