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
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.
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 ?
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…
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
OK thanks for the clarification, John.
RBZ for C API examples? 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
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)
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.
the extension for these is .plugin and it’s internal structure is the same as a .app
~/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
Oh, OK, then it’s that confusing alter-platform use of the word “plugin”.
Does it differ much from a “bundle” ?
they have different icons…
the contents could be identical…
“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…
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.
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!
The C++ SDK will soon be deprecated. You should migrate to the new C 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:
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.
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:
If it actually is a Ruby extension then Ruby’s 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:
// 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”:
I think I am still not composing my rb file correctly for the “nifty” example. My NiftyTools.dll does not appear to be loading?
There are examples that come with the SDK.
And some on the SketchUp GitHub site (which I gave the link to above.)
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.