Launch animation
-
Thanks TIG for telling me to look at Page API, because I thought it was only a collection (Pages) and not an entity.
So at the end, the solution I found is the following one :
def lire_anim (p) model = Sketchup.active_model pages = model.pages pages.selected_page = pages[p] if p<pages.size-1 then id = UI.start_timer(Sketchup.active_model.options["PageOptions"]["TransitionTime"], false) { lire_anim(p+1) } end end
and to launch : lire_anim(0)
Now, I need to find a way to stop animation while it's running...
-
You also need to understand
view.animation=
etc...
https://developers.google.com/sketchup/docs/ourdoc/view#animation=
Add this into your script's methodsanimation = Anima.new() model = Sketchup.active_model view = model.active_view anim = view.animation=animation if (anim) UI.messagebox anim else UI.messagebox "Failure" end
To cancel the current view's animation use
view.animation=nil
-
I'm close to the aim !
I have 2 issues :
1-When start the animation it goes to "stop" subrouting but it doesn't stop animation ...?!
2-When setting view.animation to nil, it' doesn't stop... ?!Again your help is welcome !
class Class_Run_Animation def initialize puts "Start of animation" show_scene(0) end def show_scene(p) puts "Go to scene #{p}" pages = Sketchup.active_model.pages pages.selected_page = pages[p] if p<pages.size-1 then id = UI.start_timer(Sketchup.active_model.options["PageOptions"]["TransitionTime"], false) { show_scene(p+1) } return true else puts "End of loop" return false end end def stop puts "Loop stopped" return false end end
-
You loop through the pages and then
return false
, this stops it, you never call stop, and don't really need to...
You should only use theinitialize()
method to set up@
variables etc, if needed...
You have dropped thedef nextFrame(view)...
Why? I think this is confusing the issue... Using it would let you create an animation class object that you could assign to the view [looping through the scenes [pages] etc] in some separate code withview.animation=Class_Run_Animation.new()
, then you can later cancel withview.animation=nil
.
The separate code used would be something like:module Inteloide def self.start_animation() Sketchup.active_model.active_view.animation=Class_Run_Animation.new() end def self.end_animation() Sketchup.active_model.active_view.animation=nil end end
Used in the console [or added to a toolbar command] as
Inteloide.start_animation
and
Inteloide.stop_animation
Your earlier code could be readily adapted to do this... -
ok, I changed to an animation class, but it still don't stop
I think the issue comes from the start_timer which start the procedure even if animation is stopped.` class Class_Run_Animation
def initialize
puts "Start of animation"
#show_scene(0)
@p=0
enddef nextFrame(view)
puts "Go to scene #{@p}"
pages = Sketchup.active_model.pages
pages.selected_page = pages[@p]
if @p<pages.size-1 then
@p+=1
id = UI.start_timer(Sketchup.active_model.options["PageOptions"]["TransitionTime"], false) { nextFrame(view) }
return true
else
puts "End of loop"
return false
end
end
endmodule Inteloide
def self.start_animation()
Sketchup.active_model.active_view.animation=Class_Run_Animation.new()
end
def self.stop_animation()
Sketchup.active_model.active_view.animation=nil
end
end` -
You've made it iterate itself!
Try something like this...def initialize() @model=Sketchup.active_model @pages = Sketchup.active_model.pages @po=@model.options["PageOptions"] end def nextFrame(view) while view @pages.to_array.each_with_index{|page, i| next unless page.name==page.label ### (SKIP) puts page.name @pages.selected_page = @pages[i] UI.start_timer(@po["TransitionTime"],false){###}### wait for a time } end#while end
or similar...
-
Well, I'm lost ;o)
what is the aim of this loop :
@pages.to_array.each_with_index{|page, i|
next unless page.name==page.label ### (SKIP)what do you put instead of "###" in the code :
UI.start_timer(@po["TransitionTime"],false){###}
(I put nextFrame(view) because if not the animation doesn't continue) -
Maybe it's because I don't understand how sketchup makes the loop for an animation, what's happen after nextframe is called and run ? I'm lost in fact.... (
-
Maybe I confused you with the addition of
next unless page.name==page.label ### (SKIP)
All this does is NOT display the page IF the name and label don't match.
A page's name and its label are the same UNLESS the page has be marked NOT to be included in the animation in the Scene-Manager dialog - it then has the name labeled inside () - so you won't show it...
The ### is a 'rem' statement - a 'comment' after the code so what follows is ignored...The next part:
puts page.name
simply displays the name of the scene it's processing in the Ruby Console
Then:
@pages.selected_page = @pages[i]
sets the selected page to be the current pages 'item' [by index 'i'] in the list of pages...
Next:
UI.start_timer(@po["TransitionTime"],false){###}### wait for a time
The timer starts a pause - the rem ### at the end is as above...
ON reflection... I appreciate that this final part is wrong.
Because the timer then runs outside of the main loop !
Perhaps using:
sleep(@po["TransitionTime"])
instead, might work instead ?? This stop processing for that long before the next page is set 'selected'. -
Hi,
I didn't saw your answer but I produced this code...
I post it for your information...but I will work on your answerSo, my code, as it is now (please don't blame me using a global variable... )
` class Class_Run_Animation
def initialize
puts "Start of animation v1"
@p=0
@id=0
enddef nextFrame(view)
if $inteloide_cont==true then
puts "Go to scene #{@p}"
pages = Sketchup.active_model.pagespages.selected_page = pages[@p] if @p<pages.size-1 then @p+=1 @id=UI.start_timer(Sketchup.active_model.options["PageOptions"]["TransitionTime"]+Sketchup.active_model.options["SlideshowOptions"]["SlideTime"], false) { nextFrame(view) } return true else puts "End of loop" return false end else puts "stop animation" @id=UI.start_timer(1, false) { nextFrame(view) } end
end
endmodule Inteloide
def self.start_animation()
$inteloide_cont=true
Sketchup.active_model.active_view.animation=Class_Run_Animation.new()
end
def self.stop_animation()
$inteloide_cont=false
Sketchup.active_model.active_view.animation=nil
end
def self.pause_animation()
$inteloide_cont = !($inteloide_cont)
puts $bg_cont
end
end`
Advertisement