sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Ruby extension module using C/C++

    Scheduled Pinned Locked Moved Developers' Forum
    17 Posts 5 Posters 4.0k 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.
    • thomthomT Offline
      thomthom
      last edited by

      You wouldn't have an example or two would you?
      And are we talking cross platform?

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

      1 Reply Last reply Reply Quote 0
      • M Offline
        macumber
        last edited by

        You can download SWIG at http://www.swig.org/ and build some of the Ruby examples. Then you just put the compiled dll in the Ruby search path for SketchUp and require it like a Ruby script. To be binary compatible with the SketchUp Ruby you should compile with MSVC on Windows and gcc on Mac. You do have to compile separately for each platform, the makefiles/Visual Studio projects are not cross platform so you either need to maintain separate projects or use something like CMake (which is a cross platform makefile generator).

        I don't know if the dll will make it through as an attachment (rename 'example.txt' to 'example.dll') but I compiled the example 'C:\SWIG\Examples\ruby\class' using Visual Studio Express 2009 and attached the dll. You can put it in the plugins directory and use the following script:

        ###########################################
        require 'example'

        c = Example::Circle.new(1)
        puts c
        s = Example::Square.new(1)
        puts s
        ###########################################

        Hope that helps,
        Dan


        example.txt

        1 Reply Last reply Reply Quote 0
        • M Offline
          macumber
          last edited by

          In case anyone tries this on Windows, this post helped me out when I was first starting:

          http://apocryph.org/2007/06/16/totally_bullshit_ruby_extension_experience_windows/

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

            @macumber said:

            To be binary compatible with the SketchUp Ruby you should compile with MSVC on Windows and gcc on Mac. You do have to compile separately for each platform, the makefiles/Visual Studio projects are not cross platform so you either need to maintain separate projects or use something like CMake (which is a cross platform makefile generator).

            Visual C++ Express 2010 - will that work? Or does it require a particular version?

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

            1 Reply Last reply Reply Quote 0
            • M Offline
              macumber
              last edited by

              I think the main things are to link against the same version of the Microsoft Runtime library (MSVCRT.DLL, looks like Sketchup 7.1 uses MSVCRT 7.0.2600.5512) and same version of Ruby (1.8.0, although I have used 1.8.6 without problem so far...). There is a fork between MSVC and MinGW camps for Ruby on Windows, make sure you don't try to link against the MinGW build of Ruby.

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

                And how can I obtain this exact DLL version?
                (I'm very green to C/C++)

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

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

                  @dan rathbun said:

                  There is strange effect when MS Common Controls 6 are ON: the images for the 4 buttons on the left of the Sketchup statusbar don't render (at least on XP, but I don't use those buttons anyway, so it's OK with me.)

                  Are they subclassed perhaps?

                  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 said:

                    Are they subclassed perhaps?

                    Not as far as I can tell.
                    UI-Spy shows them as just 'ContolType.Button', ClassName 'Button'
                    They are each wrapped inside an edit control, strange because the toolbar buttons are not and they render fine.

                    I'm not here much anymore.

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

                      @dan rathbun said:

                      There are two DLLs in the Sketchup folder (msvcp.dll, msvcr.dll).

                      I do not have these. Closest I got is C:\Program Files (x86)\Google\Google SketchUp 7

                      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 said:

                        @dan rathbun said:

                        There are two DLLs in the Sketchup folder (msvcp.dll, msvcr.dll).
                        I do not have these. Closest I got is ...

                        Sorry... typo... the files are:
                        msvcp71.dll
                        msvcr71.dll

                        I'm not here much anymore.

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

                          @thomthom said:

                          And how can I obtain this exact DLL version?

                          There are two DLLs in the Sketchup folder (msvcp71.dll, msvcr71.dll). These should have been copied to the Windows/System32 folder, and registered. If you explore the Windows/System32 folder and click on the Name column, all the "msvc*" DLL files will be listed together. You can hover over them to see their versions (or right click in the column headers, choose "More..." and check "Product Version" if you always want to see version displayed. You may have to have "Remember each folder's view settings" set in Menu: Tools > Folder Options... > View tab > Advanced settings: listbox.)
                          EDIT: corrected filenames in 1st sentence.

                          If anyone is interested, attached find a zip with 3 exported 7.x Sketchup RT_MANIFEST files. (Used MSVS to export them,) and gave them a filename with the SU version, and XML extension so they will be properly lexed in editors. (I suppose you could register .manifest extension to use the XML lexer in your editor's settings.).7.x manifest files (XML)
                          Did you know?? You can modify manifest files, ie, add dependant assemblies; rename them progname.exe.manifest (where progname is the name of the program,) and put them in the same folder as the executable. When the program loads, Windows automatically looks for an external manifest file, and loads it. An external manifest file trumps a program's internal resource manifest, (so make sure it has the same entries as the internal one, ie: export it using a resorce editor such as Visual Studio.)

                          I use an external manifest to force Sketchup to use MS Common Controls ver 6 (aka XP Styled Controls,) instead of those old ugly ver 5 Controls that look like the ones in Windows 3.x !! Vista users might benefit from using Common Controls ver 6.1, but not sure (do not have Vista.)
                          Here's the <dependancy> XML tag to add for ver 6.0 Controls:

                            <dependency>
                          	<dependentAssembly>
                          	  <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity>
                          	</dependentAssembly>
                            </dependency>
                          
                          

                          There is strange effect when MS Common Controls 6 are ON: the images for the 4 buttons on the left of the Sketchup statusbar don't render (at least on XP, but I don't use those buttons anyway, so it's OK with me.)

                          I'm not here much anymore.

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

                            404 - files not found.
                            only files starting with M in my SU folder is:
                            files.png

                            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 said:

                              404 - files not found.

                              Well.. sorry. I suppose I might have copied them in there manually to try and get SU to use those versions. It seems I remember a previous post awhile back about SU using old msvcrt versions.

                              Anyway, the point of the post was where are the DLLs. They are usually put by the application installer into the Windows/System32 folder and registered using regsvr32.exe, but normally the installer is not supposed to overwrite newer versions with older versions. If an application must use and older version, it can keep a local copy in it's program folder and specifically load the local copy. (Which may be how I ended up with copies in the SU folder, I was trying to see SU would use those instead of the ones in my Windows/System32 folder. I have a problem with the MCVCRT and I cannot update several applications, including MS Visual Studio and .NET; something has gotten 'out of whack' on my machine.)

                              I'm not here much anymore.

                              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