Results 1 to 5 of 5

Thread: Force Update of Command Line within Loop

  1. #1
    Join Date
    Tamworth, NSW, Australia

    Default Force Update of Command Line within Loop

    I have a function that does a 3d extrusion for a specified height on 3dfaces.
    I am trying to setup a progress bar as I intend to use this routine on files with 1000's of 3dfaces and want to show that things are happening.
    I have found a few helpful posts that I have copied and modified that have got me close to a solution using grtext to write to the status bar.

    The issue I have is that the grtext line is not executed until the while loop is finished which defeats the purpose.

    I have tried nomutt and clipromptupdate system variables which do not seem to change anything.

    Anyone know how to force the lisp to update the command line or status bar.

    Below is code:

    ;;;======================================================;;; EXTZ - EXTrude in Z direction
    ; Function to Extrude 3D Faces in Z Direction
    ; Modified by Steve Griffiths
    (defun c:extz (/ exht ls len ctr ctrprogress *error* msg )
      (vl-load-com);Allow Visual LISP ActiveX functions
      (Echo_Off);Turn off command visibility
      (defun *error* ( msg ) ;Define Error Function
        (if adoc (vla-endundomark adoc))
        (Echo_restore);Restore Echo if Changed
        (PDMode_Restore);Restore Point Display if Changed
        (Snap_Restore);Restore Snap if Changed
        (if (not (member msg '("Function cancelled" "quit / exit abort"))) ;If Not Exit / Esc key
          (princ (strcat "\nError: " msg)) ;Print Error Message
        );End If
        (princ);Clean Exit
      );End defun error
      (setq adoc (vla-get-activedocument (vlax-get-acad-object))) ;Set Current Document
      (vla-startundomark adoc) ;Set Undo Mark Start
      (Snap_off) ;Turn Snap Off
      ;(setvar "clipromptupdate" 1)
      ;(setvar "nomutt" 0)
      (setq exht (getreal "\nEnter extrusion height: ")) ;Get extrusion height
      (prompt "\n <Enter> for All") ;Empty Set will select all
      (setq ls (ssget "_:L" '((0 . "3DFACE")))) ;Select only 3dfaces (Exclude Locked Layers)
      (if (= nil ls) (setq ls (ssget "x" (list (cons 0 "3DFACE"))))) ;All 3DFaces if Empty Selection Set
      (setq	len (sslength ls) ;Get length of selection set
    	ctr 0) ;Set Counter
      (while (< ctr len) ;Cycle through Selection Set
        (setq ent (ssname ls ctr)) ;Get each entity	  
        (vl-cmdf "extrude" "MO" "SO" ent "" "d" "0, 0, 0" (strcat "0, 0, -" (rtos exht)));Extrude by specified height
        (setq ctrprogress (rem ctr 10))
    	(setvar "modemacro" "$(getvar,USERS1)")
        (if (= ctrprogress 0)
    	(setq progbar (cond ((= progbar "|") "/")
    				((= progbar "/") "--")
    				((= progbar "--") "\\")
    				((= progbar "\\") "|")
    				((= t t) "|")
    			  );End Conds
    	);End Setq
    	;(setvar "modemacro" progbar)
    	;(prompt progbar)
    	(grtext -1 (strcat progbar))
          )	; End Progn
        ); End If
        (setq ctr (1+ ctr));Increment counter    
      );end while
      (princ (strcat "\n" (itoa (fix len)) " 3D Faces Extruded down by " (rtos exht 2 2)));
      (PDMode_Restore);Restore Point Display if Changed
      (Snap_Restore);Restore Snap if Changed
      (vla-endundomark adoc) ;Set Undo Mark End
      (Echo_Restore);Restore Command Visibility
      (princ);Clean Exit
    Sample with 3dfaces
    3dfaces testing.dwg

    Thanks in Advance

  2. #2
    Join Date

    Default Re: Force Update of Command Line within Loop

    Using your variables, you can do something right after:
    (setq ctr (1+ ctr));Increment counter

    (princ (strcat "\n... " (itoa ctr) " of " (itoa len) "."))

  3. #3
    Join Date
    Tamworth, NSW, Australia

    Default Re: Force Update of Command Line within Loop

    Thank you GOchrisgilmer for your response.

    I tried your suggestion and the result is the same as other options in the code, nothing is outputted until the while loop if finished and then all lines are outputted at once.

    Any idea why?

    Thanks in Advance

  4. #4
    Active Member
    Join Date

    Default Re: Force Update of Command Line within Loop

    This has been talked about before, it's a little above my pay grade but seems to be inherent in autolisp. See Basically autocad will become unresponsive while the loop is processing. You can try throwing in a (grread) in the code, but that will mean you have to jiggle your mouse the whole time the routine is running. You might also try something like
    (command "_delay" 50)
    (princ (strcat "\n... " (itoa ctr) " of " (itoa len) "."))
    but I think that wont work any better, and will drag out the completion time even if it does. Maybe worth a try though.

    An outside-the-box solution might be to implement a DCL progress bar. See if you're comfortable with coding.

  5. #5
    I could stop if I wanted to
    Join Date

    Default Re: Force Update of Command Line within Loop

    if you use a ACET function it only needs 3 lines start, count & end updated some stuff but its at work so hopefully this is sufficient. This is the fancy default Autocad progress bar.

    (acet-ui-progress-init "Updating" 100)
    (acet-ui-progress-safe c)

    (acet-ui-progress-safe (setq num (+ num inc))) have this inside a repeat or a foreach etc.

    ; If the number is small the bar will just flash so use a Delay
    (setq  doc (vla-get-activedocument (vlax-get-acad-object))) ; open database
    (setq allblocks (vla-get-blocks doc))
    (setq howmany (vla-get-count allblocks))
    (setq x 0)
    (acet-ui-progress-init "Blocks" (vla-get-count allblocks))
    (vlax-for block allblocks
    (princ (strcat "\n" (vla-get-name block)))
    (acet-ui-progress-safe (setq x (+ x 1)))
    (acet-ui-progress-done); dismiss progressbar
    Last edited by BIG-AL; 2017-04-03 at 03:12 AM.

Similar Threads

  1. 2014: Force symbolic lines to show up in hidden line view
    By Bill Gilliss in forum Revit Architecture - General
    Replies: 3
    Last Post: 2014-06-02, 02:10 PM
  2. read-line loop column text file
    By dukwing16 in forum AutoLISP
    Replies: 7
    Last Post: 2006-05-13, 05:22 PM
  3. Replies: 4
    Last Post: 2006-03-13, 07:38 PM
  4. Block Insert Array (Loop within a Loop)
    By wpeacock in forum VBA/COM Interop
    Replies: 2
    Last Post: 2005-06-14, 04:24 AM
  5. Force a line wrap in Tables?
    By cadpoobah in forum AutoCAD General
    Replies: 1
    Last Post: 2005-01-21, 04:28 PM

Tags for this Thread

Posting Permissions

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