• Login
sketchucation logo sketchucation
  • Login
🤑 30% Off | Artisan 2 on sale until April 30th Buy Now

Simple Extension for Mac

Scheduled Pinned Locked Moved Developers' Forum
25 Posts 6 Posters 1.1k 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
    Al Hart
    last edited by 6 Jun 2013, 15:15

    I am referring to the old C++ "Simple Extension" from several years ago.

    But we would rather start the Mac project with the latest and greatest.

    Is there something new, (e.g. new C API) which can be used to integrate C-code with SketchUp Ruby? If so, please point us in the proper direction.

    Thanks,

    Al

    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
    • T Offline
      thomthom
      last edited by 6 Jun 2013, 15:56

      That was for reading and writing SketchUp files. Not to run from within.

      Got a link to this C++ "Simple Extension"?

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

      1 Reply Last reply Reply Quote 0
      • A Offline
        Al Hart
        last edited by 6 Jun 2013, 17:05

        You can download a copy from here:

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

        It has a read me file, and with a little work to get it to work, it actually works.
        (You have to have Ruby installed on you own machine when you compile and link it, for example)

        SketchUp sent it to me about 6 years ago, and although they don't publish or support it, they did give me permission to pass it on to others.

        You might have a lot of fun with it.

        • You can create functions in C++ and call them directly from SketchUp.

        • You can create ruby classes in C++ and access them from SketchUp

        • You can call your own SketchUp functions from C++

        • and you can access the SketchUp ruby classes directly from C++:

        For example, this code, although it is more complex to write in C then in Ruby, gets the value of SketchUp.active_model.rendering_options["ModelTransparency"] directly from the C-code

        	Sketchup = rb.find_class("Sketchup");
        	model = rb.run_func0(Sketchup, "active_model");
        	member = rb_intern("[]");
        	rendering_options = rb.run_func0(model, "rendering_options");
        	options_value = rb_funcall(rendering_options, member,1, 		rb.CString_to_value("ModelTransparency"));
        
        	bir_skp_xray_mode = rb.value_to_bool(options_value);
        

        If you get stuck getting it to work in Windows, I can help. But I could sure use some help from someone who knows more about compiling, etc. on the Mac than I do to get a version running for the Mac

        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
        • T Offline
          thomthom
          last edited by 6 Jun 2013, 18:36

          Right, so it's a Ruby C Extensions written in C++. You might get some hints to building on SU from the simple Hello World Ruby C Extension sample I posted at BitBucket: https://bitbucket.org/thomthom/sketchup-ruby-c-extension

          It got notes on how to compile on Windows and OSX. People would find that while they could compile a Ruby C Extension for plain Ruby - it would crash under OSX unless some specific compiler flags where set.

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

          1 Reply Last reply Reply Quote 0
          • S Offline
            slbaumgartner
            last edited by 6 Jun 2013, 20:00

            @al hart said:

            You can download a copy from here:

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

            It has a read me file, and with a little work to get it to work, it actually works.
            (You have to have Ruby installed on you own machine when you compile and link it, for example)

            SketchUp sent it to me about 6 years ago, and although they don't publish or support it, they did give me permission to pass it on to others.

            If you get stuck getting it to work in Windows, I can help. But I could sure use some help from someone who knows more about compiling, etc. on the Mac than I do to get a version running for the Mac

            This sounded interesting, so I downloaded it and took a quick look. It creates a Windows DLL (dynamic link library). The organization and structure of a DLL are very Windows-specific. Mac also has dynamic shared libraries, but their organization and structure are completely different. It would require a significant rewrite to get this over to the Mac; no doubt feasible, but way out of my depth!

            Steve

            1 Reply Last reply Reply Quote 0
            • A Offline
              Al Hart
              last edited by 6 Jun 2013, 22:12

              @slbaumgartner said:

              It would require a significant rewrite to get this over to the Mac; no doubt feasible, but way out of my depth!

              Steve

              Exactly what I am looking for - a Mac expert, or at least someone who is more familiar with Mac than I, who has done this already for SimpleExtension, or has created a C-code to SketchUp ruby interface which does something similar, or who can easily figure out how to write a Ruby Extension, based on SketchUp's Simple Extension, and could share it with us.

              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
              • D Offline
                driven
                last edited by 7 Jun 2013, 02:56

                @TT

                and all, I finally got around to installing your example, and have a few notes for others...

                === Compile Instructions ===
                
                type/copy-paste or drag and drop items between ][ ][
                
                1. Open a Terminal.app window 
                2. cd into the project folder and enter
                  ] cd  [drag folder into terminal] [ >> return
                3. Execute "ruby extconf.rb"  using full path by dragging
                  ] ruby [drag file into terminal] [ >> return
                4. Execute "make"
                  ] make -f Makefile [ >> return
                5. Move to "User" Plugins  using the proper folder for v2013   
                  ] mv -f SX_HelloWorld.bundle /Users/johns_iMac/Library/Application\ Support/SketchUp\ 2013/SketchUp/Plugins [ >> return 
                6. Open SU
                  ] open /Applications/SketchUp\ 2013/SketchUp.app [ >> return 
                7. Open "Ruby Console" and enter
                  ] require (Sketchup.find_support_file("Plugins/SX_HelloWorld.bundle")).to_s' [ >> return
                8. Test 
                  ] SUExtTest.knock_knock [ >> return
                
                success = Hello SketchUp World! 
                
                NB; in extconf.rb match your environment [ $CFLAGS = '-arch x86_64 -arch i386 -O3 -pipe'] works for me
                

                @Al
                I'll have a look at yours and see if I can make any sense of it... no promises,

                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
                • T Offline
                  thomthom
                  last edited by 7 Jun 2013, 08:01

                  Had a look at it myself. Looks like a Ruby C Extension wrapped in C++ with extra stuff I expect if for the exporter.

                  Al: The Ruby C Extension sample I linked to is a bare bone example of connecting Ruby and C. Now, it is possible to write these extensions in C++, I've seen examples - they had to extern the C++ functions as C type functions.

                  That SimpleExtension sample didn't seem that simple to me, certainly more than the minimum of what is needed. Look at how people in the Ruby community is developing Ruby C Extensions with C++ and you will find simpler examples.

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

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 7 Jun 2013, 08:06

                    StackOverflow got several threads on it:
                    http://stackoverflow.com/questions/10167149/compiling-ruby-c-extension
                    http://stackoverflow.com/a/2060716/486990

                    Noel Warren have used Rice:
                    http://rice.rubyforge.org/

                    And just found this which was interesting in regard to raising exceptions:
                    http://old.thoughtsincomputation.com/posts/ruby-c-extensions-c-and-weird-crashing-on-rb_raise

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

                    1 Reply Last reply Reply Quote 0
                    • O Offline
                      olilej
                      last edited by 14 Jul 2013, 01:41

                      I looked over that SimpleExtension example, it seems very promising.

                      By the way, what exactly are the real benefit of using Ruby C Extension ? Does this have to do with performance ? As in SketchUp 2013, C++ SDK doesn't allow model interaction, it would be very interesting if we could improve the plugins efficiency with that possibility.

                      Olivier

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        thomthom
                        last edited by 14 Jul 2013, 10:10

                        I use C Extensions when I need to do many calculations. Vertex Tools became 200+ times faster in calculating the soft selection when I ported the code to C Extension.

                        Just calling Ruby functions won't be faster. You'd have to be doing calculations and other processing for it to be faster.

                        It's not just performance though, you might want to spawn off other processes. Use C libraries.

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

                        1 Reply Last reply Reply Quote 0
                        • A Offline
                          Al Hart
                          last edited by 14 Jul 2013, 12:21

                          We had about the same experience as ThomThom.

                          Calling ruby functions from C-code was slower than calling them from ruby directly in SketchUp.

                          e.g. The C-code replacement for:

                          value = model.get_attribute “dictionaryname”, key, defaultvalue)
                          

                          can be done directly, (actually rather indirectly), from C-code, but the execution time is slower than in SketchUp ruby.

                          But other things, such as maintaining a table for vertices, and then doing special processing for vertices was faster.

                          Also, we were able to use Windows dialogs, functions in other Windows DLLS, etc. and attach them to SketchUp.

                          Also, we were able to use all the Ruby stuff from C++ because ruby\1.8\i386-mswin32\ruby.h, (part of the ruby code), includes

                          #if defined(__cplusplus)
                          extern "C" {
                          #endif
                          

                          Back to the original question.

                          Has anyone interfaced to C routines from the Mac, and if so could you share a sample of some sort to get us started...

                          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
                          • T Offline
                            thomthom
                            last edited by 14 Jul 2013, 13:06

                            @al hart said:

                            Has anyone interfaced to C routines from the Mac, and if so could you share a sample of some sort to get us started...

                            404 — Bitbucket

                            favicon

                            (bitbucket.org)

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

                            1 Reply Last reply Reply Quote 0
                            • A Offline
                              Al Hart
                              last edited by 14 Jul 2013, 13:56

                              @thomthom said:

                              404 — Bitbucket

                              favicon

                              (bitbucket.org)

                              Thanks, ThomThom, that looks like what I am looking for.

                              I see you had posted it before, but I didn't know what it was at the time.

                              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
                              • T Offline
                                thomthom
                                last edited by 14 Jul 2013, 14:20

                                Mind you, I recently found http://rubyinstaller.org/downloads/ which I think is a better choice for Windows than the Visual Studio solution I'd used.

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

                                1 Reply Last reply Reply Quote 0
                                • O Offline
                                  olilej
                                  last edited by 26 Nov 2013, 11:42

                                  I've been playing around with C Extension recently and I would like to know how if there is an equivalent of is_a? ruby function in C level.

                                  I found rb_obj_is_instance_of but it seems to be only meant for native ruby types.

                                  1 Reply Last reply Reply Quote 0
                                  • A Offline
                                    Al Hart
                                    last edited by 26 Nov 2013, 13:51

                                    [Ignore this for a minute - I need to add a second parameter for what the value to pass to is_a?]

                                    You can execute the equivalent of any ruby function using rb_intern() and rb_funcall()

                                    Try this:

                                    
                                    VALUE fid = rb_intern("is_a?");
                                    VALUE vret = rb_funcall(klass, fid, 0);
                                    
                                    

                                    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
                                      Al Hart
                                      last edited by 26 Nov 2013, 14:21

                                      Here is a better example, equivalent to

                                      Sketchup.is_a?(Module)

                                      
                                      
                                      VALUE Sketchup = rb_path2class("Sketchup");
                                      VALUE Module= rb_intern("Module");
                                      VALUE is_a = rb_intern("is_a?");
                                      VALUE result = rb_funcall(Sketchup, is_a, Module, 0);
                                      
                                      
                                      

                                      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 26 Nov 2013, 15:03

                                        @olilej said:

                                        I've been playing around with C Extension recently and I would like to know how if there is an equivalent of is_a? ruby function in C level.

                                        If you have the CHM... you can click on the method description, and the C source will popup:
                                        (Also works for online version, but the source link must be clicked directly, and is only visible when the mouse is hovering over the method description.)

                                        Object_kind_of.png

                                        💭

                                        I'm not here much anymore.

                                        1 Reply Last reply Reply Quote 0
                                        • Dan RathbunD Offline
                                          Dan Rathbun
                                          last edited by 26 Nov 2013, 15:05

                                          So it looks like there are some macros defined in C, to make life easier ... CLASS_OF(), RCLASS_SUPER(), etc.

                                          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