How can i do Progress bar in Ruby (Sketchup)?

Hi guys i want to create a progress bar for my plugin how can i do ? i have downloaded progressbar.rb and i have implemented it but it can’t works can you help me ? thank you

Why cant it work? You will need to “call” it from or copy the relevant code to your plugin. Simply downloading it is not enough.

yeah i have the class in my folder when i call the methods they works but i don’t see the progress bar

Typically the progress bar would be shown on the left end of the “Status” bar which is across the bottom of the Sketchup window.

My problem is when i serialize all scene, the sketchup UI is freeze, so i thought to make a showbar for resolve this problem , at this moment i using a web dialog for create a progress bar , but the problem is still here

Yes when you get the “spinning wheel of death” nothing is displayed.

can i fix this ? ther’s a way ?

Not that I know of and I have been trying for 7 years.

also thread are usless ?

you can animate the viewport activity, even when SU is busy crushing code, it does have an overhead, but is more entertaining…

it really depends on what your doing as to what you might choose to show…

both @kirill200777 and @jim_foltz had plugins the showed geometry creation doing this…

for scenes you can change to the page being processed or even use selection.add >> view refresh >> selection.clear for each entity…

I have one the changes background color and switches to wireframe while it’s doing that to minimise the cost of the activity…

if you move the cursor you see the spinning wheel, but the viewport still updates…

john

I guess it all depends on what you are doing but my experience has been that as far as the status bar, vcb, etc. nothing happens when the wheel is spinning.

I’m not sure maybe it is possible to set “disable_ui” flag of #start_operation method to false in order to make progress bar visible during some iterative operation, but it doesn’t help to “unfreeze” UI and will slow down the process for sure.
For now the only way to “unfreeze” UI during some iterative process is to use timer methods of UI class instead of standard iterators like “each” or “while” etc:
id = UI.start_timer(10) { UI.beep }
UI.stop_timer(id)

So this is the only way at the moment to get input from a user during some long-lasting operation. I think it is more important to provide ability to break/pause/cancel some long-lasting operation, than just to display some progress. But there is another problem: it is unsafe to add geometry into an active model using timer. I mean in case if operation was opened using “model.start_operation” on timer start, then it should be closed on timer stop (no matter how exactly it was stopped: naturally after reaching an end of iteration, or manually from a user break). In case if operation is left uncommitted for some reason, crashes may take place after undo.
So in my experience the better way is to use timer to display some long-lasting calculation progress, but without adding of any actual geometry into an active model, i.e. display calculation results using “view.draw” method. The idea is to split time-consuming calculation and actual geometry (faces, edges) creation. Store results of calculation into some arrays or directly into polygon mesh object, then create actual geometry from stored calculation results at once (without a timer using standard iterators like “each”, “while” etc). Usually it takes reasonable time to generate geometry from some existing array of coordinates, than generate each face or edge one-by-one inside the same iteration loop, where some heavy calculation takes place.

1 Like

Ok thank you , i have done a cycle , in this cycle i call UI.start_timer and in the callback i call my method , in this way the UI keep alives

Not sure if I understood correctly, but I think I have to mention that typically UI.start_timer should be called once (I mean not in some cycle):

condition_to_stop_timer=false
repeat_timer=true
timer_id=UI.start_timer(seconds, repeat_timer){
	
	# Place for some logic, which should be executed in a loop without UI "freezing"
	# (this logic should set "condition_to_stop_timer" to true at some point).
	
	if condition_to_stop_timer
		timer_id=UI.stop_timer(timer_id)
	end
}
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.