• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Extension using c#

Scheduled Pinned Locked Moved Developers' Forum
10 Posts 7 Posters 5.2k 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.
  • I Offline
    icehuli
    last edited by 31 Dec 2013, 15:45

    Someone might be interested in using c# and .net stuff.
    I created a very simple example to write a ruby extension in c#.
    https://bitbucket.org/icehuli/sucsexttutorial

    1 Reply Last reply Reply Quote 0
    • T Offline
      tt_su
      last edited by 6 Jan 2014, 14:37

      Cool! That's very interesting.

      Last week I was working on a Ruby C Extension in C++ and I started to write a thin wrapper over the Ruby C code so that I could manipulate them as C++ objects. It'd be nice with a set of wrappers like that the various languages.

      1 Reply Last reply Reply Quote 0
      • I Offline
        icehuli
        last edited by 14 Mar 2014, 03:03

        The C# stuff works on SketchUp 2014 with Ruby 2.0.0

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 14 Mar 2014, 04:19

          @icehuli said:

          The C# stuff works on SketchUp 2014 with Ruby 2.0.0

          ALL tutorials should show ALL objects being created INSIDE an Author's toplevel module.

          We usually use the module name Author or AuthorNamespace or CompanyNamespace, etc., do denote that the end user should replace that name with their own toplevel module name.

          Only Ruby and the API (in rare cases,) should ever create classes at the toplevel (aka TOPLEVEL_BINDING.)

          💭

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • I Offline
            icehuli
            last edited by 14 Mar 2014, 20:24

            @dan rathbun said:

            @icehuli said:

            The C# stuff works on SketchUp 2014 with Ruby 2.0.0

            ALL tutorials should show ALL objects being created INSIDE an Author's toplevel module.

            We usually use the module name Author or AuthorNamespace or CompanyNamespace, etc., do denote that the end user should replace that name with their own toplevel module name.

            Only Ruby and the API (in rare cases,) should ever create classes at the toplevel (aka TOPLEVEL_BINDING.)

            💭

            Thanks for the reminding.

            1 Reply Last reply Reply Quote 0
            • I Offline
              icehuli
              last edited by 13 May 2018, 23:12

              in case somebody using it, added a new project "IHL_CsR22ExtApp0" for Sketchup 2018/2017 x64 with ruby 22

              1 Reply Last reply Reply Quote 0
              • J Offline
                jolran
                last edited by 12 Jun 2018, 08:45

                Interesting stuff indeed, and nice job Icehuli!

                It looks like you are wrapping a lot of Ruby-communication-code into C#.
                Does it work well ? How is the performance ?
                Ive read the UnmanagedExports-package puts a bit of overhead.
                Was rather old info, I'll be intreseted to know if it has been improved.

                I'm working on a similar project with a WPF application.
                In my project I use a different pattern in using a C++/Cli "Bridge-layer" with a C++/cli ref-class that subclass the WPF app. Then I can use that class to communicate with C++ as normal through exporting the required functions.
                This means off course writing the bussiness-layer and Ruby-Communication layer in C++,
                and (for the most part) only using C# for the front-end.

                I had some problems running the application if I did not put the assembly in the same folder as Sketchup.exe. I don't want to hijack your post but it would be interesting to hear if you have any experience with this.

                The solution I found is to handle the event when the Appdomain cant locate an assembly.
                AppDomain ResolveEventHandler
                This SO-topic has some code: https://stackoverflow.com/questions/1373100/how-to-add-folder-to-assembly-search-path-at-runtime-in-net (msarahan C++/Cli version a bit further down).
                This requires a longliving Application though.

                I could also possibly explicitly load the assembly, and then use reflection to create an instance. But it becomes quite complicated when I want to use a C++/Cli ref class as subclass.

                I wonder what the policy is regarding putting dll's in the Sketchup folder ?

                1 Reply Last reply Reply Quote 0
                • S Offline
                  Shubham777 Newcomers
                  last edited by 26 Sept 2023, 12:10

                  @icehuli said:

                  in case somebody using it, added a new project "IHL_CsR22ExtApp0" for Sketchup 2018/2017 x64 with ruby 22

                  Interesting and nice job Icehuli!

                  I currently working on your C# project "IHL_CsExt0" .After successfully build your code I connected this with SketchUp 2023 but I got exception at following function :

                  public static void rb_define_module_function(VALUE module, string name, CallbackArg2 func)
                          {
                              MethodDelegates.Add(func);//keep a reference to "func" to prevent it being garbage collected
                              rb_define_module_function(module, name, func, 2); 
                          }
                  

                  exception occurs ::
                  1.Exception thrown at 0x00007FF99A750EB6 (x64-msvcrt-ruby270.dll) in SketchUp.exe: 0xC0000005: Access violation reading location 0x000000006F21B998.
                  2.System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
                  3.kernelbase.pdp Not Loaded

                  Currently using ::
                  SketchUp 2023 with "x64-msvcrt-ruby270.dll" in visual studio 2019.
                  framework=.net 4.5 also add post build event to copy "IHL_CsExt0.so" file (SketchUp)Plugin folder

                  Can you please help me out for this issue. Thank you In Advance!

                  1 Reply Last reply Reply Quote 0
                  • gullfoG Offline
                    gullfo
                    last edited by 26 Sept 2023, 13:05

                    may be the recursion?
                    rb_define_module_function(module, name, func, 2)

                    @shubham777 said:

                    public static void rb_define_module_function(VALUE module, string name, CallbackArg2 func)
                    >         {
                    >             MethodDelegates.Add(func);//keep a reference to "func" to prevent it being garbage collected
                    >             rb_define_module_function(module, name, func, 2); 
                    >         }
                    

                    exception occurs ::
                    1.Exception thrown at 0x00007FF99A750EB6 (x64-msvcrt-ruby270.dll) in SketchUp.exe: 0xC0000005: Access violation reading location 0x000000006F21B998.

                    Glenn

                    http://www.runnel.com

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      Mahadev Newcomers
                      last edited by 20 Dec 2023, 13:54

                      @icehuli said:

                      Someone might be interested in using c# and .net stuff.
                      I created a very simple example to write a ruby extension in c#.
                      https://bitbucket.org/icehuli/sucsexttutorial

                      can you guide me to run the sample code

                      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