Results 1 to 8 of 8

Thread: Repeat command until it is cancelled

  1. #1
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Repeat command until it is cancelled

    I want this command to repeat until it is canceled. It currently does that, when the escape key is used, but if the enter key or space bar is used instead of selecting a point, it spits back this error.

    Error: bad argument type: numberp: nil

    the program works fine, I just want the error message to go away

    Code:
    ;;===============================================
    ;;		 L o c a l   F u n c t i o n s		 
    ;;===============================================
    ;; error function & Routine Exit
    (defun *error* (msg)
      (if
    	(not
    	  (member
     msg
     '("console break"
       "Function cancelled"
       "quit / exit abort"
       ""
      )
    	  )
    	)
    	 (princ (strcat "nError: " msg))
      )	 ; endif
      (restore_sys_vars)   ; reset vars
    )
     
    ;; Function to save system variables in global variable
    ;;  call to function
    ;;  (save_sys_vars '("CMDECHO" "CLAYER" "OSMODE" "CECOLOR"))
    (defun save_sys_vars (lst)
      (setq *sysvarlist* '())
      (repeat (length lst)
    	(setq *sysvarlist*
    	(append *sysvarlist*
    	 (list (list (car lst) (getvar (car lst))))
    	)
    	)
    	(setq lst (cdr lst))
      )
    )
    ;; Function to reset system variables 
    (defun restore_sys_vars ()
      (repeat (length *sysvarlist*)
    	(setvar (caar *sysvarlist*) (cadar *sysvarlist*))
    	(setq *sysvarlist* (cdr *sysvarlist*))
      )
    )
    (save_sys_vars
      '("CMDECHO" "OSMODE" "CECOLOR" "CLAYER" "PICKBOX" "TEXTSTYLE")
    )
    	 ;GET SYSTEM VAR & error handling
    	 ;SET SYSTEM VAR
    (defun c:ca (/ ss elev th textobj)
      (setvar "cmdecho" 0)
      (setvar "osmode" 512)
      (setq ss (getpoint "Select Contourn")
     elev (rtos (caddr ss))
     th (* 0.06 40)
     textobj (vla-addtext acadModelSpace elev (vlax-3d-point ss) TH)
      )
      (vla-put-alignment textobj 10)
      (vla-put-textalignmentpoint textobj (vlax-3d-point ss))
      (c:ca)
      (*error* "")	;RESTORE SYSTEM VAR
      (princ)
    )	 ;end defun
    any help would be appreciated

  2. #2
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Repeat command until it is cancelled

    I removed the error message by making the changes in red, but if there are other errors, they probably wont show messages either.


    Code:
    (defun *error* (msg)
    ;| (if
    (not
    (member
    msg
    '("console break"
    "Function cancelled"
    "quit / exit abort"
    ""
    )
    )
    )
    (princ (strcat "nError: " msg))
    ) ; endif
    |; (restore_sys_vars) ; reset vars
    )
    if someone could point me in the direction of removing the message when just enter or space is used to exit the command it would be appreciated
    Last edited by ccowgill; 2006-09-22 at 12:28 PM.

  3. #3
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Repeat command until it is cancelled

    Quote Originally Posted by ccowgill
    Code:
    (defun c:ca (/ ss elev th textobj)
      (setvar "cmdecho" 0)
      (setvar "osmode" 512)
      (setq ss (getpoint "Select Contourn"))
      (if ss
        (progn
      (setq elev (rtos (caddr ss))
     th (* 0.06 40)
     textobj (vla-addtext acadModelSpace elev (vlax-3d-point ss) TH)
      )
      (vla-put-alignment textobj 10)
      (vla-put-textalignmentpoint textobj (vlax-3d-point ss))
        )
      )
      (c:ca)
      (*error* "")	;RESTORE SYSTEM VAR
      (princ)
    )	 ;end defun
    You need to verify ss as a point. The if statement above should help. I have not tested it.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  4. #4
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: Repeat command until it is cancelled

    try this
    The error is do to ss = nil if you do not select a point. The change use ss=nil to exit the while fuction.
    Code:
    ;;===============================================
    ;; L o c a l F u n c t i o n s 
    ;;===============================================
    ;; error function & Routine Exit
    (defun *error* (msg)
    (if
    	(not
    	 (member
    msg
    '("console break"
    "Function cancelled"
    "quit / exit abort"
    ""
    )
    	 ) ;_ end of member
    	) ;_ end of not
    	 (princ (strcat "nError: " msg))
    )	 ; endif
    (restore_sys_vars) ; reset vars
    ) ;_ end of defun
    ;; Function to save system variables in global variable
    ;; call to function
    ;; (save_sys_vars '("CMDECHO" "CLAYER" "OSMODE" "CECOLOR"))
    (defun save_sys_vars (lst)
    (setq *sysvarlist* '())
    (repeat (length lst)
    	(setq *sysvarlist*
    	(append *sysvarlist*
    	 (list (list (car lst) (getvar (car lst))))
    	) ;_ end of append
    	) ;_ end of setq
    	(setq lst (cdr lst))
    ) ;_ end of repeat
    ) ;_ end of defun
    ;; Function to reset system variables 
    (defun restore_sys_vars ()
    (repeat (length *sysvarlist*)
    	(setvar (caar *sysvarlist*) (cadar *sysvarlist*))
    	(setq *sysvarlist* (cdr *sysvarlist*))
    ) ;_ end of repeat
    ) ;_ end of defun
    (save_sys_vars
    '("CMDECHO" "OSMODE" "CECOLOR" "CLAYER" "PICKBOX" "TEXTSTYLE")
    ) ;_ end of save_sys_vars
    	 ;GET SYSTEM VAR & error handling
    	 ;SET SYSTEM VAR
    (defun c:ca (/ ss elev th textobj)
    (setvar "cmdecho" 0)
    (setvar "osmode" 512)
    (setq ss (getpoint "Select Contourn"))
    (while (/= ss nil)
    	(setq elev (rtos (caddr ss))
    th (* 0.06 40)
    textobj (vla-addtext acadModelSpace elev (vlax-3d-point ss) TH)
    	) ;_ end of setq
    	(vla-put-alignment textobj 10)
    	(vla-put-textalignmentpoint textobj (vlax-3d-point ss))
    	(setq ss (getpoint "Select Contourn"))
    ) ;_ end of while
    (*error* "")	;RESTORE SYSTEM VAR
    (princ)
    )
    Last edited by jwanstaett; 2006-09-22 at 02:49 PM.

  5. #5
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: Repeat command until it is cancelled

    change added the code to set acadModelSpace so it would work. you must be set acadModelSpace some place.


    Code:
     ;;===============================================
    ;;   L o c a l   F u n c t i o n s   
    ;;===============================================
    ;; error function & Routine Exit
    (defun *error* (msg)
      (if
    	(not
    	  (member
     msg
     '("console break"
       "Function cancelled"
       "quit / exit abort"
       ""
      )
    	  ) ;_ end of member
    	) ;_ end of not
    	 (princ (strcat "nError: " msg))
      )	 ; endif
      (restore_sys_vars)   ; reset vars
    ) ;_ end of defun
    (setq acadModelSpace
    	   (VLA-GET-MODELSPACE
      (VLA-GET-ACTIVEDOCUMENT (vlax-get-acad-object))
    	   ) ;_ end of VLA-GET-MODELSPACE
    ) ;_ end of setq
    ;; Function to save system variables in global variable
    ;;  call to function
    ;;  (save_sys_vars '("CMDECHO" "CLAYER" "OSMODE" "CECOLOR"))
    (defun save_sys_vars (lst)
      (setq *sysvarlist* '())
      (repeat (length lst)
    	(setq *sysvarlist*
    	(append *sysvarlist*
    	 (list (list (car lst) (getvar (car lst))))
    	) ;_ end of append
    	) ;_ end of setq
    	(setq lst (cdr lst))
      ) ;_ end of repeat
    ) ;_ end of defun
    ;; Function to reset system variables 
    (defun restore_sys_vars ()
      (repeat (length *sysvarlist*)
    	(setvar (caar *sysvarlist*) (cadar *sysvarlist*))
    	(setq *sysvarlist* (cdr *sysvarlist*))
      ) ;_ end of repeat
    ) ;_ end of defun
    (save_sys_vars
      '("CMDECHO" "OSMODE" "CECOLOR" "CLAYER" "PICKBOX" "TEXTSTYLE")
    ) ;_ end of save_sys_vars
    	 ;GET SYSTEM VAR & error handling
    	 ;SET SYSTEM VAR
    (defun c:ca (/ ss elev th textobj)
      (setvar "cmdecho" 0)
      (setvar "osmode" 512)
      (setq ss (getpoint "\nSelect Contourn"))
      (while (/= ss nil)
    	(setq elev   (rtos (caddr ss))
       th   (* 0.06 40)
       textobj (vla-addtext acadModelSpace elev (vlax-3d-point ss) TH)
    	) ;_ end of setq
    	(vla-put-alignment textobj 10)
    	(vla-put-textalignmentpoint textobj (vlax-3d-point ss))
    	(setq ss (getpoint "\nSelect Next Contourn"))
      ) ;_ end of while
      (*error* "")	;RESTORE SYSTEM VAR
      (princ)
    )	 ;end defun

  6. #6
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Repeat command until it is cancelled

    sorry about that, acadModelSpace is defined in my main lisp program (the one that loads all my routines)

    Opie, yours suggestion worked fine other than:
    Code:
    (vla-put-textalignmentpoint textobj (vlax-3d-point ss))
      (c:ca)
    );end progn
    );end if
    the two ) need to be after c:ca

  7. #7
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Repeat command until it is cancelled

    Does it repeat if you do that? It's your program. Enjoy.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  8. #8
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Repeat command until it is cancelled

    yes, it operates as intended, thanks for your help

Similar Threads

  1. Repeat last command
    By revit.wishlist1942 in forum Revit Architecture - Wish List
    Replies: 1
    Last Post: 2013-01-04, 05:39 PM
  2. Retain pre-selected objects when a command is cancelled.
    By Wish List System in forum AutoCAD Wish List
    Replies: 4
    Last Post: 2012-08-15, 03:28 AM
  3. Command alias repeat on the command line
    By rbilger in forum AutoCAD General
    Replies: 8
    Last Post: 2011-08-18, 09:47 PM
  4. Command is automatically cancelled
    By dbeaudoin in forum ACA General
    Replies: 3
    Last Post: 2010-02-23, 07:13 PM
  5. repeat command
    By Ning Zhou in forum Revit Architecture - General
    Replies: 2
    Last Post: 2009-12-14, 07:59 PM

Posting Permissions

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