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!
    🔌 Smart Spline | Fluid way to handle splines for furniture design and complex structures. Download

    VCB and Shortcut Keys

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

      @thomthom said:

      I looked further at the behaviour of the Tool class - using variations of this snippet to inspect the behaviour:

      thomthom,

      Your help is well above and beyond anything I could ask for. Thanks again. I am loading the snippet to complete the "etc" and see if there are keys I can use.

      Joe....
      http://www.srww.com

      1 條回覆 最後回覆 回覆 引用 0
      • D 離線
        driven
        最後由 編輯

        Hi Joe,
        your script partially works on mac with to_f added @ line 4.
        jumps out of tool if you hit a   q t o p a f h l
        a lot of Capitals work as well, e.g LBWH all work, as a block or on their own...

        
        value = text.to_f.to_l #<<ADDED  TO FLOAT
        
        

        john

        learn from the mistakes of others, you may not live long enough to make them all yourself...

        1 條回覆 最後回覆 回覆 引用 0
        • ChiefwoodworkerC 離線
          Chiefwoodworker
          最後由 編輯

          @driven said:

          Hi Joe,
          your script partially works on mac with to_f added @ line 4.

          Interesting John. On my Windows PC I modified the script as follows:

          <span class="syntaxdefault">def onUserText</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">text</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> view</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    puts</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Text is a #{text.class} class."</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    begin<br />      value </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> text</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_l<br />      puts</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Value is a #{value.class} class."</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">    rescue<br />      </span><span class="syntaxcomment"># Error parsing the text<br /></span><span class="syntaxdefault">      UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">beep<br />      puts </span><span class="syntaxstring">"Cannot convert #{text} to a Length"<br /></span><span class="syntaxdefault">      value </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> nil<br />      Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">set_status_text </span><span class="syntaxstring">""</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> SB_VCB_VALUE<br />    end<br />    return if </span><span class="syntaxkeyword">!</span><span class="syntaxdefault">value<br />    if </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">state </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> 1 and </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">stick_pt2</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">valid</span><span class="syntaxkeyword">?<br /></span><span class="syntaxdefault">      build_story_stick</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">true</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> value</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">      new_stick<br />    end<br />  end</span>
          

          and get the following puts to the console. No complaints of coercing String to Length.

          Text is a String class.
          Value is a Length class.

          But your code is clearly more correct and you may have saved me a Mac bug. Very interesting that it works on the PC but not the Mac.

          Joe....
          http://www.srww.com

          1 條回覆 最後回覆 回覆 引用 0
          • ChiefwoodworkerC 離線
            Chiefwoodworker
            最後由 編輯

            @chiefwoodworker said:

            But your code is clearly more correct and you may have saved me a Mac bug. Very interesting that it works on the PC but not the Mac.

            Whoops! Let me correct myself. SketchUp has a String def called to_l so the you don't need the to_f. Are you sure it doesn't work without the to_f?

            Joe....
            http://www.srww.com

            1 條回覆 最後回覆 回覆 引用 0
            • D 離線
              driven
              最後由 編輯

              with your original code, I get
              Cannot convert 1w to a Length
              if I change only this line

              value = text.to_f.to_l #just to do something
              

              I get 1w in the message box...

              with your last code I get an empty message box, with or without the .to_f

              john

              learn from the mistakes of others, you may not live long enough to make them all yourself...

              1 條回覆 最後回覆 回覆 引用 0
              • S 離線
                slbaumgartner
                最後由 編輯

                Ya gotta love it! The following works just fine on the Mac, even though h is the shortcut for the pan tool, but fails on Windows by switching to pan.

                <span class="syntaxdefault"></span><span class="syntaxkeyword">class&nbsp;</span><span class="syntaxdefault">MyTool<br />&nbsp;&nbsp;def&nbsp;onUserText</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">rawtext</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">view</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">begin<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"VCB&nbsp;held&nbsp;#{rawtext}"</span><span class="syntaxkeyword">)&nbsp;</span><span class="syntaxcomment">#&nbsp;show&nbsp;the&nbsp;raw&nbsp;input<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxkeyword">if(</span><span class="syntaxdefault">rawtext</span><span class="syntaxkeyword">[-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">chr&nbsp;</span><span class="syntaxkeyword">=~&nbsp;/[</span><span class="syntaxdefault">wh</span><span class="syntaxkeyword">]/)&nbsp;</span><span class="syntaxcomment">#trap&nbsp;and&nbsp;strip&nbsp;key&nbsp;characters&nbsp;if&nbsp;present<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">key&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">rawtext</span><span class="syntaxkeyword">[-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">chr<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">rawtext</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">chop</span><span class="syntaxkeyword">!<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">text&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">rawtext<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">text</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_l&nbsp;</span><span class="syntaxcomment">#see&nbsp;if&nbsp;text&nbsp;is&nbsp;convertible&nbsp;to&nbsp;a&nbsp;length<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">rescue<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxcomment">#&nbsp;can't&nbsp;process&nbsp;the&nbsp;VCB&nbsp;input.&nbsp;&nbsp;This&nbsp;could&nbsp;be&nbsp;because&nbsp;the&nbsp;trailing&nbsp;character<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;isn't&nbsp;one&nbsp;of&nbsp;the&nbsp;key&nbsp;characters&nbsp;or&nbsp;because&nbsp;the&nbsp;text&nbsp;isn't&nbsp;a&nbsp;number<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">beep<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts&nbsp;</span><span class="syntaxstring">"Cannot&nbsp;convert&nbsp;#{rawtext}&nbsp;to&nbsp;Length&nbsp;with&nbsp;optional&nbsp;key"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">value&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">nil<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">set_status_text&nbsp;</span><span class="syntaxstring">""</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">SB_VCB_VALUE<br />&nbsp;&nbsp;&nbsp;&nbsp;end<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxkeyword">return&nbsp;if&nbsp;!</span><span class="syntaxdefault">value<br />&nbsp;&nbsp;&nbsp;&nbsp;UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">messagebox</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Got&nbsp;value&nbsp;=&nbsp;#{value},&nbsp;key&nbsp;=&nbsp;#{key}"</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;</span><span class="syntaxdefault">end<br />end<br />Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">select_tool</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">MyTool</span><span class="syntaxkeyword">.new&nbsp;)&nbsp;</span><span class="syntaxdefault"></span>
                

                Steve

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

                  Why not take your normal 'numbers' text as your lengths, and then use key-down checks for toggling what it means ?
                  Like Cmd/Ctrl, Shift etc *** - so on one press of that key it expects one type of value [shown in status-bar] on the next press it's something else = i.e. it's a 'toggle'.

                  ***You can use TAB key action as a toggle BUT it must be key-up as the MAC doesn't recognize tab-down - only tab-up !

                  TIG

                  1 條回覆 最後回覆 回覆 引用 0
                  • ChiefwoodworkerC 離線
                    Chiefwoodworker
                    最後由 編輯

                    @tig said:

                    Why not take your normal 'numbers' text as your lengths, and then use key-down checks for toggling what it means ?
                    Like Cmd/Ctrl, Shift etc *** - so on one press of that key it expects one type of value [shown in status-bar] on the next press it's something else = i.e. it's a 'toggle'.

                    ***You can use TAB key action as a toggle BUT it must be key-up as the MAC doesn't recognize tab-down - only tab-up !

                    Hi TIG,

                    That is exactly what I will end up doing in my tool. So as far as I am concerned I have a solution to the problem I raised, thanks to the folks like you who responded to my original question.

                    However, I think the bigger issue here is that there are scripts in this thread that work on the Mac and not the PC, and scripts that work on the PC and not the Mac. Apparently the Mac is not aware of the String class to_l method and the PC doesn't handle the h shortcut key correctly. Although I would argue that the PC is handling the h shortcut key the way I would like it to and the PC and Mac are handling shortcut keys when they shouldn't be if the VCB is active for user input.

                    I for one just wish that release 2013 spent more time on bug fixes, platform inconsistencies and Ruby API maintenance than it did on icon changes which are driving me nuts and causing me a lot of work.

                    But again, thank you and the others who helped me on this issue.

                    Joe....
                    http://www.srww.com

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

                      @driven said:

                      with your original code, I get
                      Cannot convert 1w to a Length
                      if I change only this line

                      value = text.to_f.to_l #just to do something
                      

                      I get 1w in the message box...

                      with your last code I get an empty message box, with or without the .to_f

                      john

                      What should "1w" represent?

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

                      1 條回覆 最後回覆 回覆 引用 0
                      • D 離線
                        driven
                        最後由 編輯

                        @thomthom said:

                        What should "1w" represent?

                        chosen at random, maybe 1*width or 1 womble
                        john

                        learn from the mistakes of others, you may not live long enough to make them all yourself...

                        1 條回覆 最後回覆 回覆 引用 0
                        • ChiefwoodworkerC 離線
                          Chiefwoodworker
                          最後由 編輯

                          @driven said:

                          @thomthom said:

                          What should "1w" represent?

                          chosen at random, maybe 1*width or 1 womble
                          john

                          I'm with you John. I calculate all my dimensions in wombles.

                          Joe....
                          http://www.srww.com

                          1 條回覆 最後回覆 回覆 引用 0
                          • icehuliI 離線
                            icehuli
                            最後由 編輯

                            additional observation:
                            If onKeyDown or onKeyUp returns true then onCancel is not triggered. It is blocked by onKeyDown/onKeyUp as well.

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

                            Advertisement