+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Super Member
    Using
    AutoCAD 2010
    Join Date
    Dec 2010
    Posts
    1,173

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

    Registered forum members do not see this ad.

    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

    Code:
    ;;;--------------------------------------------------------------------;
    ;;;       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)
    )

  2. #2
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,881

    Default

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

    Code:
    (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
    Last edited by BIGAL; 13th Jan 2015 at 08:38 am.
    A man who never made mistakes never made anything

  3. #3
    Super Member
    Using
    AutoCAD 2010
    Join Date
    Dec 2010
    Posts
    1,173

    Default

    thanks Bigal.

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

    still have the same wonders thu...
    Last edited by samifox; 13th Jan 2015 at 10:27 pm.

  4. #4
    Super Member hanhphuc's Avatar
    Using
    AutoCAD 2007
    Join Date
    Apr 2013
    Location
    Happy Garden
    Posts
    565

    Default

    Does
    Code:
    cond
    helps?
    lambda not optimized.. ( apply '= "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments

  5. #5
    Super Member
    Using
    AutoCAD 2010
    Join Date
    Dec 2010
    Posts
    1,173

    Default

    Registered forum members do not see this ad.

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

Similar Threads

  1. Replies: 3
    Last Post: 2nd Jul 2014, 03:54 am
  2. Replies: 3
    Last Post: 16th Jun 2014, 01:50 pm
  3. Error Trapping
    By Arepo in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 6th Nov 2013, 09:32 pm
  4. Help with error trapping and exploding block.
    By Jimmy Sean in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 2nd Mar 2011, 07:00 pm
  5. error Trapping??
    By BLOACH85 in forum AutoLISP, Visual LISP & DCL
    Replies: 20
    Last Post: 19th Mar 2009, 05:13 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts