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

    Optimization Tips

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

      UI.show_inspector "Outliner"
      toggles it.
      Shows it if it's closed
      Rolls it up if it's shown
      Unrolls it if it's rolled up

      There's no way with the API to tell (now) what state it is in.

      I'm not here much anymore.

      1 條回覆 最後回覆 回覆 引用 0
      • TIGT 離線
        TIG Moderator
        最後由 編輯

        I think Jim made a Windows hack to toggle a rollup...

        ### toggleWindows.rb - based on Jim's ideas - only for Windows...
        ### 20090401 TIG
        ### needs "win32api.so"
        if [PLATFORM].grep(/mswin/)==[PLATFORM] and Sketchup.find_support_file("Win32API.so","Plugins/")
        ### = a Windows machine
          require 'Win32API.so'
          def toggleRollUp(name)
            findWindow = Win32API.new("user32.dll","FindWindow",['P','P'],'N')
            pw=findWindow.call(0,name)
            sendMessage = Win32API.new("user32.dll","SendMessage",['N','N','N','P'],'N')
            sendMessage.call(pw,0x00a1,2,"")#WM_NCLBUTTONDOWN
            sendMessage.call(pw,0x0202,0,"")#WM_LBUTTONUP
          end
          def isRolledUp(name)
            findWindow = Win32API.new("user32.dll","FindWindow",['P','P'],'N')
            getWindowRect= Win32API.new("user32.dll","GetWindowRect",['P','PP'],'N')
            pw=findWindow.call(0,name)
            data=Array.new.fill(0.chr,0..4*4).join
            getWindowRect.call(pw,data);
            rect=data.unpack("i*")
            #if window height is less than 90 then the window is rolledup
            return (rect[3]-rect[1])<90
          end
        end#if
        

        You add 'Outliner' to run it... test if rolled up, toggle roll up if not etc etc........

        TIG

        1 條回覆 最後回覆 回覆 引用 0
        • Dan RathbunD 離線
          Dan Rathbun
          最後由 編輯

          its nice but...
          The windows have other language names in the loacalized versions.
          The code needs updating. It needs to search by ID instead.
          (Or have arrays of the Inspector captions in all the local versions.)

          It also should be in the SKX forum, either as a UI module extended method (which would be half done, as it's only Win32,) or a SKX::GUI::WIN method.. or something

          I'm not here much anymore.

          1 條回覆 最後回覆 回覆 引用 0
          • TIGT 離線
            TIG Moderator
            最後由 編輯

            I only pass on Jim's hack... if you want to 'fix' it please do... It'd be better if the API had proper access to these anyway !

            TIG

            1 條回覆 最後回覆 回覆 引用 0
            • K 離線
              kwalkerman
              最後由 編輯

              Dan, this is absolutely what I need. It is the updating of the UI that is slowing the calculation down. Having the outliner window open compounds the problem.

              --
              Karen

              1 條回覆 最後回覆 回覆 引用 0
              • thomthomT 離線
                thomthom
                最後由 編輯

                @kwalkerman said:

                Dan, this is absolutely what I need. It is the updating of the UI that is slowing the calculation down. Having the outliner window open compounds the problem.

                --
                Karen

                You are using .start_operation with the disable_ui flag, right?

                Also, try to do as much as possible in bulk operations. Transform and erase in bulks. entities.erase_entities instead of entity.erase! etc.
                Cache calculation results - Ruby is horribly slow in crunching numbers.
                Often, methods that accepts Point3D objects can use Vertex objects as well - though the API docs doesn't mention this. If you are doing many iteration vertex.position will eat time. So try to feed the methods raw vertices instead.

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 條回覆 最後回覆 回覆 引用 0
                • Dan RathbunD 離線
                  Dan Rathbun
                  最後由 編輯

                  @dan rathbun said:

                  its nice but...
                  The code needs updating. It needs to search by ID instead.
                  (Or have arrays of the Inspector captions in all the local versions.)

                  Ooops.. just checked. The Outliner does not have an ID.
                  But Jim's system call 'may' work. The window object can have a different "name" than the text displayed on the caption bar.
                  Someone running a non-English version could test it and let us know.

                  I'm not here much anymore.

                  1 條回覆 最後回覆 回覆 引用 0
                  • Dan RathbunD 離線
                    Dan Rathbun
                    最後由 編輯

                    @dan rathbun said:

                    @dan rathbun said:

                    The code needs updating. ...
                    (Or have arrays of the Inspector captions in all the local versions.)

                    But Jim's system call 'may' work. The window object can have a different "name" than the text displayed on the caption bar.

                    Someone running a non-English version could test it and let us know.

                    Didier tested it and the results are both good and bad:
                    see: Re: Anyone with non-english Sketchup?

                    I'm not here much anymore.

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

                      @thomthom said:

                      What I found most interesting in those test was that Vertex is a valid argument where the manual claims only Point3d. And passing the Vertex is faster than Vertex.position.

                      Well i think you'll find this is a commonality of the API and the Docs is the fact that "those" who are creating the API and the Docs ARE NOT "those" who use it on a daily basis! 😉

                      Always sleep with a loaded gun under your pillow!

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

                        Hi guys,

                        I have just found out that converting String to Length directly is up to 13x slower in comparision to converting it to Float first and only then to Length...

                        
                        def string_to_length_conversion(iterations=100_000)
                        	a=0
                        	t1=Time.now.to_f
                        	iterations.times do
                        		# convert to Length directly
                        		a = '5,0'.to_l
                        	end
                        	t2=Time.now.to_f
                        	puts "Conversion to Length directly took #{t2-t1} sec, a=#{a}"
                        
                        	t1=Time.now.to_f
                        	iterations.times do
                        		# convert to Float, then apply units (meters in this case) and set to Length
                        		a = '5,0'.to_f.m.to_l
                        	end
                        	t2=Time.now.to_f
                        	puts "Conversion to Length via Float took #{t2-t1} sec, a=#{a}"
                        end
                        #Conversion to Length directly took 1.84500002861023 sec, a=5,00m
                        #Conversion to Length via Float took 0.14300012588501 sec, a=5,00m
                        
                        
                        1 條回覆 最後回覆 回覆 引用 0
                        • thomthomT 離線
                          thomthom
                          最後由 編輯

                          @unknownuser said:

                          I have just found out that converting String to Length directly is up to 13x slower in comparision to converting it to Float first and only then to Length...

                          That is useful to know. But that assumes one has a string with only a numeral.
                          String.to_l will allow you to covert strings such as '20m' and '20mm'. With out any length unit indication in the string it will assume the length is in the unit of the current model.

                          Thomas Thomassen — SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          1 條回覆 最後回覆 回覆 引用 0
                          • TIGT 離線
                            TIG Moderator
                            最後由 編輯

                            BUT remember that .to_l parses any 'units' text to work out the actual value into inches...
                            So "1.0m".to_l >>> 39.3700787401575"
                            or "1'".to_l >>> 12"
                            BUT
                            "1.0m".to_f.to_l >>> 1.0"
                            and "1'".to_f.to_l >>> 1"
                            therefore you may as well miss out the second method .to_l as
                            "1.0m".to_f >>> 1.0
                            and "1'".to_f >>> 1
                            i.e. as a 'raw number'... AND 'raw numbers' are assumed to be in inches anyway == 1.0"...
                            Also .to_l and .to_f work differently if there is no 'unit' suffix...
                            If you have mm set as your current units then
                            "1".to_l >>> 0.0393700787401575 (inches)
                            but "1".to_f >>> [ruby:3h6c8mbs]1.0[/ruby:3h6c8mbs] (float/number),
                            and with inches as the current units
                            "1".to_l >>> [ruby:3h6c8mbs]1[/ruby:3h6c8mbs] (inch)
                            SO if you have an input that might be in anything other than inches and might have units in its string you do need to use .to_l or you risk returning a wrong value... 🤓

                            TIG

                            1 條回覆 最後回覆 回覆 引用 0
                            • Dan RathbunD 離線
                              Dan Rathbun
                              最後由 編輯

                              + vs << vs "#{}"

                              Benchmark Test (at ruby-talk-google)
                              String concatenation in ruby

                              I'm not here much anymore.

                              1 條回覆 最後回覆 回覆 引用 0
                              • thomthomT 離線
                                thomthom
                                最後由 編輯

                                ` t=Time.now; 1000000.times{ 3**2 }; puts Time.now - t
                                0.948
                                nil

                                t=Time.now; 1000000.times{ 3*3 }; puts Time.now - t
                                0.216
                                nil`

                                Thomas Thomassen — SketchUp Monkey & Coding addict
                                List of my plugins and link to the CookieWare fund

                                1 條回覆 最後回覆 回覆 引用 0
                                • thomthomT 離線
                                  thomthom
                                  最後由 編輯

                                  @unknownuser said:

                                  does the whole line have to be in c? im trying to map this out---
                                  %(#0040FF)[]

                                  What do you mean? Are you making a C Extension?

                                  Thomas Thomassen — SketchUp Monkey & Coding addict
                                  List of my plugins and link to the CookieWare fund

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • thomthomT 離線
                                    thomthom
                                    最後由 編輯

                                    @unknownuser said:

                                    THOM THOM WHAT KIND OF SCRIPTING LANGUAGE IS RUBY??????? 😐

                                    Sorry, but I don't understand what 'kind' you mean. Can you elaborate a bit more?

                                    And please, do not use all caps. It's hard to read and it's considered bad manners.

                                    Thomas Thomassen — SketchUp Monkey & Coding addict
                                    List of my plugins and link to the CookieWare fund

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • Dan RathbunD 離線
                                      Dan Rathbun
                                      最後由 編輯

                                      Ruby is a 100% Object-Oriented Interpreted Scripting Language.

                                      See: "Ruby Newbie's Guide to Getting Started"

                                      I'm not here much anymore.

                                      1 條回覆 最後回覆 回覆 引用 0
                                      • Dan RathbunD 離線
                                        Dan Rathbun
                                        最後由 編輯

                                        @unknownuser said:

                                        does the whole line have to be in c? im trying to map this out---

                                        If you are new to Ruby... learn Ruby scripting, don't worry about it's C source code, you'll just confuse yourself. (The Ruby interpreter engine just happens to be written in C and compiled. You don't need to know C unless your involved with actually maintaining / updating the Ruby Core libraries. This has noting to do with using Ruby or writing Ruby scripts, or using Sketchup.)

                                        I'm not here much anymore.

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • thomthomT 離線
                                          thomthom
                                          最後由 編輯

                                          i += 1 vs i = i.next

                                          i=0; t=Time.now; 10000000.times { i+=1 }; Time.now-t
                                          2.045

                                          i=0; t=Time.now; 10000000.times { i=i.next }; Time.now-t
                                          1.682

                                          Thomas Thomassen — SketchUp Monkey & Coding addict
                                          List of my plugins and link to the CookieWare fund

                                          1 條回覆 最後回覆 回覆 引用 0
                                          • TIGT 離線
                                            TIG Moderator
                                            最後由 編輯

                                            @thomthom said:

                                            i += 1 vs i = i.next
                                            i=0; t=Time.now; 10000000.times { i+=1 }; Time.now-t
                                            2.045
                                            i=0; t=Time.now; 10000000.times { i=i.next }; Time.now-t
                                            1.682

                                            So avoid i='0'; t=Time.now; 10000000.times { i.next! }; Time.now-t
                                            ~8.300 😒

                                            TIG

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

                                            Advertisement