sketchucation logo sketchucation
    • Login
    šŸ¤‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Plugin DLL

    Scheduled Pinned Locked Moved Developers' Forum
    29 Posts 4 Posters 6.9k Views
    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.
    • A Offline
      Alienizer
      last edited by

      Assuming that you have a ruby script with only the following line...

      require 'TestPlugin.dll'

      Using the 2.0 type library I have the complete set of commands and properties available, and the TestPlugin.dll does load when Sketchup starts, but I don't know how to get the Sketchup CoSkpApplication interface! If I use Connect, it stalls forever.

      Does anyine knows how this works? Does Sketchup sends something to the DLL when it loads? Or is there a callback of some sort, anything?

      This link shows an example how to get the Application interface if you have the document object, but how do you get the document to begin with!?

      Link Preview Image
      Reading Textures from a SketchUp Model Using the Reader SDK

      Posted by Sang Ahn, SketchUp Software Engineer In case you haven't looked yet, we have an SDK that allows you to read SketchUp files using ...

      favicon

      (sketchupapi.blogspot.com)

      Thanks

      I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

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

        In Ruby..

        doc = Sketchup.active_model

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • A Offline
          Alienizer
          last edited by

          @dan rathbun said:

          In Ruby..

          doc = Sketchup.active_model

          Yes I know, but how do you get the "Sketchup" object in a DLL when it loads?

          I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

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

            @alienizer said:

            ..., but how do you get the "Sketchup" object in a DLL when it loads?

            Look in your SDK \SkpReader\Documentation
            folder for file:
            _write_textures_and_u_vs_8cpp-example.html

            This forum is used by mostly Ruby guys, so you should probably post your questions in the C++ SDK forum at Google Groups (where most of the C++ guys will see them.)
            http://groups.google.com/group/su-sdk-fileshare/topics

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • A Offline
              Alienizer
              last edited by

              Thanks Dan

              I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

              1 Reply Last reply Reply Quote 0
              • Al HartA Offline
                Al Hart
                last edited by

                You need some sample code called Simple Extension.

                SketchUp doesn't seem to make it available, but they will let me send you a copy. See this thread: http://forums.sketchucation.com/viewtopic.php?f=80&t=13548

                Send an email to al.hart@renderplus.com and I will try to send you a copy (if I can find one)

                The "secret" is that you create a dll called, for example, ABC.DLL, then do require('ABC.dll'), (with the proper path, etc.), SkethchUp will load it and make a call to Init_ABC() (the name of your DLL) and you take it from there.

                The sample DLL is linked with Ruby DLLs and cann access and modify SketchUp classes and more.

                Al Hart

                http://wiki.renderplus.com/images/e/ef/Render_plus_colored30x30%29.PNG
                IRender nXt from Render Plus

                1 Reply Last reply Reply Quote 0
                • A Offline
                  Alienizer
                  last edited by

                  That's exactly what I'm after Al. I sent you an email. I appreciate all your help. šŸ˜

                  I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                  1 Reply Last reply Reply Quote 0
                  • Al HartA Offline
                    Al Hart
                    last edited by

                    @alienizer said:

                    That's exactly what I'm after Al. I sent you an email. I appreciate all your help. šŸ˜

                    I found my previous emails and found a link to it, and sent it off to you.

                    Good Luck! (There is nothing easy about figuring this out and getting it to work.)

                    If you have some questions, post them here.

                    Al Hart

                    http://wiki.renderplus.com/images/e/ef/Render_plus_colored30x30%29.PNG
                    IRender nXt from Render Plus

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      Alienizer
                      last edited by

                      Thanks Al, this will help me so much I appreciate your time and super fast reply.

                      I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

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

                        I wonder if we ( the community ) can set up a wiki page for how to create C extensions for SketchUp? It'd really help people getting into it.

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

                        1 Reply Last reply Reply Quote 0
                        • Al HartA Offline
                          Al Hart
                          last edited by

                          We could put documentation on how to use it in Google Docs - either starting a new one - on on the SuWiki now located in the SketchUp Sage Site

                          What SketchUp told me was:

                          @unknownuser said:

                          I believe Sang has (or will have) simple extensions in our SDK soon, but in the meantime it's perfectly okay to distribute this. The more people who know the techniques, the better.

                          Here is what I have been sending people:

                          @unknownuser said:

                          You can download a copy from:

                          http://www.renderplus.com/downloads/SimpleExtension.zip

                          This is basically a Ruby Extension - and SketchUp has created a sample.

                          This lets you can C-code functions directly from SketchUp ruby, call SketchUp ruby functions directly from C-code, and also access SketchUp classes directly from C-code.

                          What would be good would be a case study where a new user tries to use it, and points out what it is difficult, gets help, etc.

                          Al Hart

                          http://wiki.renderplus.com/images/e/ef/Render_plus_colored30x30%29.PNG
                          IRender nXt from Render Plus

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            Alienizer
                            last edited by

                            I totally agree, and we should be able to write plugins entirely in a dll. First, I'm sure it's faster to execute since it's compiled, rather than interpreted by Ruby.

                            But I think the Sample Extension is incomplete. It will not compile as-is. All the rb_ functions are undefined, unless I'm missing something?

                            I can now see the concept, but it seems that every calls are passed as text, again slowing down the dll. Might as well write it all in ruby!

                            What about the Type Library 2.0? This gives us complete access to the Sketchup API, without having ruby as the middle man. If we can get the ISkpApplication interface when the dll loads, we are in business, every API calls are visible, and easy to use, ISkpOptionsManager, ISkpOptionsProvider, ISkpEntities, ISkpCurve, ISkpFileWriter to name a few.

                            I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

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

                              @alienizer said:

                              But I think the Sample Extension is incomplete. It will not compile as-is. All the rb_ functions are undefined, unless I'm missing something?

                              You are.. šŸ˜‰

                              You will need to download the Ruby source (Ruby is written in C,) and include ruby.h (and perhaps tchar.h)
                              See the ol' Pick-Axe Ruby book chapter: Extending Ruby

                              Link to SU 8.x Ruby source (v1.8.6-p287) zip
                              Link to Ruby 1.8.x branch source dir

                              I'm not here much anymore.

                              1 Reply Last reply Reply Quote 0
                              • Al HartA Offline
                                Al Hart
                                last edited by

                                @alienizer said:

                                I totally agree, and we should be able to write plugins entirely in a dll. First, I'm sure it's faster to execute since it's compiled, rather than interpreted by Ruby.

                                After you get the DLL working, you can access and modify SketchUp classes directly from the C-code. However, it turns out that it is somewhat slower to do things in C-code.

                                So we left most routines which access SketchUp classes in RUBY. We use the DLL to let us access Windows features, use Windows dialogs, etc. Also, things which do not directly access SketchUp classes are much faster in C++.

                                Al Hart

                                http://wiki.renderplus.com/images/e/ef/Render_plus_colored30x30%29.PNG
                                IRender nXt from Render Plus

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

                                  @alienizer said:

                                  I totally agree, and we should be able to write plugins entirely in a dll.

                                  There is a future pitfall for DLL files. Their support has been removed for the Ruby 1.9.x branch (which we are hoping that Sketchup begins using soon. Unicode string support etc.)
                                  Anyway... the require() method will not load files with a DLL extension in Ruby 1.9.x

                                  You do not need a real DLL file (to write a Sketchup plugin,) unless you are exporting DLL functions for public use by other non-Sketchup / non-Ruby programs.

                                  Compile as a .so (source object) file if a DLL is not necessary.

                                  BTW... you can always use the WinAPI C call LoadLibrary() to load a DLL. You can make the call using the Ruby Win32API.so extension, or Daniel Berger's newer win32-api package.

                                  I'm not here much anymore.

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

                                    A few more links:

                                    ruby embedded into c++
                                    Tutorial, Guide, Howto
                                    by Simon neoneye Strandgaard

                                    stackoverflow forum topic:
                                    How to embed Ruby in C++?
                                    ... which mentions a textfile that comes with the Ruby source, named: README.EXT

                                    README.EXT.txt

                                    I'm not here much anymore.

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

                                      Other threads on this issue:

                                      Getting Started with C++ and Sketchup

                                      Ruby extension module using C/C++ (mostly about using SWIG)

                                      Example of Compiled Extension with SWIG and CMake

                                      Ruby C++ extension crashes SketchUp

                                      Re: Optimization Tips (discussing Ruby vs C speed)

                                      Programming in C, C++ for Mac and Windows?

                                      Are Swig generated Ruby bindings compatible with Sketchup?

                                      Examples:

                                      TBD's SUExt extension example

                                      I'm not here much anymore.

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

                                        Added an [Info] page to the [Code Snippets] sticky thread, specifically for C/C++ coding links, etc.

                                        I'm not here much anymore.

                                        1 Reply Last reply Reply Quote 0
                                        • A Offline
                                          Alienizer
                                          last edited by

                                          Thanks to both of you, Al and Dan.

                                          But I'm not sure which way to go anymore! I was under the impression that compiled code would run faster than ruby interpreter!!! As of ruby 1.8, the code is interpreted, not compiled into pcode or anything. So that confuses me even more.

                                          So if 1.9 will not load a dll with require(), then there is no more point on writing a dll is there? The reason I wanted to do this in the first place is for speed, and the fact that I can created windows which you can't do in ruby unless you use html, but again, html is limited, and need extra files, javascript etc.

                                          So what do you guys suggest? Which way is best for now and the future? I mean, they way to go about writing plugins? Simply using ruby and that's it? No more COM or anything?

                                          I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

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

                                            @al hart said:

                                            @unknownuser said:

                                            You can download a copy from:

                                            http://www.renderplus.com/downloads/SimpleExtension.zip

                                            This is basically a Ruby Extension - and SketchUp has created a sample.

                                            What would be good would be a case study where a new user tries to use it, and points out what it is difficult, gets help, etc.

                                            Item (1): coders need to download Ruby source (links here)

                                            Item (2): in the package, file stdafx.h, line 54:
                                            #include "C:/ruby/source/ruby-1.8.2/ruby.h"
                                            needs to be changed to the correct Ruby version source dir, for the plugin's targeted Sketchup version (ruby-1.8.0 for SU < 8, ruby-1.8.6-p287 for SU 8+)

                                            Item (3): WIN Sketchup is a MFC application. The package assumes the user will have a full edition of MS Visual Studio, which comes with the MFC source files.
                                            Visual Studio Express editions do not come with these files.

                                            Express users can manually add the MFC header files, by installing the Windows Driver Kit Version 7.1.0 The download is an ISO DVD image, but some archive apps can open this type of file, such as 7zip, so you need not waste a blank DVD.

                                            If you manually copy the header files from the ISO arhive, it looks as though the header files may need to be copied & renamed, ie: "_afxwin.h_00593" to "afxwin.h"
                                            Then these files either:

                                            1. moved to the Windows SDK/includedir, or the appropriate Visual Studio include dir, or 1. set VS-Express to use your WDK/include dir, via the Tools (menu) > Options (dialog)

                                            If you install the WDK then you will not need to rename files, and the Installer may ask if you wish to integrate with Visual Studio, so the include paths may be added for you.

                                            VS_CPP_includepath.png

                                            I'm not here much anymore.

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

                                            Advertisement