So at last there are two files that in fact holds allfunction definitions.
First YOUR_LIB.rb that holds all function definitions.
All functions are defined in a separate class (YOUR) to avoid crashes with another people's plugins.
YOUR_PLUGIN.rb holds definition of your plugin, what happens when it is initialised, what happens when You move cursor, etc.
In fact You could define all the functions You need in not in YOUR_LIB file but in a YOUR_PLUGIN , but if Tou want to use a function in another plugin, You just have to call it from library of functions , and not copy it in a plugin file.
Sunday, 7 April 2013
Wednesday, 13 March 2013
What sits in YOUR_PLUGIN_loader.rb ?
In the previous post You have seen how the base file is built, now it is time to analyse other files:
First lines to line 22 You know already.
Lines 24, 27 and 28 are used to get strings for plugin / extension description. These are used if You make a localised versions in other languages. Personally I have never used it, so I cannot quarantee that it is 100% correct.
Lines 29 to 32 gives a description of Your plugin that You will see when you will install this extention to Sketchup.
And finally line 34 which register your Plugin.
First lines to line 22 You know already.
Lines 24, 27 and 28 are used to get strings for plugin / extension description. These are used if You make a localised versions in other languages. Personally I have never used it, so I cannot quarantee that it is 100% correct.
Lines 29 to 32 gives a description of Your plugin that You will see when you will install this extention to Sketchup.
And finally line 34 which register your Plugin.
To Be Continued...
Monday, 11 March 2013
What sits in YOUR_PLUGIN_base.rb ?
So what exactly sits in the files that were mentioned in the last post ?
Let's start with YOUR_PLUGIN_base. rb file.
Lines 1 to 19 are description of the plugin, this part should be quite obvious.
Lines 21, 22 and 23 are call-outs for 3 files that are necesary for our plugin to function.
"sketchup.rb" includes all genereal ruby function definitions that sketchup normaly uses,
"YOUR_LIB.rb" includes definitions of Your functions and
"YOUR_PLUGIN.rb" includes definition of tour plugin.
Lines from 25 are executed only if this file was not already loaded.
Line 27 adds new submenu YOUR_PLUGIN to Sketchup's Plugin menu.
Line 29 adds new toolbar YOUR_PLUGIN to Sketchup.
Line 33 defines a new comand "cmd , which calls out a new tool - YOUR_PLUGIN.
Line 34 and 35 show path to icons that will sit in toolbar.
Line 36 is a tooltip - a text that will appeara whrn you hold a cursor above your toolbar.
Line 37 - sets the status bar text for your plugin
Line 38 - sets the menu item name for your plugin
Lines 39 and 40 - add YOUR_PLUGIN tool to new menu and toolbar
Let's start with YOUR_PLUGIN_base. rb file.
Lines 1 to 19 are description of the plugin, this part should be quite obvious.
Lines 21, 22 and 23 are call-outs for 3 files that are necesary for our plugin to function.
"sketchup.rb" includes all genereal ruby function definitions that sketchup normaly uses,
"YOUR_LIB.rb" includes definitions of Your functions and
"YOUR_PLUGIN.rb" includes definition of tour plugin.
Lines from 25 are executed only if this file was not already loaded.
Line 27 adds new submenu YOUR_PLUGIN to Sketchup's Plugin menu.
Line 29 adds new toolbar YOUR_PLUGIN to Sketchup.
Line 33 defines a new comand "cmd , which calls out a new tool - YOUR_PLUGIN.
Line 34 and 35 show path to icons that will sit in toolbar.
Line 36 is a tooltip - a text that will appeara whrn you hold a cursor above your toolbar.
Line 37 - sets the status bar text for your plugin
Line 38 - sets the menu item name for your plugin
Lines 39 and 40 - add YOUR_PLUGIN tool to new menu and toolbar
Wednesday, 6 March 2013
Your plugin files
In the Sketchup main directory there is a Plugin folder. inside You will find a ruby file named 'sketchup.rb'. This file is very important and it will be called by other ruby files in our plugin.
Inside the template there are two ruby files, one is 'Your_Plugin_Loader.rb' and is used to load your plugin while Sketchup is starting. The other one is 'Your_library.rb'. Here we will write all the functions that will be needed on our way. In the template is located also a folder named Your_plugin, and inside You will find three files (later it can be more).
These are an graphic file with icon, 'Your_plugin_base.rb' ruby file which is a definition of toolbars and menus, and also 'Your_plugin.rb' where we will write our plugin definition.
To be continued...
Tuesday, 5 March 2013
Voronoi diagram - introduction
And so we start - again!
This is a first post from what I expect to be quite a long story. I will try to show all the steps needed to create a Sketchup plugin that will allow You to create a Voronoi diagram.
Some of the readers will ask what that is - well picture is worth more than words:
From wikipedia:
"A Voronoi diagram is a way of dividing space into a number of regions. ... The regions are called Voronoi cells. It is dual to the Delaunay triangulation."
So as You can see on the picture above, In Sketchup You have to draw a set of polygons around specified points. But how do You know where are the vertices of every polygon located? What steps You have to take ?
So to create a Voronoi diagram from group of points we will write a function called "Voronoi tesselation", that will return voronoi cells as a polygons. Sounds easy, but in fact there will be a lat of steps involved.
To avoid things to get overcomplicated we will work with 2D Voronoi ( Yes, You can also make a 3D Voronoi).
In fact we will be working in 3D space, but voronoi cells will be flat. So the first step will be in fact making sure that all the points sits on the same plane. To do that we will make another function "Flatten to plane". But this will be more detailed in next post. So our flow diagram will look like this:
This is a first post from what I expect to be quite a long story. I will try to show all the steps needed to create a Sketchup plugin that will allow You to create a Voronoi diagram.
Some of the readers will ask what that is - well picture is worth more than words:
Graphic by www.cs.wustl.edu/
From wikipedia:
"A Voronoi diagram is a way of dividing space into a number of regions. ... The regions are called Voronoi cells. It is dual to the Delaunay triangulation."
So as You can see on the picture above, In Sketchup You have to draw a set of polygons around specified points. But how do You know where are the vertices of every polygon located? What steps You have to take ?
So to create a Voronoi diagram from group of points we will write a function called "Voronoi tesselation", that will return voronoi cells as a polygons. Sounds easy, but in fact there will be a lat of steps involved.
To avoid things to get overcomplicated we will work with 2D Voronoi ( Yes, You can also make a 3D Voronoi).
In fact we will be working in 3D space, but voronoi cells will be flat. So the first step will be in fact making sure that all the points sits on the same plane. To do that we will make another function "Flatten to plane". But this will be more detailed in next post. So our flow diagram will look like this:
To be continued...
Subscribe to:
Posts (Atom)