DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Progress Bar

Started by Garry K, January 09, 2013, 06:33:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Garry K

Does DC have anything like a progress bar or a status area that a macro controls?

It would be nice to display something to the user during the execution of a macro that takes a long time.

Dr PR

Garry,

I think I have seen macros that print a string of asterisks in a dialog window to let you know the macro hasn't crashed, but that leaves a lot to be desired in comparison to a status bar.

You could also just print a string like "running" followed a few seconds later by whitespace overwriting the text, and repeated periodically.

Or you could just print the percent periodically, overwriting the earlier result.

For these schemes you must open a dialog box, keep it open while the macro executes, and periodically write to it. I'm not sure you can do this. Alternately, you could periodically open a dialog and print to it.

I'm sure the experienced macro jocks on the Forum can tell you how to do this.

Phil
DesignCAD user since 1987

JJG

Yes, on my side, I don't know any native code or statement that would do that.

I used the folowing code, only in macro build with loop(s) using FOR and NEXT statements :



If sys(80)<1 then goto Fin
Count=sys(80)

for t=1 to sys(80)

'ProgressionBar
if maxi<Count then maxi=Count
Current=Count


'...      'work on entity
'...

message "OK"   'only for test of this code

Count=Count-1
pr=int(((maxi-current)*100)/maxi)
print STRING$(pr, "#")


next t
End

Fin:
message "Sorry, Entities to Change must be selected already. Select Entities then restart macro..."
End

dcadRob

Progress bar macro:
'test progress bar
sys$(42)="Running Macro - Progress Bar"
window 3,45
locate 2,1
print "Progress 0% ["
locate 2,40
print "] 100%"
'test with 100000 iterations
max=100000
ttdone=0
' ttstep is number of iterations which equals 5% of progress
ttstep=max/20

for i=1 to max

' j loop only here to slow down macro for demostration
for j=1 to 10
y=sqrt(3)
next j

if i>ttdone*ttstep then
ttdone=ttdone+1
locate 2,14
print string$(ttdone,"X")
end if
next i
wclose

dcadRob

#4
Busy indicator macro:
'test clock tick
sys$(42)="Running Macro"
window 3,20
locate 2,1
print "Working ..."

for i=1 to 100000

' j loop only here to slow down macro for demonstration
for j=1 to 10000
y=sqrt(3)
next j

locate 2,12
print "     "
locate 3,12
print "     "
locate 2,12
if i mod 4=0 then print "+"
if i mod 4=1 then print "  +"
locate 3,12
if i mod 4=2 then print "  +"
if i mod 4=3 then print "+"

next i
wclose

JJG

OK, dcadRob, you win by KO !
Thanks !!!
;)

Bob P

#6
Be aware that introducing a counter/changing display into a macro can sometimes slow the macro down significantly, depending on the other primary operations.  Instead of a progress bar, I display the approximate running time that the macro will need to run as a warning that requires a key-press to start or to abort the operation.  I've got one old macro (removes duplicate lines) that may take about an hour to run on a large file.

dcadRob

I don't think that a progress bar would slow the macro significantly. A display based on movement, time or printing current entity number in a big loop could be slow. It's possible to set it up so that it displays something only at regular intervals.

This statement only displays something once  every 1000 iterations of the i-loop:
if i MOD 1000=0 then gosub display

You need to find a balance which depends on what the macro is doing and how long it takes.

You could also use the time variable SYS$(7) to calculate an approximate completion time for a macro. That requires doing some time math.


Garry K

Lots of good ideas. My macro is data driven.

Even for an entire large kitchen consisting of 20+ cabinets the C++ side creates a data file in under a second.
Then I load Design cad with the macro as the argument. A large kitchen can take more than a minute to complete.  I can put up a message before generating each cabinet. And then one for creating blocks. Should update the window once every few seconds or so.

Thanks.

prl

Garry,

A good compromise would be to use sys(36)=2 for say 10 cabinets, then switch to sys(36)=0 and do a progress regen, then switch back to silent mode, repeat until your total kitchen is constructed.  The user would get the point.  The intermediate update regens are the progress bar. 

Garry K

I tried the Window idea but it doesn't display. I am initializing for speed with these

Sys(36) = 2
Sys(48) = 0
Sys(49) = 1
Sys(470) = 1

Sys$(42) = "Progress"
Window 5, 20
Locate 3, 1
Print "This is a test"

dcadRob

That can't be the entire macro. How are you testing the code you posted?

Garry K

No - the entire macro is quite large. It opens a data file and runs through the data.
This macro takes 52 seconds on my computer.

It draws a kitchen.

prl

Garry,

You need to pause the sample macro code in order to see the window.  Put an anykey statement at the end and you will see it.

JJG

That's why, personally, I prefer to write some "####' in the status bar .... and not in a separate window.
Because, even with sys(36)=2 (ie. super silent mode enabled), you can see the progress.
;)


(try with the dcd.file below ; select all, then run the "Model of progressionBar.d3m"_macro)