sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    [Code] Quick Reference Card in a WebDialog

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 5 Posters 804 Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by Dan Rathbun

      Display the Quick Reference Card in a WebDialog
      (Adds menu item to "Help" menu.)

      (Fixed menu item creation per thomthom's advice below.)

      
      #
      #  Example to display the Quick Reference Card in a WebDialog.
      #  Adds a "Quick Reference Card" item to the "Help" menu.
      #
      
      module Example
      
        module Qcard
      
          @@qcard = nil
          @@qcard_path = File.join(Sketchup.get_resource_path(''),"QuickReferenceCard.pdf")
          @@qcard_local = false
      
          if File.exist?(@@qcard_path)
            @@qcard_local = true
          else
            iver = Sketchup.version.to_i.to_s
            plat =( RUBY_PLATFORM =~ /(darwin)/i ? 'Mac' ; 'Win' )
            @@qcard_path = "http://dl.google.com/sketchup/gsu#{iver}/"
            @@qcard_path << "docs/en/SketchUp#{iver}Refcard#{plat}.pdf"
          end
      
          @@say = { 'menu item text' => 'Quick Reference Card' }
          
          class << self
          
            def qcard
              #
              unless @@qcard
                @@qcard = UI;;WebDialog.new(@@say['menu item text'],true,'Help_Qcard',1000,783,50,100,true)
                if @@qcard_local
                  @@qcard.set_file( @@qcard_path )
                else
                  @@qcard.set_url( @@qcard_path )
                end
              end
              #
              if @@qcard.visible?
                @@qcard.bring_to_front
              else
                RUBY_PLATFORM =~ /(darwin)/i ? @@qcard.show_modal ; @@qcard.show
              end
              #
            end
          
          end # proxy class
      
          unless file_loaded?('Example;;Qcard')
            if Sketchup;;Menu.instance_method(;add_item).arity == 1
              UI.menu('Help').add_item(@@say['menu item text']) { qcard() }
            else
              UI.menu('Help').add_item(@@say['menu item text'],3) { qcard() }
            end
            file_loaded('Example;;Qcard')
          end
      
        end # module Qcard
      
      end # module Example
      

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • D Offline
        driven
        last edited by

        hi dan

        coming up blank, but no errors,
        if I linefeed the path bits and the WD bits, it appears in a pdf reader view... like it should.

        can't see why it's not running when intact?
        john

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

        1 Reply Last reply Reply Quote 0
        • S Offline
          slbaumgartner
          last edited by

          On my Mac, the WebDialog opens and spins a bit and then SketchUp crashes.

          Steve

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            <span class="syntaxdefault"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxkeyword">if&nbsp;</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">version</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_i&nbsp;</span><span class="syntaxkeyword">>&nbsp;</span><span class="syntaxdefault">7<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Help'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(@@</span><span class="syntaxdefault">say</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'menu&nbsp;item&nbsp;text'</span><span class="syntaxkeyword">],</span><span class="syntaxdefault">3</span><span class="syntaxkeyword">)&nbsp;{&nbsp;</span><span class="syntaxdefault">qcard</span><span class="syntaxkeyword">()&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Help'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(@@</span><span class="syntaxdefault">say</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'menu&nbsp;item&nbsp;text'</span><span class="syntaxkeyword">])&nbsp;{&nbsp;</span><span class="syntaxdefault">qcard</span><span class="syntaxkeyword">()&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">end<br /></span>
            

            The second argument wasn't added in the first SU8 release. A safer way is to test for functionality instead of version (like you do in webdesign: test for features instead of user agent strings)

            <span class="syntaxdefault"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxkeyword">if&nbsp;</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Menu</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">instance_method</span><span class="syntaxkeyword">(;</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">arity&nbsp;</span><span class="syntaxkeyword">==&nbsp;</span><span class="syntaxdefault">1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Help'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(@@</span><span class="syntaxdefault">say</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'menu&nbsp;item&nbsp;text'</span><span class="syntaxkeyword">])&nbsp;{&nbsp;</span><span class="syntaxdefault">qcard</span><span class="syntaxkeyword">()&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'Help'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(@@</span><span class="syntaxdefault">say</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'menu&nbsp;item&nbsp;text'</span><span class="syntaxkeyword">],</span><span class="syntaxdefault">3</span><span class="syntaxkeyword">)&nbsp;{&nbsp;</span><span class="syntaxdefault">qcard</span><span class="syntaxkeyword">()&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">end<br /></span>
            

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

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @thomthom: Fixed OP code post per your good advice.

              @others: This code is really a test to see how the WebDialog handles both local and remote PDF documents without a wrapping HTMl page. (Just letting the browser control load the PDF viewer.)

              (1) The reason I have a check for a local PDF file, in the localized resource directory, with the exact filename "QuickReferenceCard.pdf", is because that was what was designed into SketchUp via:
              Sketchup.send_action(21466)
              which opens the file using Adobe Reader, if it exists, and displays "Cannot find file.." messagebox if it does not.
              Apparently, they were planning on having multi-language "Qcards" but never got beyond creating just the English edition.

              (2) There is really a problem remotely accessing the PDFs on the download.trimble.com site because of the expiration and unique signature fields.
              Even on PC, it loads the first time in a session, but not if you close the dialog, and re-open it.

              Likely it will work faster if the file is local.
              They can be downloaded here:
              http://support.google.com/sketchup/bin/answer.py?hl=en&answer=116693
              No easy way via the API to download and save a file into the local resources folder. (Basically a bad idea, because this is an application "owned" folder.)

              (3) Not going to create a plugin from this... just testing. Perhaps Alex or someone else who already has a Help/Reference extension, can add this feature in.

              (4) Also.. too bad the card is not in HTML, or a translator could translate it.
              (And it could be updated to say "Trimble" instead of "Google".)

              đź’­

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @driven said:

                coming up blank, but no errors,
                if I linefeed the path bits and the WD bits, it appears in a pdf reader view... like it should.

                can't see why it's not running when intact?

                Well for a local file, do you need to prepend "localhost://" or "file://" on the Mac ?
                IE, we might need to insert a conditional for Mac that prepends whatever is needed.

                I think the remote problems are in the way that the download site is set up. If the PDF files were just in a directory allowing ftp access, there would not be a problem.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  @dan rathbun said:

                  (1) The reason I have a check for a local PDF file, in the localized resource directory, with the exact filename "QuickReferenceCard.pdf", is because that was what was designed into SketchUp via:
                  Sketchup.send_action(21466)
                  which opens the file using Adobe Reader, if it exists, and displays "Cannot find file.." messagebox if it does not.

                  And you like it in a separate window (rather than a child window that is always on top,) the equiv. for the integer action would be something like:
                  UI.openURL(@@qcard_path)

                  So on my machine where Chrome is my default browser:
                  UI.openURL('http://dl.google.com/sketchup/gsu8/docs/en/SketchUp8RefcardWin.pdf')
                  ... opens it remotely but in a Chrome tab.

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • alexschreyerA Offline
                    alexschreyer Extension Creator
                    last edited by

                    Thanks for the tip! I should really add it to the RCE.

                    With regards to loading from web failing: Have you tried adding a random number parameter to the end of the URL, so that it doesn't get cached by IE? As in: http://dl.google.com/sketchup/gsu8/docs/en/SketchUp8RefcardWin.pdf?p=randomnumber

                    Author of "Architectural Design with SketchUp":
                    http://sketchupfordesign.com/

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      No I did not try that.

                      Did you open IE and paste in the url, so you can see the hidden input fields ?

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        driven
                        last edited by

                        @all,
                        Retested latest version [with TT's bit] and it all works on my mac...
                        john

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

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          slbaumgartner
                          last edited by

                          @driven said:

                          @all,
                          Retested latest version [with TT's bit] and it all works on my mac...
                          john

                          I now get a blank window. John, do you have a custom WebKit installed? Or some kind of PDF viewer plugin?

                          Steve

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            driven
                            last edited by

                            @slbaumgartner said:

                            John, do you have a custom WebKit installed? Or some kind of PDF viewer plugin?

                            Are you insinuating that I may have tampered with my SU instal;)

                            I have the standard WebKit

                            SU WebDialog doesn't seem to use Safari's
                            WebKit built-in PDF
                            — from file “”.
                            MIME Type Description Extensions
                            application/pdf Portable Document Format pdf

                            but instead seems to be using

                            Adobe Acrobat and Reader Plug-in
                            Adobe Acrobat and Reader Plug-in for Web Browsers, Version 9.5.2 — from file “AdobePDFViewer.plugin”.

                            have a look what yours are...

                            html=%q(
                            <html>
                            
                                <head>
                                    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
                                    <title>Installed Plug-ins</title>
                                <style type="text/css">
                                        body { color; #555; }
                                        div#margins { margin; 5%; }
                                        
                                        div.plugin-name {
                                            margin-top; 2em;
                                            margin-bottom; 1en;
                                            font-size; large;
                                            font-weight; bold;
                                            color; black;
                                        }
                                        
                                        table {
                                            background-color; #F5F5F5;
                                            color; #222;
                                            font; message-box;
                                            width; 100%;
                                            border; 1px solid #222;
                                            border-spacing; 0px;
                                        }
                                        
                                        th {
                                            text-align; center;
                                            font-weight; bold;
                                            background-color; #CCC;
                                        }
                                        
                                        th + th, td + td { border-left; 1px solid #AAA; }
                                        td               { border-top; 1px solid #AAA;  }
                                        th, td           { padding; 3px; }
                                        
                                        td.extensions    { text-align; center; }
                                        
                                        th.MIME-type     { width; 30%; }
                                        th.description   { width; 50%; }
                                        th.extensions    { width; 20%; }
                                    </style>
                                </head>
                            
                                <body>
                                    <div id="margins">
                                        <script type="application/x-javascript">
                            
                                            // Localizers; Translate the title above, and these six strings, and leave the rest of the file intact.
                            
                                            var InstalledPlugIns = "Installed Plug-ins";
                                            var BetweenDescriptionAndFilename = " &mdash; from file &ldquo;";
                                            var AfterFilename = "&rdquo;.";
                                            var MIMETypeColumnHeader = "MIME Type";
                                            var DescriptionColumnHeader = "Description";
                                            var ExtensionsColumnHeader = "Extensions";
                            
                                            // Now the code.
                            
                                            navigator.plugins.refresh(false); // Supposedly helps if new plug-ins were added.
                            
                                            var plugins = [];
                                            for (var pi = 0; pi < navigator.plugins.length; pi++) {
                                                plugins.push(navigator.plugins[pi]);
                                            }
                            
                                            plugins.sort(function(a, b) {
                                                return a.name.localeCompare(b.name);
                                            });
                                            
                                            for (var pi = 0; pi < plugins.length; pi++) {
                                                var plugin = plugins[pi];
                            
                                                document.writeln("<div class=\"plugin-name\">" + plugin.name + "<\/div>");
                            
                                                document.writeln("<blockquote>" + plugin.description + BetweenDescriptionAndFilename + plugin.filename + AfterFilename + "<\/blockquote>");
                            
                                                document.writeln("<table class=\"types-table\">");
                            
                                                document.writeln("<thead><tr>");
                                                document.writeln("<th class=\"MIME-type\">" + MIMETypeColumnHeader + "<\/th>");
                                                document.writeln("<th class=\"description\">" + DescriptionColumnHeader + "<\/th>");
                                                document.writeln("<th class=\"extensions\">" + ExtensionsColumnHeader + "<\/th>");
                                                document.writeln("<\/tr><\/thead>");
                            
                                                document.writeln("<tbody>");
                                                for (var mi = 0; mi != plugin.length; ++mi) {
                                                    document.writeln("<tr>");
                                                    document.writeln("<td class=\"MIME-type\">" + plugin[mi].type + "<\/td>");
                                                    document.writeln("<td class=\"description\">" + plugin[mi].description + "<\/td>");
                                                    document.writeln("<td class=\"extensions\">" + plugin[mi].suffixes + "<\/td>");
                                                    document.writeln("<\/tr>");
                                                }
                                                document.writeln("<\/tbody>");
                            
                                                document.writeln("<\/table>");
                                            }
                            
                                        </script>
                                    </div>
                                </body>
                            
                            </html>
                            
                            )
                            dlg = UI;;WebDialog.new("Instaled_Webkit_Plugins", true,
                               "ISP", 739, 641, 150, 150, true);
                             dlg.set_html(html)
                             dlg.show_modal
                            

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

                            1 Reply Last reply Reply Quote 0
                            • D Offline
                              driven
                              last edited by

                              @Dan,
                              sorry for the detour...

                              I just disabled 'Adobe Reader' and it doesn't 'list' the alt "webKit PDF plugin", but it did open in it,
                              and it includes the option to open in Preview.app, from which I can 'save as' at the 'correct' local path.

                              if I then add, as suggested...

                              @@qcard.set_file( "file;///" + @@qcard_path )
                              

                              it is working locally and I don't get the 'access denied' if I do a manual reload of the page...

                              on my mac your test now appears to be functional.
                              john

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

                              1 Reply Last reply Reply Quote 0
                              • Dan RathbunD Offline
                                Dan Rathbun
                                last edited by

                                OK so, ... to display PDF in a WebDialog (on either platform,) the user must have installed Adobe Reader plugin for their browser ??

                                IF true.. (for the case of a "qcard",) it might be easier to convert the Quick Reference Card to HTML. (Which can be translated more easily?)

                                This test was really about displaying PDFs in a WebDialog, and I used the "qcard" as the test file.

                                Maybe the conclusion is that PDFs are problematic ??

                                I'm not here much anymore.

                                1 Reply Last reply Reply Quote 0
                                • S Offline
                                  slbaumgartner
                                  last edited by

                                  @driven said:

                                  @slbaumgartner said:

                                  John, do you have a custom WebKit installed? Or some kind of PDF viewer plugin?

                                  Are you insinuating that I may have tampered with my SU instal;)

                                  I have the standard WebKit

                                  SU WebDialog doesn't seem to use Safari's
                                  WebKit built-in PDF
                                  — from file “”.
                                  MIME Type Description Extensions
                                  application/pdf Portable Document Format pdf

                                  but instead seems to be using

                                  Adobe Acrobat and Reader Plug-in
                                  Adobe Acrobat and Reader Plug-in for Web Browsers, Version 9.5.2 — from file “AdobePDFViewer.plugin”.

                                  Nice plugin scanner, John!

                                  I got
                                  Adobe Acrobat and Reader Plug-in for Web Browsers, Version 9.0.0 — from file “AdobePDFViewer.plugin”.

                                  So maybe there's a version sensitivity involved? In any case, it seems to support Dan's feeling that PDF display via WebDialog is not reliable from machine to machine..

                                  Steve

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  • First post
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement