TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Augusto 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
(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)
-
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 (http://www.theswamp.org/index.php?topic=49381.0)
-
Untested, but IMHO it should work...
(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)
)
-
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
-
Cheers...
:beer:
;-)