Author Topic: Progress Bar  (Read 15088 times)

0 Members and 1 Guest are viewing this topic.

CincyJeff

  • Newt
  • Posts: 89
Re: Progress Bar
« Reply #15 on: January 27, 2016, 07:29:11 AM »
hmspe,
I was never able to make progress bars work well so I went to reports on the command line with code similar to:
Code: [Select]
 
  (setq spin  0)

  ;;; get a selection set and convert to a list of enames

  (setq total (strcat " of " (itoa (length set1))))
  (foreach memb set1
 
    ;;; do stuff

    (setq spin (1+ spin))
    (if (= (rem spin 10) 0)
      (cond ( (< spin   100) (princ (strcat "\rProcessing     " (itoa spin) total)))
            ( (< spin  1000) (princ (strcat "\rProcessing    " (itoa spin) total)))
            ( (< spin 10000) (princ (strcat "\rProcessing   " (itoa spin) total)))
            (t               (princ (strcat "\rProcessing  " (itoa spin) total)))
      )
    )
  )
  (princ (strcat "\rTrimming " total " of " total))
In a compiled vlx nothing echoes to the command line until the loop is complete. At least the progress bar is in your face so you know something is happening.

hmspe

  • Bull Frog
  • Posts: 362
Re: Progress Bar
« Reply #16 on: January 27, 2016, 08:45:47 AM »
In a compiled vlx nothing echoes to the command line until the loop is complete. At least the progress bar is in your face so you know something is happening.

That could well be.  I don't compile to vlx.  Uncompiled lisp is fast enough for my purposes.  Lee is probably correct about Windows considering programs unresponsive after 5 seconds, but I see no signs of that with this code.  The command line continues to update and there is no "Not Responding" banner in the title bar or dimming of the screen.  The code works for me and meets my expectations.  YMMV. 
"Science is the belief in the ignorance of experts." - Richard Feynman

ymg

  • Guest
Re: Progress Bar
« Reply #17 on: January 27, 2016, 09:04:08 AM »
CincyJeff,

Did you try with the Express tools one (acet-ui-progress).

You update it in your long loop.  Works for me

