• Login
sketchucation logo sketchucation
  • Login
πŸ”Œ Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

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 1 Aug 2011, 05:11

    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
    • D Offline
      Dan Rathbun
      last edited by 1 Aug 2011, 17:10

      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 1 Aug 2011, 18:13

        @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
        • D Offline
          Dan Rathbun
          last edited by 1 Aug 2011, 18:13

          @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
          • D Offline
            Dan Rathbun
            last edited by 1 Aug 2011, 18:17

            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 1 Aug 2011, 18:58

              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 1 Aug 2011, 19:41

                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
                • D Offline
                  Dan Rathbun
                  last edited by 1 Aug 2011, 20:01

                  @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 1 Aug 2011, 22:20

                    Thanks Dan

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

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      Dan Rathbun
                      last edited by 1 Aug 2011, 23:08

                      @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 2 Aug 2011, 00:54

                        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
                        • D Offline
                          Dan Rathbun
                          last edited by 2 Aug 2011, 01:06

                          @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 2 Aug 2011, 01:15

                            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
                            • D Offline
                              Dan Rathbun
                              last edited by 2 Aug 2011, 01:20

                              @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 2 Aug 2011, 01:23

                                @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 26 Feb 2016, 16:49

                                  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 27 Feb 2016, 01:05

                                    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 27 Feb 2016, 01:15

                                      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
                                      • M Offline
                                        Marthmatica
                                        last edited by 27 Feb 2016, 01:58

                                        @driven said:

                                        why would you use

                                        Sketchup.send_action(JcB::My_Ext.initalise)

                                        when

                                        JcB::My_Ext.initalise

                                        works for a loaded file?

                                        john

                                        Oh yeah. Forgot. The reason I was doing this, is to send the send_action "string" (or whatever it really is), from a DLL. And it works sometimes, soemtimes not, and so I was trying to get it to be reliable.

                                        I don't know how to construct a "this.that" thing from a DLL, if that is required to run a ruby command. I just needed to keep the string as simple as possible. Still experimenting. I just need to call SU commands, from outside of SU data forms, even if initiated in SU, as that is all I can do at present. The reason is as usual, the data aids a real IDE may provide, versus naked scripts having to read text and Excel sheets as the "middleman". Just tryign to minimize the back and forth kind of supposed solutions I Frankenstein together.

                                        I really don't know why SU doesn't just expose the whole OM for use by other IDEs. May be it does, but the stupid gene has yet to be naturally selected with myself, and so stupid is what stupid does, take a million years to find a four line solution that works. But, I got a million years, so, might as well do something "extraciricular" while I am here.

                                        1 Reply Last reply Reply Quote 0
                                        • M Offline
                                          Marthmatica
                                          last edited by 27 Feb 2016, 02:32

                                          Answering my own post. eval("str") makes this 100% reliable, THAT was my problem. I'll be learning for a while. I'll see if it works on whole chunks of ruby code sends from the DLL.

                                          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