# How to add C++ plugins to SketchUp editor

**URL:** <https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679>\
**Category:** SketchUp SDK\
**Created:** [April 15, 2016, 2:11pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679 "2016-04-15T14:11:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![arularasu](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@arularasu](https://forums.sketchup.com/u/arularasu)\
**Post date:** [April 15, 2016, 2:11pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/1 "2016-04-15T14:11:28Z")

</div>

I am basically new to sketchup…  
Can someone provide me the guidelines to follow for adding a c++ plugin to sketchup  
for example xmltoskp c++ project generates a dll file.  
how should i add that dll to sketchup for exporting

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [April 15, 2016, 4:47pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/2 "2016-04-15T16:47:59Z")

</div>

On OS X you have to place the bundle file under the same plugins directory where you place the ruby extensions, (or not recommended, in the plugins folder in the .app)

On Win you have to place it under a folder called exporters, example: C:\Program Files\SketchUp\Exporters

I forwarded this internally to improve the docs.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 15, 2016, 7:54pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/3 "2016-04-15T19:54:29Z")

</div>

> [@arularasu](#):
>
> for example xmltoskp c++ project generates a dll file.how should i add that dll to sketchup for exporting

That is not an exporter. It creates an SKP file. And (_I think_) it is _really_ meant to be used by another application (that uses XML files,) to export a SKP file. The external application would use the Windows API `LoadLibrary()` function to load the DLL.

But… can it be used as an importer if dropped into the “Importers” folder ?

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [April 15, 2016, 8:11pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/4 "2016-04-15T20:11:19Z")

</div>

> [@DanRathbun](#):
>
> But… can it be used as an importer if dropped into the “Importers” folder ?

on a mac it runs as an importer from the user plugins folder, if you load it each session from a rbz inside you extension folder…

i.e. you have it built and added it in a renamed zip folder…

your extension calls the loader and the loader is simply…

```ruby
Sketchup.install_from_archive(File.join(File.dirname( __FILE__ ), "xml.rbz")) if Sketchup.is_pro?

```

on load SU unzips the rbz and overwrites any pre-existing same named binary file…

it appears in the File menu, or any you dictate…

I did for both import and export examples when I built them…

john

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 15, 2016, 9:28pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/5 "2016-04-15T21:28:12Z")

</div>

OK thanks for the clarification, John.

---

<div class="post-metadata">

**Author:** ![thomthom](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/thomthom/32/12606_2.png) [@thomthom](https://forums.sketchup.com/u/thomthom)\
**Post date:** [April 16, 2016, 12:13pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/6 "2016-04-16T12:13:06Z")

</div>

> [@john\_drivenupthewall](#):
>
> on load SU unzips the rbz and overwrites any pre-existing same named binary file…

RBZ for C API examples? I’m confused…

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [April 16, 2016, 1:51pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/7 "2016-04-16T13:51:14Z")

</div>

> [@thomthom](#):
>
> I’m confused…

to clarify further…

When I built the two examples, I did not want them in the App Contents path…

I could not get SU to load them from my plugins sub-folder using `Sketchup::require`, `load`, `require` or `require_relative` …

but `Sketchup.install_from_archive` **did** load and add the menu items for both if they are contained inside xml.rbz, inside my plugins sub-folder…

I just checked now, and they **do** load and run directly from the User/\*\*/Plugins, so there is no need to load them each time, as I was doing…

I’ll add an `unless File.exist?` check to stop that…

john

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 16, 2016, 4:14pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/8 "2016-04-16T16:14:18Z")

</div>

> [@john\_drivenupthewall](#):
>
> When I built the two examples, …

What did they become ? **`so`** or **`bundle`** files ? Ruby’s **`Kernel.require`** is supposed to be able to load them.

> **Re:** [Module: Kernel (Ruby 2.0.0)](http://ruby-doc.org/core-2.0.0/Kernel.html#method-i-require)
> 
> If the filename has the extension “ **`.rb`** ”, it is loaded as a source file; if the extension is “ **`.so`** ”, “ **`.o`** ”, or “ **`.dll`** ”, or the default shared library extension on the current platform, Ruby loads the shared library as a Ruby extension.
> 
> Otherwise, Ruby tries adding “ **`.rb`** ”, “ **`.so`** ”, and so on to the name until found.

So you’ll note there are two search loops. I usually like to specify the file extension for compiled libraries when I load them with **`require()`**, just to make sure of what I’m trying to load. Someone could create a “ **`.rb`** ” file of the same name and it’ll get loaded first. If I don’t know about it, things can get “squirrelly.”

I do have to take into account the post Ruby 1.8 “ **`Win32API.rb`** ” wrapper replacement for “ **`Win32API.so`** ”, but that is one I now expect.

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [April 16, 2016, 4:36pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/9 "2016-04-16T16:36:07Z")

</div>

> [@DanRathbun](#):
>
> What did they become ?

the extension for these is **.plugin** and it’s internal structure is the same as a **.app**

```plaintext
~/Library/Application\ Support/SketchUp\ 2016/SketchUp/Plugins/XmlImporter.plugin 
Contents

~/Library/Application Support/SketchUp 2016/SketchUp/Plugins/XmlImporter.plugin/Contents:
Info.plist	MacOS Resources

~/Library/Application Support/SketchUp 2016/SketchUp/Plugins/XmlImporter.plugin/Contents/MacOS:
XmlImporter

~/Library/Application Support/SketchUp 2016/SketchUp/Plugins/XmlImporter.plugin/Contents/Resources:
English.lproj

~/Library/Application Support/SketchUp 2016/SketchUp/Plugins/XmlImporter.plugin/Contents/Resources/English.lproj:
InfoPlist.strings	OptionsDialog.nib

```

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [April 16, 2016, 5:18pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/10 "2016-04-16T17:18:26Z")

</div>

Oh, OK, then it’s that confusing alter-platform use of the word “plugin”.

Does it differ much from a “bundle” ?

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [April 16, 2016, 5:59pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/11 "2016-04-16T17:59:06Z")

</div>

> [@DanRathbun](#):
>
> Does it differ much from a “bundle” ?

they have different icons…

the contents could be identical…

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [April 16, 2016, 6:30pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/12 "2016-04-16T18:30:45Z")

</div>

“Bundle” is the generic term for a folder with specifically structured contents. OS X understands certain types of bundles, including applications, frameworks, plugins, media libraries, packages…

---

<div class="post-metadata">

**Author:** ![arularasu](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@arularasu](https://forums.sketchup.com/u/arularasu)\
**Post date:** [June 3, 2016, 9:43am UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/13 "2016-06-03T09:43:10Z")

</div>

Hi Guys thanks for the information’s. I have a great problem in starting my first sketchup plugin. I am good in c++.  
Can any one provide a step by step info to create a plugin.

---

<div class="post-metadata">

**Author:** ![MaryG](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@MaryG](https://forums.sketchup.com/u/MaryG)\
**Post date:** [June 16, 2017, 5:36pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/14 "2017-06-16T17:36:32Z")

</div>

It is year later, in searching for the same answer, I find only the question. If there is an answer, please post it or a link to it. Thanks!

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [June 16, 2017, 9:12pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/15 "2017-06-16T21:12:33Z")

</div>

The **C++** SDK will soon be deprecated. You should migrate to the new **C** SDK.

[https://extensions.sketchup.com/en/developer\_center/sketchup\_sdk](https://extensions.sketchup.com/en/developer_center/sketchup_sdk)

In the root folder of the SDK archive, there is a file **“`migration_guide.html`”** that you should read.

* * *

A deprecated **C++** example “ **skptoxml** ” plugin is included with the SDK in path:  
**“`.../deprecated/SkpReader/Examples/skptoxml`”**

* * *

Examples for the new **C** API:

> **[GitHub - SketchUp/ruby-c-extension-examples: Ruby C extension examples](https://github.com/SketchUp/ruby-c-extension-examples)**
>
> Ruby C extension examples. Contribute to SketchUp/ruby-c-extension-examples development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![MaryG](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@MaryG](https://forums.sketchup.com/u/MaryG)\
**Post date:** [June 18, 2017, 3:34am UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/16 "2017-06-18T03:34:49Z")

</div>

I’m still having trouble finding out how to load the completed .dll into SketchUp. If I can get those step-by-step instructions, that would be great.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [June 18, 2017, 5:10pm UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/17 "2017-06-18T17:10:46Z")

</div>

Mary, **if it is a dedicated importer or exporter** plugin, then Thomas answers above (and mentions the “Exporters” subfolder, but there is also an “Importers” subfolder for importer plugins.) You also must implement the appropriate C interface in the API.

_See:_

> [@How to add C++ plugins to SketchUp editor](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/2):
>
> On OS X you have to place the bundle file under the same plugins directory where you place the ruby extensions, (or not recommended, in the plugins folder in the .app) On Win you have to place it under a folder called exporters, example: C:\Program Files\SketchUp\Exporters I forwarded this internally to improve the docs.

* * *

**If it actually is a Ruby extension** then Ruby’s [**`require()`**](http://ruby-doc.org/core-2.2.4/Kernel.html#method-i-require) method can load **so** and **dll** files, among a few other types. (Ruby itself is written in **C** language.)

But in order for **`require()`** to load it, it must have an entry point that Ruby can find. This entry point (C function) always begins with the prefix “`Init_`” and always has the suffix of the library filename (minus the extension.)

So if your C extension filename is “ **`MaryG_utils.dll`** ” then the entry point C function must be named “**`Init_MaryG_utils()`**”.

If your C extension filename was “ **`MaryG_nifty_tools.so`** ” then the entry point C function must be named “**`Init_MaryG_nifty_tools()`**”.

And this C function entry point must initiate any interfaces between the Ruby interpreter side and the C side of your extension. Example, **at the bottom** of your C extension code:

```auto
// Entry point of the C extension.
extern "C" CEXT_EXPORT
void Init_MaryG_nifty_tools()
{
  VALUE mMary_G_TopLevel = rb_define_module("MaryG");
  VALUE mNifty_Tools = rb_define_module_under(mMary_G_TopLevel ,"NiftyTools");
  // Define a ruby module method MaryG::NiftyTools::tool_help
  rb_define_module_function(mNifty_Tools, "tool_help",
      VALUEFUNC(ToolHelp), 0); // calls the C function ToolHelp defined above
  // ... other Ruby object interface definitions ...
}

```

For more information of writing Ruby C extensions, see this PDF book “ **Extending Ruby 1.9** ”:

> **[ext\_ruby.pdf](https://media.pragprog.com/titles/ruby3/ext_ruby.pdf)**
>
> 486.54 KB

---

<div class="post-metadata">

**Author:** ![MaryG](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@MaryG](https://forums.sketchup.com/u/MaryG)\
**Post date:** [June 20, 2017, 1:23am UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/18 "2017-06-20T01:23:23Z")

</div>

I think I am still not composing my rb file correctly for the “nifty” example. My NiftyTools.dll does not appear to be loading?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [June 20, 2017, 5:23am UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/19 "2017-06-20T05:23:48Z")

</div>

There are examples that come with the SDK.

And some on the SketchUp GitHub site (which I gave the link to [above](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/15).)

---

<div class="post-metadata">

**Author:** ![MaryG](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@MaryG](https://forums.sketchup.com/u/MaryG)\
**Post date:** [June 21, 2017, 3:57am UTC](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679/20 "2017-06-21T03:57:50Z")

</div>

I have looked at the github samples and the SDK samples. What is incomplete is, once you have your .dll (or renamed as a .so file), SketchUp 2017 requires it to be put together in a .rbz (zip file). The samples do not give the complete story, how to compose the …rbz and all the files in it. Also, a readme.txt file as to where the loaded plugin should appear in the menus (or other ways) so that you know it loaded and can be tested.

[Next page](https://forums.sketchup.com/t/how-to-add-c-plugins-to-sketchup-editor/23679.md?page=2)
