Results 1 to 6 of 6

Thread: Crash out of While function

  1. #1
    Member
    Join Date
    2008-09
    Posts
    9
    Login to Give a bone
    0

    Default Crash out of While function

    How can I cleanly exit a "while" function used with "ssget"? I thought an empty return would work but it exits the whole routeen. If I give give the "while" a fixed exit the routeen works fine. It crashes out befor the list is written to a txt file. Thanks for any help.
    See below

    Code:
    (defun c:BB ()
    (setq ss x)
    (Setvar "osmode" 0)
    (setq infolst nil)
    (setq T1 1)
    
    (while (/= ss nil)
    
    (Prompt "Pick Dimension")
        (setq SS (ssget))
        (setq elst1 (entget(ssname SS 0)))
        (setq P1 (cdr(assoc 11 elst1)))
    
        (setq p2 (list (+ (car p1) 0.55)(+ (cadr p1) 0.38) 0.0))
        (setq p3 (list (- (car p2) 0.10)(- (cadr p2) 0.10) 0.0))
        (command "circle" P2 0.25 "")
        
        (setq T2 (itoa T1))
        (command "text" P3 "0.180" "0" T2)
    
        (setq D1 (cdr(assoc 42 elst1)))
        (setq D1 (rtos D1 2 3))
        (setq INFOLST (append INFOLST (list D1)))
        (setq T1 (1+ T1))
    
    );while
    
    ;Write INFOLST out to file
    
     (setq R (length INFOLST)
           FN "c:\\cad\\Iso9000.txt"
           I 0
          TEX (open FN "w")
     )
          (repeat R
              (setq L (nth I INFOLST))
              (write-line L TEX)
              (setq I (1+ I))
           )
    (close TEX)
    
    
       
    (princ)
    )
    (princ)
    Last edited by Opie; 2008-09-10 at 01:09 PM. Reason: [CODE] tags added, see Moderator Note

  2. #2
    I could stop if I wanted to
    Join Date
    2006-04
    Posts
    466
    Login to Give a bone
    0

    Default Re: Crash out of While function

    If SS is nil it will not work in other functions.

    ie: (setq elst1 (entget(ssname SS 0)))

    (ssname nil 0) will crash.

    Use:

    (if (/= ss nil) (progn...

  3. #3
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Crash out of While function

    Quote Originally Posted by aaronic_abacus View Post
    Use:
    (if (/= ss nil) (progn...
    That's a bit silly. Use:
    (if ss (progn ...
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  4. #4
    I could stop if I wanted to
    Join Date
    2006-04
    Posts
    466
    Login to Give a bone
    0

    Default Re: Crash out of While function

    ;This autolisp program is a revision of your posted code.
    ;It works now!

    Code:
    (defun c:BB ()
    (setq ss 1)
    (Setvar "osmode" 0)
    (setq infolst nil)
    (setq T1 1)
    
    (while (/= ss nil)
    
    (Prompt "Pick Dimension")
    (setq SS (ssget))
    (if (/= ss nil) (progn;kind of funny hehe!***********************************************************************
    
    
    (setq elst1 (entget(ssname SS 0)))
    (setq P1 (cdr(assoc 11 elst1)))
    
    (setq p2 (list (+ (car p1) 0.55)(+ (cadr p1) 0.3) 0.0))
    (setq p3 (list (- (car p2) 0.10)(- (cadr p2) 0.10) 0.0))
    (command "circle" P2 0.25 "")
    
    (setq T2 (itoa T1))
    (command "text" P3 "0.180" "0" T2)
    
    (setq D1 (cdr(assoc 42 elst1)))
    (setq D1 (rtos D1 2 3))
    (setq INFOLST (append INFOLST (list D1)))
    (setq T1 (1+ T1))
    ));end progn/if
    
    );while
    
    ;Write INFOLST out to file
    
    (setq R (length INFOLST))
    (setq FN "c:\\cad\\Iso9000.txt")
    (setq I 0)
    (setq TEX (open FN "w"))
    
    (repeat R
    (setq L (nth I INFOLST))
    (write-line L TEX)
    (setq I (1+ I))
    )
    (close TEX)
    
    
    
    (princ)
    )
    (princ)
    Attached Files Attached Files
    Last edited by aaronic_abacus; 2008-09-10 at 12:50 AM.

  5. #5
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Crash out of While function

    What Robert meant was that (/= ss nil) is the same as saying ss. E.g.
    Code:
    (defun c:BB    ()
        (setq ss 1)
        (Setvar "osmode" 0)
        (setq infolst nil)
        (setq T1 1)
        (while ss ;Does the same as (/= ss nil)
            (Prompt "Pick Dimension")
            ;| (setq SS (ssget))
            (if    (/= ss nil)
            Can be replaced with the following line - one step only
            |;
            (if (setq SS (ssget))
                (progn
                    (setq elst1 (entget (ssname SS 0)))
                    (setq P1 (cdr (assoc 11 elst1)))
    
                    (setq p2 (list (+ (car p1) 0.55) (+ (cadr p1) 0.3) 0.0))
                    (setq p3 (list (- (car p2) 0.10) (- (cadr p2) 0.10) 0.0))
                    (command "circle" P2 0.25 "")
    
                    (setq T2 (itoa T1))
                    (command "text" P3 "0.180" "0" T2)
    
                    (setq D1 (cdr (assoc 42 elst1)))
                    (setq D1 (rtos D1 2 3))
                    (setq INFOLST (append INFOLST (list D1)))
                    (setq T1 (1+ T1))
                ) ;_ end of progn
            );_end of if
        );_end of while
        ;;Write INFOLST out to file
        (setq R (length INFOLST))
        (setq FN "c:\\cad\\Iso9000.txt")
        (setq I 0)
        (setq TEX (open FN "w"))
    
        (repeat    R
            (setq L (nth I INFOLST))
            (write-line L TEX)
            (setq I (1+ I))
        ) ;_ end of repeat
        (close TEX)
    
        (princ)
    ) ;_ end of defun
    (princ)

  6. #6
    Member
    Join Date
    2008-09
    Posts
    9
    Login to Give a bone
    0

    Default Re: Crash out of While function

    Many Many thanks. Very clean solutions. I clearly had not thougth that one through. Again thanks to all!!

Similar Threads

  1. Why Revit 2010 Crash, while deleting any Function Material Layer of Floor?
    By bingles7 in forum Revit Architecture - General
    Replies: 3
    Last Post: 2010-05-06, 05:13 PM
  2. Can't Get Journal to fix crash/test crash
    By Hulston1982 in forum Revit Architecture - General
    Replies: 3
    Last Post: 2008-07-07, 08:58 PM
  3. Help with Sub Function and calling it from main Function
    By avinash00002002 in forum VBA/COM Interop
    Replies: 1
    Last Post: 2006-06-21, 02:20 PM
  4. crash, bang, wallop! ( Radiosity Crash)
    By gmak in forum Revit - Rendering
    Replies: 4
    Last Post: 2004-07-16, 09:20 PM
  5. crash, bang, wallop! ( Radiosity Crash)
    By gmak in forum Revit Architecture - General
    Replies: 2
    Last Post: 2004-07-15, 04:22 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
  •