sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    How to pause a ruby script for 1 second

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    25 貼文 5 Posters 5.3k 瀏覽 5 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • tbdT 離線
      tbd
      最後由 編輯

      UI.start_timer(1, false) { Sketchup.active_model.selection.clear}
      

      SketchUp Ruby Consultant | Podium 1.x developer
      http://plugins.ro

      1 條回覆 最後回覆 回覆 引用 0
      • N 離線
        N Lindenthal
        最後由 編輯

        @TBD

        Thank you very much. Your delay goes.

        …
        only with 1 second, but not with 0.9 seconds. Why not?

        1 條回覆 最後回覆 回覆 引用 0
        • tbdT 離線
          tbd
          最後由 編輯

          Mac issue ? on PC works even with 0.1

          SketchUp Ruby Consultant | Podium 1.x developer
          http://plugins.ro

          1 條回覆 最後回覆 回覆 引用 0
          • J 離線
            Jim
            最後由 編輯

            @unknownuser said:

            Mac issue ? on PC works even with 0.1

            Are you sure? (Windows XP Pro SP2)

            
            t1=Time.now; UI.start_timer(0.1) {p Time.now-t1} ==> 0.01
            t1=Time.now; UI.start_timer(0.999) {p Time.now-t1} ==> 0.01
            t1=Time.now; UI.start_timer(1) {p Time.now-t1} ==> 1.001
            t1=Time.now; UI.start_timer(5) {p Time.now-t1} ==> 5.007
            
            

            Hi

            1 條回覆 最後回覆 回覆 引用 0
            • N 離線
              N Lindenthal
              最後由 編輯

              @TDB

              Yes, Mac

              select_comp_by_name("Fahrstuhl");Morisdov.transf_get("transf1");UI.start_timer( 0.99999, false) { Sketchup.active_model.selection.clear}
              
              

              does not clear.
              Perhaps »Morisdov.trasf_get("transf1")« needs exact 1 second, so it goes with 1 and with 1.01 seconds, but not with littlebit less (0.999).

              On Mac on ruby console does not go:

              t1=Time.now; UI.start_timer(0.1) {p Time.now-t1} ==> 0.01
              

              Error is:

              @unknownuser said:

              t1=Time.now; UI.start_timer(5) {p Time.now-t1} ==> 0.01
              t1=Time.now; UI.start_timer(0.1) {p Time.now-t1} ==> 0.01

              Error: #<SyntaxError: (eval):202: compile error
              (eval):201: parse error
              t1=Time.now; UI.start_timer(5) {p Time.now-t1} ==> 0.01
              ^
              (eval):202: parse error
              t1=Time.now; UI.start_timer(0.1) {p Time.now-t1} ==> 0.01
              ^>
              (eval):202

              1 條回覆 最後回覆 回覆 引用 0
              • tbdT 離線
                tbd
                最後由 編輯

                of course, ==> means what it should return and you must not type that

                SketchUp Ruby Consultant | Podium 1.x developer
                http://plugins.ro

                1 條回覆 最後回覆 回覆 引用 0
                • N 離線
                  N Lindenthal
                  最後由 編輯

                  Yes, TDB, that I could know myself. Excuse me, please.

                  @Jim
                  Your times are the same with me.
                  How can I get ==> 0.5 or ==> 0.99?

                  Mac OS X 10.4.11

                  1 條回覆 最後回覆 回覆 引用 0
                  • tbdT 離線
                    tbd
                    最後由 編輯

                    yup. my bad. I checked only visual and didnt do any time checks.

                    seems that it ignores decimals (0.1...0.9 = 0, 1.1 ... 1.9 = 1) - so we need to use that. for interface like clear selection doesnt matter that much anyway

                    SketchUp Ruby Consultant | Podium 1.x developer
                    http://plugins.ro

                    1 條回覆 最後回覆 回覆 引用 0
                    • N 離線
                      N Lindenthal
                      最後由 編輯

                      To pause is a workaround. Would be better to ask how long

                      Morisdov.transf_get("transf2")
                      
                      

                      works and then clear without pause/delay.

                      Can ruby know how long the earlier line works?

                      1 條回覆 最後回覆 回覆 引用 0
                      • A 離線
                        AlexMozg
                        最後由 編輯

                        Here such variant:

                        
                        time_limit = 0.2
                        @val_time = Time.now
                        @timer = UI.start_timer(0, true) do
                        	if Time.now - @val_time >= time_limit
                        		UI.stop_timer @timer
                        		Sketchup.active_model.selection.clear
                        		@val_time = @timer = nil
                        	end
                        end
                        
                        
                        

                        It works 😄

                        1 條回覆 最後回覆 回覆 引用 0
                        • N 離線
                          N Lindenthal
                          最後由 編輯

                          @AlexMozg

                          Unfortunately it does not work, if this line is before

                          Morisdov.transf_get("transf2")
                          
                          

                          Please try with proper_animation.rb and one selected component with Position 2

                          Morisdov.transf_get("transf2")
                          time_limit = 0.2
                          @val_time = Time.now
                          @timer = UI.start_timer(0, true) do
                             if Time.now - @val_time >= time_limit
                                UI.stop_timer @timer
                                Sketchup.active_model.selection.clear
                                @val_time = @timer = nil
                             end
                          end
                          

                          The selected component will stay selected.

                          1 條回覆 最後回覆 回覆 引用 0
                          • tbdT 離線
                            tbd
                            最後由 編輯

                            welcome to thread synchronization fun - as you can see Morisdov.transf_get uses start_timer
                            so you need to sync with that (e.g. add global variable in transf_get end for example)

                            SketchUp Ruby Consultant | Podium 1.x developer
                            http://plugins.ro

                            1 條回覆 最後回覆 回覆 引用 0
                            • N 離線
                              N Lindenthal
                              最後由 編輯

                              How?

                              1 條回覆 最後回覆 回覆 引用 0
                              • tbdT 離線
                                tbd
                                最後由 編輯

                                btw, did you increased time_limit from AlexMozg example first ? to like 5 ?

                                SketchUp Ruby Consultant | Podium 1.x developer
                                http://plugins.ro

                                1 條回覆 最後回覆 回覆 引用 0
                                • A 離線
                                  AlexMozg
                                  最後由 編輯

                                  And it is possible and so:

                                  
                                  ...
                                  ...
                                  def self.timer(proc, time_limit=0.5)
                                  $val_time = Time.now
                                  $timer = UI.start_timer(0, true) do
                                     if Time.now - $val_time >= time_limit
                                        UI.stop_timer $timer
                                        proc.call
                                        $val_time = $timer = nil
                                     end
                                  end
                                  end
                                  ...
                                  select_comp_by_name("Fahrstuhl")
                                  Morisdov.transf_get("transf2")
                                  self.timer(proc{Sketchup.active_model.selection.clear})
                                  ...
                                  
                                  
                                  

                                  Though it is possible to do without global variables.
                                  But, I do not know that Morisdov.transf_get does.
                                  ;

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • N 離線
                                    N Lindenthal
                                    最後由 編輯

                                    def self.timer(proc, time_limit=0.9)
                                    $val_time = Time.now
                                    $timer = UI.start_timer(0, true) do
                                       if Time.now - $val_time >= time_limit
                                          UI.stop_timer $timer
                                          proc.call
                                          $val_time = $timer = nil
                                       end
                                    end
                                    end
                                    select_comp_by_name("Fahrstuhl")
                                    Morisdov.transf_get("transf2")
                                    self.timer(proc{Sketchup.active_model.selection.clear})
                                    

                                    With 0.9 it works for exactly one time, each next start lets Sketchup crash down.
                                    With 0.2 SketchUp crashes immediately.

                                    I think I have to ask Morisdov by PM.

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • A 離線
                                      AlexMozg
                                      最後由 編輯

                                      @n lindenthal said:

                                      ...
                                      I think I have to ask Morisdov by PM.

                                      Ask me, and I shall try to answer.

                                      1 條回覆 最後回覆 回覆 引用 0
                                      • N 離線
                                        N Lindenthal
                                        最後由 編輯

                                        @alexmozg said:

                                        … Ask me, and I shall try to answer.

                                        Here is my »Fahrstuhl«, english elevator.

                                        My script selects the "Fahrstuhl“, puts it to another position (here position 1 and 2), and then clears the selection:

                                        select_comp_by_name("Fahrstuhl")
                                        Morisdov.transf_get("transf1")
                                        UI.start_timer(1, false) {Sketchup.active_model.selection.clear}
                                        

                                        Position 1

                                        select_comp_by_name("Fahrstuhl")
                                        Morisdov.transf_get("transf2")
                                        UI.start_timer(1, false) {Sketchup.active_model.selection.clear}
                                        

                                        Position 2

                                        To get the script work, the following .rbs must be installed:

                                        1. select_com_by_name.rb
                                        def select_comp_by_name(comp_name)
                                        	model = Sketchup.active_model
                                        	sel = model.selection
                                        	sel.clear
                                        	if compdef = Sketchup.active_model.definitions[comp_name]
                                        		sel.add(compdef.instances)
                                        	else
                                        		Sketchup.active_model.active_entities.each do |d|
                                        			if d.typename == "ComponentInstance"
                                        			sel.add d if d.name==comp_name
                                        		end
                                        	end
                                        		if sel.count == 0
                                        			UI.beep
                                        		else
                                        			UI.messagebox(sel.count.to_s + " gesuchte Dinger gefunden.")
                                        		end
                                        	end
                                        end
                                        
                                        1. proper_animation.rb

                                        My question is, how to select the "Fahrstuhl/elevator" without selection marks.

                                        So I tried to use the following script:

                                        def self.timer(proc, time_limit=1)
                                        $val_time = Time.now
                                        $timer = UI.start_timer(0, true) do
                                           if Time.now - $val_time >= time_limit
                                              UI.stop_timer $timer
                                              proc.call
                                              $val_time = $timer = nil
                                           end
                                        end
                                        end
                                        select_comp_by_name("Fahrstuhl")
                                        Morisdov.transf_get("transf2")
                                        self.timer(proc{Sketchup.active_model.selection.clear})
                                        

                                        Would be a wonder to get the arrows in model be buttons, which start the elevator scripts.


                                        Fahrstuhl = Elevator

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • A 離線
                                          AlexMozg
                                          最後由 編輯

                                          @unknownuser said:

                                          My question is, how to select the "Fahrstuhl/elevator" without selection marks.

                                          The simplest - to make changes to a script "Morisdov".
                                          Somehow here so:

                                          
                                          def Morisdov.transf_get(dict_key, ss=nil)
                                            model=Sketchup.active_model					
                                            ents=model.active_entities
                                             if ss
                                               @ents = ss
                                             else
                                               @ents=[]
                                               model.selection.each {|e| @ents.push(e)}
                                             end											
                                            @ents.freeze
                                            model.selection.clear
                                          ....
                                          ....
                                          end
                                          
                                          

                                          And completely to get rid from selection.

                                          Where I can find "following.rbs"?
                                          I shall think...

                                          1 條回覆 最後回覆 回覆 引用 0
                                          • N 離線
                                            N Lindenthal
                                            最後由 編輯

                                            @alexmozg said:

                                            @unknownuser said:

                                            …And completely to get rid from selection.

                                            Where I can find "following.rbs"?
                                            I shall think...

                                            Yes, rid from selection …

                                            … but how? This way?

                                            select_comp_by_name("Fahrstuhl")
                                            def Morisdov.transf_get(dict_key, ss=nil)
                                              model=Sketchup.active_model               
                                              ents=model.active_entities
                                               if ss
                                                 @ents = ss
                                               else
                                                 @ents=[]
                                                 model.selection.each {|e| @ents.push(e)}
                                               end                                 
                                              @ents.freeze
                                              model.selection.clear
                                            end
                                            

                                            (my poor english) Which "following.rbs" you need?

                                            1 條回覆 最後回覆 回覆 引用 0
                                            • 1
                                            • 2
                                            • 2 / 2
                                            • 第一個貼文
                                              最後的貼文
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement