Jump to content
samifox

error trapping - what should be handled by user and what by *error*

Recommended Posts

samifox

hi,

 

i've written some input validation code, and i wonder what is really required to code and what can be handled by the autolisp *error* function.

 

secondly, for readability sake, since the validation code is long i were thinking to link it from a different sub-function . is this a good idea?

 

(this function is not going to interact with the user so i didnt use the getinit codes)

 

Thanks

Shay

 

;;;--------------------------------------------------------------------;
;;;       Function:  setEntSeg(ent typ max min)                                        ;
;;;       Vesion:    0.0
;;;       Creation:
;;;       Update:
;;;       Sub-function : 3DTO2DpONIT()
;;;                                                                    ;
;;;    Description:  divids entity into segments while maintaining
;;;                  typ segment length. when total length cannot be
;;;                  divided without a reminder. last segments being handled
;;;                  according to min max parameters.
;;;                  
;;;                                                                    ;
;;;      Arguments:                                                    ;
;;;             typ = typical segment length.                         ;
;;;             mn = integer. minimum length allowed.                              ;
;;;             mx = integer. maximum length allowed.                     ;

;;;                                                                    ;
;;; Returned Value:  A list of 2d coordinates represanting the
;;;                  new segments.
;;;                                                                    ;
;;;          Usage:                                                    ;
;;;                                                                  ;
;;;--------------------------------------------------------------------;



(defun setEntSeg (ent mn typ mx / plst y x cnt ang)
 (if (= (cdr (assoc 0 ent)) "LWPOLYLINE")
   (if	(not (and (zerop mn) (zerop typ) (zerop mx)))
     (if (and (or (= (type typ) 'INT))
       (or (= (type mn) 'INT))
       (or (= (type mx) 'INT))
  )
(if (not (and (minusp mn) (minusp mx)))
  (if (and (> mx typ) (< mn typ))
    (princ "input is valid\n")
    (princ
      "iilegeal values, make sure mx is greater than typ and mn is smaller than typ\n"
    )
  )

  (princ "negative values are not allowed\n")
)

(princ "mn and/or mx must be integer\n")
     )
     (princ "zero is not allowed/n")
   )

   (princ "function works only with lwpolyline\n")
 )
 (princ)
)




(defun test ()
 (setq	ent (entmake (list (cons 0 "LWPOLYLINE")
		   (cons 100 "AcDbEntity")
		   (cons 100 "AcDbPolyline")
		   (cons 90 2)
		   (cons 10 (list 0 0))
		   (cons 10 (list 100 100))
		   (cons 210 (list 0 0 1))
	     )
    )
 )

 (setEntSeg ent 6 6 6)
)

Share this post


Link to post
Share on other sites
BIGAL

eror checking

 

If Not polyline do in loop with a exit option "you have not picked a pline please try again or pick nothing to exit" de. Its a bit late if they have picked an object then they have no 2nd go. now where is my code example trying to find uses a while to check if NIL no object picked then (exit).

 

(while (setq obj (entget (car (entsel "\nPick Pline"))))

(if (= (cdr (assoc 0 obj)) "LWPOLYLINE")
(progn
; your code
; your code
 (princ "wow")
 ; your code
 ; your code
(exit) ; to get out of while
) ; end progn
(alert (strcat "You picked a " (cdr (assoc 0 obj)) " try again nothing to exit"))
) ; end if

) ; end while

Edited by BIGAL

Share this post


Link to post
Share on other sites
samifox

thanks Bigal.

 

as i said, input verification will take place in the getInput() function.

 

still have the same wonders thu...

Edited by samifox

Share this post


Link to post
Share on other sites
hanhphuc

Does

[url="http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-7BA45202-D95F-4F2D-8D83-965024826074"]cond[/url]

helps?

Share this post


Link to post
Share on other sites
samifox

What *error* can handle and what i can handle?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×