Access SketchUp SDK from C#/ .net project

Not sure how you expect to call it, but you can load a dll file with something similar to:

require 'fiddle'
kernel32 = Fiddle.dlopen 'kernel32'
load_library = Fiddle::Function.new(
  kernel32['LoadLibraryW'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT,
)
if load_library.call(dll_path.encode('utf-16le')).zero?
  abort "Failed to load file from #{dll_path}"
end

No idea how to do it on macOS…

The LoadError message, "cannot load file -- ./SketchUpPlugin.dll" indicates you are relying upon what the current working directory is. Ie, the global require method must either be a full absolute pathname to the file, OR a good relative pathname from one of the paths in the global $LOAD_PATH array.
SketchUp will automatically push the paths to valid “Plugins” directories into the global $LOAD_PATH array.

So, … within your "Bim.rb" file, you should be calling require sketchup_plugin_dll, where sketchup_plugin_dll is either the full absolute path to the DLL file, or a relative path from SketchUp’s "Plugins" directory.

Since, ALL extensions must be within their OWN subdirectory, you can prefix the path with your extension’s subfoldername. So let us pretend that your extension’s subfolder name is: "mahadev_bimmatch"

To use a relative path string, you would then load your DLL via a call like:

require "mahadev_bimmatch/SketchUpPlugin.dll"

In this case the require method will use all the paths in the $LOAD_PATH array to find an existing file to load. If it finds a match, it will load it.

To use an absolute path, you can use some of Ruby’s core methods from the File class.
If the DLL file is in the same directory as the Ruby file that is making the call to load it, then do:

require File.join( __dir__, 'SketchUpPlugin.dll' )

… OR to use String interpolation …

require "#{__dir__}/SketchUpPlugin.dll"

See method documentation for:

Thanks for the feedback

Hi @MSP_Greg & @DanRathbun ,

I hope you are doing great.

Thanks for your great knowledge transfer.

i tried but still issue is coming, Kindly guide me.

Would be more appreciated,

image

Hi Guys,

My intension is create custom plugin inside sketchup using c#.

i got he sample solution and compiled , then got the dll.

But dont how to load use the dll inside sketchup.

I have used .rb file for loading .dll but throwing error while opening sketchup

Kindly guide me on how to create custom plugin in sketchup using c#

Hi @DanRathbun ,

I hope you are doing great

I have seen the comments , it was more useful to me

And i have complied and got the .dll file.

But unfortunately i dont know, how load that .dll into SketchUp. Getting issue.

Kindly guide me on that. Advance thanks for your support

Well, the DLL file should not be in the “Plugins” folder.
All extension files except the extension registrar rb script, need to be in an extension subfolder.

See:

Also, all your extensions must operate within a unique top level Ruby namepsace module.
Each one of your extensions should be separated from one another, in its own submodule, sinde your namespace module.


Without seeing the code for the Enty point of the DLL we cannot see why it is not loading.
The Ruby entry point must be the same string and case as the DLL filename, prefixed with Init_, ie:

void Init_SketchUpPlugin {
  // Do plugin setup code ...
}

If your DLL file was named "mahadev_bimmatch.dll", then the entry point function must be named:

void Init_mahadev_bimmatch {
  // Do plugin setup code ...
}

Something like

// mahadev_bimmatch.cs compile to mahadev_bimmatch.dll

//
// ... C# code ...
//

extern "C" {

    static VALUE meth_some_command() {
        // Do C code here or call C#, etc., ...
    }

    static VALUE setup_plugin() {

        // Create a reference to Ruby top level Namespace module:
        VALUE mNamespace = rb_define_module("Mahadev");

        // Create a reference to Ruby extension submodule:
        VALUE mBimMatch  = rb_define_module_under(mNamespace, "BimMatch");

        // Define a Ruby module method named "some_command":
        rb_define_singleton_method(mBimMatch, "some_command", meth_some_command, 0);

        //
        // Define other Ruby methods or classes beneath mBimMatch here ...
        //
    }

    // Define the Ruby entry point function:
    void Init_mahadev_bimmatch {
        setup_plugin();
    }

}