See the top rated post in this thread. Click here

Results 1 to 4 of 4

Thread: How to stop a routine after its first iteration?

  1. #1
    Member
    Join Date
    2014-01
    Posts
    3
    Login to Give a bone
    0

    Default How to stop a routine after its first iteration?

    Hi all,

    I've beat my head against the wall trying to understand and alter this useful LSP routine that was provided to me.
    Its purpose is to change the description of Cogo Points. It prompts for the desired New Description, then asks for a selection of points, and then changes the description of the selected points to the New Description.

    The routine works well, but I wish it cleanly ended the command after the first iteration. Instead, it prompts for the New Description once more.

    Can anyone suggest an alteration to the routine so that it stops after this first iteration? Thanks in advance!

    Code:
    (defun c:chdesc (/ doc ss obj newdesc olddesc)
      (vl-load-com)
      (setq doc 
    (vla-get-activedocument (vlax-get-acad-object)))
      (while (and (setq newdesc (getstring "\nNew point description:"))
           (not (eq newdesc ""))
           (setq ss (ssget '((0 . "AECC_COGO_POINT"))))
           (setq ctr -1)
           )
        
    (vla-startundomark doc)
        (while (setq obj (ssname ss (setq ctr (1+ ctr))))
          (setq obj (vlax-ename->vla-object obj))
          (vlax-put obj 'rawdescription newdesc))
        (vla-endundomark doc)
        )  
      (princ)
    )
    Attached Files Attached Files
    Last edited by mikeeddy1520476; 2018-01-28 at 04:58 PM. Reason: Edited to format code block, added LSP attachment

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    1

    Default Re: How to stop a routine after its first iteration?

    Try untested:
    Code:
    (defun c:chdesc (/ doc ss obj newdesc olddesc)
      (vl-load-com)
      (setq doc 
    (vla-get-activedocument (vlax-get-acad-object)))
      (while (and (setq newdesc (getstring "\nNew point description:"))
           (not (eq newdesc ""))
           (setq ss (ssget '((0 . "AECC_COGO_POINT"))))
           (setq ctr -1)
           )
        
    (vla-startundomark doc)
        (setq obj (ssname ss (setq ctr (1+ ctr))))
        (setq obj (vlax-ename->vla-object obj))
        (vlax-put obj 'rawdescription newdesc))
        (vla-endundomark doc)
      (princ)
    )
    I simply removed the while loop for selecting Cogo points.

  3. #3
    Member
    Join Date
    2014-01
    Posts
    3
    Login to Give a bone
    0

    Default Re: How to stop a routine after its first iteration?

    Thank you very much for your reply and your effort, Tom.

    I tested your revised code, and unfortunately it still prompts for the New Description after the first iteration, and now it only changes the description of the highest-numbered point in a selection of points (all other points in the selection remain unchanged).

    Does that mean the other 'while' loop needs to be removed?
    I'll keep tinkering with it myself, but I'm always open to suggestions. Thank you again.

  4. #4
    Member
    Join Date
    2014-01
    Posts
    3
    Login to Give a bone
    0

    Default Re: How to stop a routine after its first iteration?

    You pointed me in the right direction, Tom.
    I removed the other while loop and it seems to work just fine.

    Thanks again.

    Code:
    (defun c:chdesc (/ doc ss obj newdesc olddesc)
      (vl-load-com)
      (setq doc 
    (vla-get-activedocument (vlax-get-acad-object)))
           (setq newdesc (getstring "\nNew point description:"))
           (not (eq newdesc ""))
           (setq ss (ssget '((0 . "AECC_COGO_POINT"))))
           (setq ctr -1)
        
    (vla-startundomark doc)
        (while (setq obj (ssname ss (setq ctr (1+ ctr))))
          (setq obj (vlax-ename->vla-object obj))
          (vlax-put obj 'rawdescription newdesc))
        (vla-endundomark doc)  
      (princ)
    )

Similar Threads

  1. Stop a routine midstream
    By M. Kubitza in forum AutoLISP
    Replies: 9
    Last Post: 2010-04-20, 08:23 PM
  2. How to Stop the Routine
    By BeKirra in forum AutoLISP
    Replies: 3
    Last Post: 2009-03-04, 09:44 PM
  3. sheetset iteration order resetting
    By adam.kalajzich in forum VBA/COM Interop
    Replies: 1
    Last Post: 2008-09-25, 03:11 PM
  4. Replies: 2
    Last Post: 2007-04-20, 09:51 AM
  5. Exceeded iteration limit when evaluating curve
    By earld in forum AutoCAD 3D (2006 or below)
    Replies: 2
    Last Post: 2004-06-03, 02:30 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
  •