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

    DLL callback to ruby

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

      Dan, one last question, can the dll be compiled in 64bit or does it have to be 32bit like SK?

      Does the handle return by rb_define_module('Sketchup') correspond to the ISkpApplication interface?

      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:

        Dan, one last question, can the dll be compiled in 64bit or does it have to be 32bit like SK?

        I would say 32bit, because the Ruby that Sketchup loads is also 32bit. There is a 64bit Ruby edition, but it may be in the 1.9.x branch, which Sketchup cannot load even 1.9.x 32bit.

        @alienizer said:

        Does the handle return by rb_define_module('Sketchup') correspond to the ISkpApplication interface?

        I would say "not exactly". There may be some C++ methods from that interface, that are "Ruby wrapped" into the Sketchup module, as well as others from different C++ objects.

        Getting a handle on the application object (and from there it's window object, and then it's UI element objects, and so on...) are methods that the current Ruby Sketchup module lacks. You'll have to use a C++ call, as shown in the SDK examples to get the app handle.

        I'm not here much anymore.

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

          Thank Dan. So far, everything works great, I even got this to work...

          modUI = rb_define_module('UI');
          menu = rb_funcall(modUI, rb_intern('menu'), 0, nil);

          but I'm stuck on this one...

          rb_funcall(menu, rb_intern('add_item'), 1, rb_str_new2('File/Testing'));

          It tells me "tried to create Proc object without a block"

          Where do you learn all this? I can't find any docs on rb_intern or what to pass to it. I only guess!

          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

            The API add_item method takes 2 args, a String and a Block, ... not 1 arg.

            I'm not here much anymore.

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

              @dan rathbun said:

              The API add_item method takes 2 args, a String and a Block, ... not 1 arg.

              Indeed! I figured it out, and the rb_intern('menu') takes one, a str of the submenu name, like "Plugins" right?

              When I do rb_intern('add_submenu') with 1 arg of str "Testing", it adds only "T" to the Pluigns menu, the first letter only!?

              If I don't use rb_str_new2 SK crash, Am I doing it right?

              For the Block, do I have to use rb_something to pass the Block, or just the reference pointer?

              Sorry to be a pain in the......

              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:

                I can't find any docs on rb_intern or what to pass to it.

                At the bottom of the "Extending Ruby" chapter, of the "Pick-Axe" book:
                @unknownuser said:

                *ID rb_intern(char name")

                Returns an ID for a given name. If the name does not exist, a symbol table entry will be created for it.

                I just pasted an example that used the rb_intern to create an ID... not sure if it's really needed. You can try just passing a normal string, as the method name argument.
                (Using rb_intern on the C-side, is the same as using a Symbol on the Ruby side, thus:
                :test_item or "test_item".intern or "test_item".to_sym

                What are the arguments, for ruby C-side functions, generally?

                The list at the bottom of the "Extending Ruby" chapter, is not complete, AND that edition was written for Ruby circa 1.6.x (so it's out of date.)

                For a definitive list, refer to to the function prototypes, in the Ruby C source folder:
                %(#000000)[**.../include/ruby-*<version>*/ruby/ruby.h**]
                .. so if your using Ruby ver 1.8.6, the path would be:
                %(#000000)[**.../include/ruby-1.8.6/ruby/ruby.h**]

                ADD: .. and other header files as well.

                I'm not here much anymore.

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

                  Yea, you need to use rb_str_new2 to convert the Cstring to a Ruby String.

                  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
                    • A Offline
                      Alienizer
                      last edited by

                      Dan, what is the Block expected in rb_funcall(menu, rb_intern('add_submenu')...

                      I keep getting the error "tried to create Proc object without a block" if I use 1 arg.

                      If I use 2 arg, I get "wrong number of arguments (2 for 1)" but even you said it needs 2!? Confusing πŸ˜•

                      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:

                        For the Block, do I have to use rb_something to pass the Block, or just the reference pointer?

                        Not sure... the proc and block functions are listed in intern.h

                        Depends on if the block / proc will be defined at runtime on the Ruby side, or before hand in your C code.

                        This generated doxygen website is old (v 1.8.4) but you may find it easier to find things:
                        http://www.ruby-doc.org/doxygen/current/globals.html#index_r

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

                            @alienizer said:

                            Thanks Dan

                            no problemo ...

                            Also, if you have the Ruby Reference CHM, when you wish to see the C-side source for a method, you can click within the method's definition area, and a source box will unfold.

                            I'm not here much anymore.

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

                              Sweet! But only ruby18-core.chm works out of the 3! Or is it me?

                              I just posted http://forums.sketchucation.com/viewtopic.php?f=180&t=39119 another challange for you πŸ˜’ 😳

                              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:

                                Sweet! But only ruby18-core.chm works out of the 3! Or is it me?

                                ruby18.chm is a wrapper that loads both of the other two, as expandable nodes in the tree control.
                                CHM files use a MSIE stub named hh.exe
                                They a compiled HTML Help Markup files.
                                You can get the HTML Help Workshop app on MS Download.

                                I'm not here much anymore.

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

                                  Yes indeed, I didn't know the other 2 were loaded into the one. That's a nice ref book! Thanks Dan.

                                  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:

                                    Yes indeed, I didn't know the other 2 were loaded into the one. That's a nice ref book! Thanks Dan.

                                    Well it's supplied with the mingGW compiled Windows Ruby one-click install packages. So I'm not responsible.

                                    Check your Private Messages

                                    I'm not here much anymore.

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

                                      @dan rathbun said:

                                      Well it's supplied with the mingGW compiled Windows Ruby one-click install packages. So I'm not responsible.

                                      I know, but I should have figured it out myself 😐

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

                                      1 Reply Last reply Reply Quote 0
                                      • D Offline
                                        driven
                                        last edited by

                                        why would you use

                                        Sketchup.send_action(JcB::My_Ext.initalise)

                                        when

                                        JcB::My_Ext.initalise

                                        works for a loaded file?

                                        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
                                        • M Offline
                                          Marthmatica
                                          last edited by

                                          looks like you solved the problem.

                                          If I want to call an rb function, from a loaded rb in SU, you could just send this function from a dll:

                                          Sketchup.send_action my_rb_function_def_name_in_an_rb_loaded_file (no string wrap), as you can other SU commands

                                          which rb SU command, and its function call string is just a string in a class property or in some dll function, thus called in either direction, from dll, or to dll.

                                          Its a little clunky I notice, a bit unreliable after the stack is toasted a little.

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

                                            Because I didn't know. Thanks, that'll be better. Any other tips for reliably sending strings and data from DLL's easily?

                                            Is there anyway to extend UI webdialog to contain activex controls? I have not tried it yet, I suppose it is doable. The dilemma is sending external commands to SU, in my case, and that work around is running script functions that have to be loaded, for now.

                                            Also, if you know the browser engine for the UI webdialog, can it be set to a specific browser in SU?

                                            @unknownuser said:

                                            WebDialog.newSketchUp 6.0+

                                            The new method is used to create a new webdialog.

                                            Note that the browser which is embedded inside the dialog depends on the user's OS. On Mac, Safari is embedded, while on the PC whatever version of Internet Explorer is installed will be embedded.

                                            I don't have explorer, thank God, but some engine is being used in SU, just wondering where that may be set.

                                            Just trying to make some easy connectible user dialogs, and experimenting for fun. May be I'll find a hole or two as well, an accidental "in", that's always nice.

                                            Was also wonderign why "creatObject" from the Sketchup encapsulated object model is impossible, I assume, maybe it is not programmed to be accessible. But the exe. exposes the object model, but not many useful methods, eyt I can instantiate the SU object in ActiveX anyways, but I'll keep chipping away the stone. There is more than one hole, and they'll emerge up in time, but I only have a million years here.

                                            Thanks

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

                                            Advertisement