Author Topic: Update countdown text  (Read 1773 times)

0 Members and 1 Guest are viewing this topic.

Augusto

  • Newt
  • Posts: 75
Update countdown text
« on: September 28, 2018, 01:19:27 PM »
Hello guys!

I'm trying to countdown, but the text does not update.  :blink:
Could someone tell me the reason?

Thank you.
Luís Augusto

Code: [Select]
(defun c:countdown

  (/
    start
    time
    insertionPoint
    textString
    height
    textObj
    acadObj
    doc
    modelSpace
  )

  (setq acadObj (vlax-get-acad-object))
  (setq doc (vla-get-ActiveDocument acadObj))
  (setq modelSpace (vla-get-ModelSpace doc))
  (setq insertionPoint (vlax-3d-point 0 0 0)
textString "Time Remaining: 00 seconds."
height        0.5
  )

  (setq textObj     (vla-AddText modelSpace textString insertionPoint height)
timeCounter (*
      30 ;Seconds
      1000.
    )
start     (getvar 'MILLISECS)
  )

  (while (setq time_elapse (< (- (getvar 'MILLISECS) start) timeCounter))
    ;(grread t)
    (or
      (/= textString
  (setq textString (vla-get-textstring textObj))
      )
      (and
(vla-put-textstring
  textObj
  (strcat
    "\nTime Remaining: "
    (rtos (fix(/ (- timeCounter (- (getvar 'MILLISECS) start)) 1000.)) 2 0)
    " seconds"
  )
)
(vla-update textObj)
      )
    )
  )
  (princ)
)
(vl-load-com)
« Last Edit: September 28, 2018, 01:34:40 PM by Augusto »

Augusto

  • Newt
  • Posts: 75
Re: Update countdown text
« Reply #1 on: September 28, 2018, 01:29:42 PM »
By implementing the command (grread t) within the loop, the text refreshes when you move the mouse.
Is there another way to do it?  :woow:

http://www.theswamp.org/index.php?topic=49381.0

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Update countdown text
« Reply #2 on: September 28, 2018, 02:19:48 PM »
Untested, but IMHO it should work...

Code: [Select]
(defun c:countdown
  (/
    start
    time
    insertionPoint
    textString
    height
    textObj
    acadObj
    doc
    modelSpace
  )

  (vl-load-com)

  (setq acadObj (vlax-get-acad-object))
  (setq doc (vla-get-ActiveDocument acadObj))
  (setq modelSpace (vla-get-ModelSpace doc))
  (setq insertionPoint (vlax-3d-point 0 0 0)
        textString "Time Remaining: 00 seconds."
        height 0.5
  )

  (setq textObj (vla-AddText modelSpace textString insertionPoint height)
        timeCounter (*
                       30 ;Seconds
                       1000.
                    )
        start (getvar 'MILLISECS)
  )

  (while (< (- (getvar 'MILLISECS) start) timeCounter)
    (if (/= (setq textString
          (strcat
            "Time Remaining: "
            (itoa (fix (/ (- timeCounter (- (getvar 'MILLISECS) start)) 1000.)))
            " seconds."
          ))
          (vla-get-textstring textObj)
        )
      (progn
        (vla-put-textstring textObj textString)
        (vla-update textObj)
      )
    )
  )
  (alert "Time limit over...")
  (princ)
)
« Last Edit: September 28, 2018, 03:01:45 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Augusto

  • Newt
  • Posts: 75
Re: Update countdown text
« Reply #3 on: September 28, 2018, 03:00:30 PM »
Untested, but IMHO it should work...

 'vla-put-textstring returns nil :embarrassed2:

Sorry guys.
I think I need to have a beer. Cheers!  :lmao:

Thank you very much again ribarm


ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Update countdown text
« Reply #4 on: September 28, 2018, 03:03:57 PM »
Cheers...
:beer:
 ;-)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube