sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Update | Sketchucation Tools 5.0.8 released with licensing improvements and bugfixes Download

    Simple Extension for Mac

    Scheduled Pinned Locked Moved Developers' Forum
    25 Posts 6 Posters 2.7k Views 6 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.
    • Al HartA
      Al Hart
      last edited by

      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).PNG
      IRender nXt from Render Plus

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

        @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
        • Al HartA
          Al Hart
          last edited by

          @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).PNG
          IRender nXt from Render Plus

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

            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
              olilej
              last edited by

              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
              • Al HartA
                Al Hart
                last edited by

                [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).PNG
                IRender nXt from Render Plus

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

                  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).PNG
                  IRender nXt from Render Plus

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

                    @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
                      Dan Rathbun
                      last edited by

                      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
                      • Dan RathbunD
                        Dan Rathbun
                        last edited by

                        • Pragmatic Programmer: Extending Ruby 1.9

                        I'm not here much anymore.

                        1 Reply Last reply
                        Reply Quote 0
                        • O
                          olilej
                          last edited by

                          Great, my goal is to make sure I'm dealing with a Entity in order to access its attributes.

                          Here is the code I've come up with.

                          VALUE result = rb_obj_is_kind_of(obj, rb_path2class("Sketchup;;Entity"));
                          if (Qtrue == result){
                          	VALUE rval = rb_funcall(obj, rb_intern("get_attribute"), 2, rb_str_new2("dynamic_attributes"), rb_str_new2("..."));
                          	...
                          }
                          
                          1 Reply Last reply
                          Reply Quote 0
                          • Dan RathbunD
                            Dan Rathbun
                            last edited by

                            Only Sketchup::ComponentDefinition and Sketchup::ComponentInstance will have dictionaries with that special name.

                            I'm not here much anymore.

                            1 Reply Last reply
                            Reply Quote 0

                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                            With your input, this post could be even better 💗

                            Register Login
                            • 1
                            • 2
                            • 2 / 2
                            • First post
                              Last post
                            Buy SketchPlus
                            Buy SUbD
                            Buy WrapR
                            Buy eBook
                            Buy Modelur
                            Buy Vertex Tools
                            Buy SketchCuisine
                            Buy FormFonts

                            Advertisement