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

    SDK, optimization, and cross platform support

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 1.1k Views 4 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.
    • W Offline
      Whaat
      last edited by

      I am getting very interested in using the SketchUp SDK for the purpose of increasing the performance of my Ruby scripts. Problem is, I have very poor understanding of how the process of creating DLLs and interfacing them with Ruby code works.

      I am not expecting a detailed description of how to get this to work but maybe someone could help point me in the right direction (online resources?) or at least answer some of these basic questions that I have:

      1. Is the SketchUp SDK incorpated from Ruby by creating DLLs and then calling them with the WIN32API? Is there another way? What is the equivalent method on Mac?
      2. How do you create a DLL or Mac equivalent? Is it simply a compiled CPP file that contains a class and associated methods? Or is it more complex? Where can I find some good reference material on creating DLLs that applies to Mac and PC?
      3. I don't have Visual C++. Do I need it for this sort of thing or is there another (free?) way?
      4. Is it relatively straightforward to function parameters back and forth between Ruby and the DLL? For example, I might want to send some SketchUp entities to a DLL (using Ruby) and then have the DLL do some heavy processing and then get the results back into Ruby. What is the process for this?

      Thanks in advance!

      SketchUp Plugins for Professionals

      1 Reply Last reply Reply Quote 0
      • tbdT Offline
        tbd
        last edited by

        @whaat said:

        I have very poor understanding of how the process of creating DLLs and interfacing them with Ruby code works.

        Sketchup SDK is a completely different thing from shared objects (.so) from Ruby.

        also "Both the SkpReader and SkpWriter APIs were written prior to SketchUp's acquisition by Google. Neither API is under active development" (from here)

        @whaat said:

        1. Is the SketchUp SDK incorpated from Ruby by creating DLLs and then calling them with the WIN32API? Is there another way? What is the equivalent method on Mac?

        let's forget about Sketchup SDK and talk about .so

        they are dynamic loaded library (.dll on win, .dylib on mac) that allows creating ruby objects in a different language. they will be seen in Ruby world as normal classes, methods, ... and there is no need of a Win32API or anything else. just pure ruby stuff - require and Class.new

        @whaat said:

        1. How do you create a DLL or Mac equivalent? Is it simply a compiled CPP file that contains a class and associated methods? Or is it more complex? Where can I find some good reference material on creating DLLs that applies to Mac and PC?

        see http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html

        the idea is that you have a ruby 'config' file that will create a makefile that will create the dynamic library. it is easy and powerful (and "fun" to debug inside Sketchup)

        it should work on both Mac/Pc with some tweaking of the makefile

        @whaat said:

        1. I don't have Visual C++. Do I need it for this sort of thing or is there another (free?) way?

        you can use gcc on Mac (comes with OS pre installed) and on PC you can use PellesC - this is what I use for Podium

        @whaat said:

        1. Is it relatively straightforward to function parameters back and forth between Ruby and the DLL? For example, I might want to send some SketchUp entities to a DLL (using Ruby) and then have the DLL do some heavy processing and then get the results back into Ruby. What is the process for this?

        you define a Ruby class in C world that does all the work and send back the results in whatever Ruby object you want (array, string, ...)

        some things to remember:

        • it is single task - if it takes a lot of time, SU UI will be blocked and white.
        • don't mix native threads with Ruby threads
        • watch out for function calls level - recursion will quickly end with a 'stack level too deep' error
        • language functions can be destroyed by ruby garbage collection and end in no-man land and crash everything
        • debug extensions out of Sketchup first, in normal Ruby - easier and faster to debug
        • you will spend more time debugging than coding πŸ˜‰

        SketchUp Ruby Consultant | Podium 1.x developer
        http://plugins.ro

        1 Reply Last reply Reply Quote 0
        • W Offline
          Whaat
          last edited by

          Thanks so much TBD for your help! Much appreciated!

          @unknownuser said:

          let's forget about Sketchup SDK and talk about .so

          OK, but I will need the functions in the SDK to do the processing. I need access to SketchUp entity information using C++. (eg. methods to determine the vertices of a given face) So I need the SDK, right? These are methods that I need a performance increse on.
          Any advice on using the SDK?

          @unknownuser said:

          • you will spend more time debugging than coding πŸ˜‰

          Yes I fear this, especially as someone with so little experience in these matters. 😞

          SketchUp Plugins for Professionals

          1 Reply Last reply Reply Quote 0
          • tbdT Offline
            tbd
            last edited by

            @whaat said:

            I need access to SketchUp entity information using C++. (eg. methods to determine the vertices of a given face) So I need the SDK, right?

            yes. for that you will need Visual C++ (you can use other compilers but making it compilable is a big task and tiresome)

            you can use skpreader to read the info and send it to your application. there is an example in the SDK that converts a skp to xml so you can use that for start.

            also there is a undocumented bridge between SDK world and Ruby - see this

            SketchUp Ruby Consultant | Podium 1.x developer
            http://plugins.ro

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

              @unknownuser said:

              see http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html

              This link was quite useful in understanding your SUExt sample.
              Got any link to further reading as to how you deal with other data types passes? How do you make a method that takes an array as argument (or hash) iterates it and return a new one?

              Is it possible to handle SU defined classes?

              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:

                How do you make a method that takes an array as argument (or hash) iterates it and return a new one?

                http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html
                Examples (in C,) dealing with arrays are given (although somewhat simple.)

                I'm not here much anymore.

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

                  cheers!

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

                  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