I also ran a test with (dos_getprogress) it also works for me
under win 7.  You do need to update the box with (dos_getprogress -1)
within 5 seconds as demonstrated by Lee.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.    (setq x (getvar 'millisecs)
  3.          y 10000  ;will run 10 seconds)
  4.    )
  5.    (dos_getprogress "Testing" "Testing, please wait..." y)
  6.    (while (< (- (getvar 'millisecs) x) y) (dos_getprogress -1))
  7.    (dos_getprogress t)
  8.    
  9. )
  10.  


ymg
« Last Edit: January 27, 2016, 10:18:55 AM by ymg »

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Progress Bar
« Reply #18 on: January 27, 2016, 10:20:02 AM »
I gave up on progress bars a long time ago.

For simple activity indicator
Code: [Select]
(princ "\r")(prin1 en)



For a percentage indicator ( untested)
Code: [Select]
(setq sl (sslength ss)
         i 0)

then

(princ (strcat ("\r" (rtos (* (/ i sl) 10.) 2 1)))) "%      ")


Or simply princ the incremental on decremental counter.

My $0.02  -David
R12 Dos - A2K

CincyJeff

  • Newt
  • Posts: 89
Re: Progress Bar
« Reply #19 on: January 27, 2016, 12:27:24 PM »
David Bethel,
It looks like the problem is compiling into a vlx. Nothing is echoed to the command line until completion and using the (prin1 en) in a loop produces a single 0 on completion. It looks like my choices come down to uncompiled with working progress bar or compiled with partial progress bar. Thanks for the input.

CincyJeff

  • Newt
  • Posts: 89
Re: Progress Bar
« Reply #20 on: January 27, 2016, 12:45:00 PM »
To anyone interested,
I contacted Dale with DOSLib and he gave me a fix for my problem:
During a long, time consuming task, if AutoCAD does not not have a chance to "peek and pump" it's Windows message queue, then Windows might think the application has hung. So, in your time consuming task, you might want to sprinkle a call to DOS_PAUSE, which will force AutoCAD to flush its message queue, thus keeping the UI alive. Something as simple as this might help:

(dos_pause 0)


Thanks Dale and everyone else that contributed.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Progress Bar
« Reply #21 on: January 27, 2016, 12:55:30 PM »
Would using acet-sys-sleep also work?

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Progress Bar
« Reply #22 on: January 27, 2016, 12:56:49 PM »
Also (command "_.delay" ... ) might be worth a shot.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Progress Bar
« Reply #23 on: January 27, 2016, 05:20:10 PM »
To anyone interested,
I contacted Dale with DOSLib and he gave me a fix for my problem:
< ... >

I thought that would be the case.

I applaud your efforts to keep your users advised regarding what is happening and your attempts to stop them panicking when your app is running a processor intensive process.

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Progress Bar
« Reply #24 on: January 27, 2016, 06:29:53 PM »
Quick & dirty conceptual solution code for those that use the command line for status:

Code: [Select]
(defun MP:String ( char n )

    (   (lambda ( s n )
            (while (< (strlen s) n) (setq s (strcat s s)))
            (substr s 1 n)
        )
        (if (eq 'int (type char)) (chr char) char)
        (max 0 (fix n))
    )

)

Code: [Select]
(defun MP:Left ( text n / len )

    (if (< (setq n (max (fix n) 0)) (setq len (strlen text)))
        (substr text 1 n)
        text
    )

)

Code: [Select]
(defun MP:Right ( text n / len )

    (if (< (setq n (max (fix n) 0)) (setq len (strlen text)))
        (substr text (1+ (- len n)))
        text
    )

)

Code: [Select]
(defun MP:Flush ( / cmdecho millisecs ceiling )

    (cond
        (   (null (setq ceiling 2000 millisecs (getvar 'millisecs)))
        )
        (   (/= 'int (type *MP:Flush:MilliSecs*))
            (setq *MP:Flush:MilliSecs* millisecs)
        )
        (   (< ceiling (- millisecs *MP:Flush:MilliSecs*))
            (setq cmdecho (getvar 'cmdecho))
            (setvar 'cmdecho 0)
            (vl-cmdf ".delay" 0)
            (setvar 'cmdecho cmdecho)
            (setq *MP:Flush:MilliSecs* millisecs)
        )
    )

    (princ)

)

Code: [Select]
(defun MP:Status ( message percent )

    ;;  Use percent arg to:
    ;;
    ;;  *   Initialize (via t) ................ e.g. (MP:Status nil T)
    ;;  *   Clean up (via nil) ................ e.g. (MP:Status nil nil)
    ;;  *   Specify percent (via 0 - 100) ..... e.g. (MP:Status "Message" 42)

    (MP:Flush)

    (cond
        (   (member percent '(nil t))
            (princ (strcat "\r" (MP:String " " 80)))
        )
        (   (<= 0 (setq percent (fix percent)) 100)
            (if (/= percent *MP:Status:Percent*)
                (progn
                    (princ
                        (strcat
                            "\r" (MP:String " " 80)
                            "\r" message
                            " [" (MP:Right (strcat "0" (itoa (min 99 percent))) 2) "%] "
                            (MP:Left
                                (strcat
                                    (MP:String "•" (/ percent 2.0))
                                    (MP:String "·" 50)
                                )
                                50
                            )
                        )
                    )
                    (setq *MP:Status:Percent* percent)
                )
            )
        )
    )

    (princ)

)

Code: [Select]
(defun c:Test ( / i ceiling )

    ;;  initialize
    (MP:Status nil t)

    (setq i -1)

    (repeat (setq ceiling 5000000)
        ;;  display message and percent
        (MP:Status "MP:Status Test:" (/ (* 100.0 (setq i (1+ i))) ceiling))
    )

    ;;  cleanup
    (MP:Status nil nil)

    (princ)

)

MP:Status Test: [42%] •••••••••••••••••••••·····························

Cheers.

Edit: Changed to vanilla {code} ... {/code} tags as the {code=cadlisp-7} ... {/code} tags make it highly inconvenient to copy the code.
« Last Edit: January 28, 2016, 11:51:00 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Progress Bar
« Reply #25 on: January 27, 2016, 06:55:43 PM »
As nice as that is, quite a few people/firms have the commandline turned off ... or can have.

It's a pity AutoCAD doesn't have an  in-built modeless dialog that is accessible from lisp.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Progress Bar
« Reply #26 on: January 27, 2016, 06:57:31 PM »
Truth. That said, can easily embellish code to abuse modemacro.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Progress Bar
« Reply #27 on: January 27, 2016, 07:05:35 PM »
To wit:

Code: [Select]
(defun MP:Status ( message percent )

    ;;  Use percent arg to:
    ;;
    ;;  *   Initialize (via t) ................ e.g. (MP:Status nil T)
    ;;  *   Clean up (via nil) ................ e.g. (MP:Status nil nil)
    ;;  *   Specify percent (via 0 - 100) ..... e.g. (MP:Status "Message" 42)

    (MP:Flush)

    (cond
        (   (eq t percent)
            (setq *MP:Status:ModeMacro* (getvar 'modemacro))
            (setvar 'modemacro "")
        )
        (   (null percent)
            (setvar 'modemacro *MP:Status:ModeMacro*)
        )
        (   (<= 0 (setq percent (fix percent)) 100)
            (if (/= percent *MP:Status:Percent*)
                (progn
                    (setvar 'modemacro
                        (strcat
                            message
                            " [" (MP:Right (strcat "0" (itoa (min 99 percent))) 2) "%] ["
                            (MP:Left
                                (strcat
                                    (MP:String "|" 100)
                                    (MP:String "·" 100)
                                )
                                100
                            )
                            "]"
                        )
                    )
                    (setq *MP:Status:Percent* percent)
                )
            )
        )
    )

    (princ)

)

Cheers.

Edit: Changed to vanilla {code} ... {/code} tags as the {code=cadlisp-7} ... {/code} tags make it highly inconvenient to copy the code.
« Last Edit: January 28, 2016, 10:50:18 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Progress Bar
« Reply #28 on: January 27, 2016, 07:07:01 PM »
yep, modemacro is accustomed to abuse.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Progress Bar
« Reply #29 on: January 27, 2016, 07:12:57 PM »

It's tempting to put together a lisp callable method using
Autodesk.AutoCAD.Runtime.ProgressMeter in dotNet




Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.