Will NOT scramble ??
-
@thomthom said:
Plugins/foobar.rb
<span class="syntaxdefault">require </span><span class="syntaxstring">'sketchup.rb'<br /></span><span class="syntaxdefault">require </span><span class="syntaxstring">'extensions.rb'<br /><br /><br /></span><span class="syntaxdefault">module Author<br /> module PluginName<br /> <br /> </span><span class="syntaxcomment"># Constants<br /></span><span class="syntaxdefault"> PATH </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">dirname</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> __FILE__ </span><span class="syntaxkeyword">),</span><span class="syntaxdefault"> </span><span class="syntaxstring">'PluginSupportFolder'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">).</span><span class="syntaxdefault">freeze<br /> <br /> </span><span class="syntaxcomment"># Extension<br /></span><span class="syntaxdefault"> loader </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> PATH</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'loader.rb'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> ex </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> SketchupExtension</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Hello Scrambled World'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> loader </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> ex</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">description </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Lorem Ipsum"<br /></span><span class="syntaxdefault"> ex</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">version </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'1.0.0'<br /></span><span class="syntaxdefault"> ex</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">copyright </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'John Smith © 2012'<br /></span><span class="syntaxdefault"> ex</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">creator </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'John Smith (john@example.com)'<br /></span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">register_extension</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> ex</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> true </span><span class="syntaxkeyword">)<br /><br /></span><span class="syntaxdefault"> end </span><span class="syntaxcomment"># module PluginName<br /></span><span class="syntaxdefault">end </span><span class="syntaxcomment"># module Author </span><span class="syntaxdefault"></span>
Plugins/PluginSupportFolder/loader.rb
<span class="syntaxdefault">require </span><span class="syntaxstring">'sketchup.rb'<br /><br /><br /></span><span class="syntaxdefault">module Author<br /> module PluginName<br /> <br /> </span><span class="syntaxcomment"># Menus and Toolbars<br /></span><span class="syntaxdefault"> unless file_loaded</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">basename</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">__FILE__</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> m </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Plugins'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> m</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">...</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> <br /> </span><span class="syntaxcomment"># Load the rest of the files - which might be scrambled.<br /></span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;require(</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">PATH</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'file1'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;require(</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">PATH</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'file2'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;require(</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">PATH</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'file3'</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /><br /></span><span class="syntaxdefault"> end </span><span class="syntaxcomment"># module PluginName<br /></span><span class="syntaxdefault">end </span><span class="syntaxcomment"># module Author<br /><br /></span><span class="syntaxdefault">file_loaded</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">basename</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">__FILE__</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span>
Sorry, but I still don't understand - are the two code samples two alternatives or ONE way to do WHAT ?
In the second code you have "PluginName" - what is that compared to the items under the Plugin menu ?
and what is it compared to the "the rest of the files" ... file1, file2 and file 3 ?How are the folder structure - should ALL my .rb and .rbs files be store in the PluginSupportFolder ?
Are "loader.rb" a peace of code that load ALL my plugins under the menu "Plugins" or .. ?
Please give me some overview of the structure.
I get this error message when running SketchUp:
Error Loading File C:/Program Files/Google/Google SketchUp 8/Plugins/PluginSupportFolder/loader.rb
tried to create Proc object without a blockError Loading File Foobar.rb
tried to create Proc object without a block -
You have a script xxx.rb file that is placed in the Plugins folder.
this file will then auto-load/run, and thereby it creates an Extension.
It also sets /tool_folder/yyy.rb to be loaded IF the Extension is active, but not otherwise.
The /tool_folder/yyy.rb file is a 'loader' script.
It does not auto-load/run because it's in the subfolder - but it is activated from the xxx.rb file that itself loads from Plugins, IF the specified Extension is active...
When loaded the yyy.rb file will create, menus, submenus, context-menus and toolbars... AND it loads the file[s] /tool_folder/aaa.RBS etc - which are your files containing the main code for your tool[s].
RBS files are compiled but IF you are not compiling them they will simply end in .RB and will be human-readable...
The Plugins subfolder, referred to above as 'tool_folder', is your own subfolder in Plugins; and inside which you package your main tools' files.
It can be a single user named subfolder with more subfolders for each tool - e.g. then you'd use Plugins/KSOR_tools_folder/tool_aaa/yyy.rb - or it can be a tool-specific folder like Plugins/KSOR_tool_aaa/yyy.rb - you choose...
This subfolder [or its subfolders] can also contain any images needed for toolbar-buttons and the many files used to make webdialogs etc... -
@tig said:
You have a script xxx.rb file that is placed in the Plugins folder.
this file will then auto-load/run, and thereby it creates an Extension.
It also sets /tool_folder/yyy.rb to be loaded IF the Extension is active, but not otherwise.
The /tool_folder/yyy.rb file is a 'loader' script.
It does not auto-load/run because it's in the subfolder - but it is activated from the xxx.rb file that itself loads from Plugins, IF the specified Extension is active...
When loaded the yyy.rb file will create, menus, submenus, context-menus and toolbars... AND it loads the file[s] /tool_folder/aaa.RBS etc - which are your files containing the main code for your tool[s].
RBS files are compiled but IF you are not compiling them they will simply end in .RB and will be human-readable...
The Plugins subfolder, referred to above as 'tool_folder', is your own subfolder in Plugins; and inside which you package your main tools' files.
It can be a single user named subfolder with more subfolders for each tool - e.g. then you'd use Plugins/KSOR_tools_folder/tool_aaa/yyy.rb - or it can be a tool-specific folder like Plugins/KSOR_tool_aaa/yyy.rb - you choose...
This subfolder [or its subfolders] can also contain any images needed for toolbar-buttons and the many files used to make webdialogs etc...A good one - I'll try to get the structure set up - but a little fire was started in the end and a little smoke came up ... ha, ha !
-
This code samples sucks more and more of just killing time !
Now I can't use the danish special signs æøåÆØÅ instide a string without fooling the interpretor !
I get very, very tired when things like tha tcomes up ... Zzz ZZ ZZZZZ yawning .... prusssssss
-
@ksor said:
Sorry, but I still don't understand - are the two code samples two alternatives or ONE way to do WHAT ?
ONE way to define a
SketchupExtension
class compatible plugin.ThomThom's example was (an incomplete,) short version, of my longer, more verbose, lesson that you can find here:
[ Code ] SketchupExtension and rbs rubies
It is not necessary to completely quote large code blocks.. you can can reference them using a [ url ] bbCode tag (like I did above.)
The error you are getting.. is because it was an incomplete sample, and was missing the menu_item
**{**
...**}**
code block, on line 10, of the "loader.rb" sample.He never intended you to try and load those files as is. He expected you to modify them to use with REAL module names, and REAL file names.
Whenever you see a module name "Author", you are expected to replace that with YOUR OWN TOPLEVEL AUTHOR module name.
Whenever you see a submodule "Plugin..." name, you are expected to replace that with YOUR OWN SPECIFIC PLUGIN submodule name.
-
@ksor said:
Now I can't use the danish special signs æøåÆØÅ instide a string without fooling the interpretor !
Are you saying that UTF-8 characters do not work inside scrambled rubies ???
Did you save your unscrambled rb file as "UTF-8 without BOM" (aka "ANSI as UTF-8"), before scrambling ???
-
@ksor said:
In the second code you have "PluginName" - what is that compared to the items under the Plugin menu ?
That is up to YOU.
You can create a "toplevel" author submenu, ("KSOR Plugins" or whatever,) and put all your plugin sub-submenus under that. (But you must create the submenu in the outer KSOR module definition, assign it to a constant or
@@
module variable. (If you use a@@
module var, you'll need to define a getter method, so you submodules can get a handle to it, later, to add submenus and menuitems. Then EACH of your plugins mustrequire
the file for your author module.)# ALL KSOR plugins must call; require("KSOR/KSOR_module.rb") module KSOR MENU = UI.menu('Plugins').add_submenu('KSOR Plugins') unless defined?(MENU) END
If some of your plugins only have 1 menuitem, then they do not need a sub-submenu of their own, and you can just put the menuitem on the "KSOR Plugins" submenu.
OR... first create a "Plugin Options" submenu of the "KSOR Plugins" submenu, add a menu separator, and then ...
As each plugin is loaded:- Place any menuitem commands to use plugin features, on the "KSOR Plugins" submenu (and they'll appear below the menu separator.)* If a plugin has menuitem commands to change settings or options, those commands can go either on your "KSOR Plugins/Plugin Options" submenu, or you can create a special sub-sub-submenu, under "KSOR Plugins/Plugin Options" for that specific plugin (IF you think you need to keep IT'S option menuitems separate from your other plugin option menuitems.)
@ksor said:
[What is] the folder structure - should ALL my .rb and .rbs files be store[d] in the PluginSupportFolder ?
YES .. a specific plugin subfolder, OF YOUR OWN AUTHOR folder, probably named "Plugins/ksor".
@ksor said:
Please give me some overview of the structure.
Keep it simple !!
1) Use the same name for your toplevel author namespace, AND your toplevel folder (directory.)
2) Use the same names for your submodule names, AND your subfolder names. (This makes it easier to remember what the pathstrings and namespace stings will be, when you code
require()
,load()
andinclude()
arguments.3) SketchupExtension registration scripts:
- IF they will be in the "Plugins" folder, prefix their filename, with "Author_" (where Author is YOUR toplevel module name, aka YOUR namespace.) This helps prevent name clashes, and we can tell at a glance in a directory listing, who authored the file.)
- Put the PluginName into the filename, after any prefix, and before the suffix. (Where PluginName is the name of the plugin, or it's submodule name. This helps prevent filename clashes, and we can tell at a glance in a directory listing, what plugin it registers.)
- Suffix them with "_ext.rb" so we can tell at a glance, that they are SketchupExtension registration scripts.
Example: In "Plugins" folder:
"KSOR_WidgetMaker_ext.rb"
which registers a "WidgetMaker" plugin, and IF the user turns it on (in the Preferences dialog,) would run a loader script:
"Plugins/KSOR/WidgetMaker/loader.rb"@ksor said:
Are "loader.rb" a peace of code that load ALL my plugins under the menu "Plugins" or .. ?
NO... it was meant to be an example of loading a specific plugin, and would be within a specific plugin subfolder.
If you will have loader scripts for various plugins, in a common subfolder, (of YOUR author folder,) then you must prefix the filenames, like:
"pluginname_loader.rb" -
@dan rathbun said:
@ksor said:
Now I can't use the danish special signs æøåÆØÅ instide a string without fooling the interpretor !
Are you saying that UTF-8 characters do not work inside scrambled rubies ???
Did you save your unscrambled rb file as "UTF-8 without BOM" (aka "ANSI as UTF-8"), before scrambling ???
What I say is that I used some ordinary danish characters æøåÆØÅ and the the interpretor crashed with a lot of errors !
If I saved with or without BOM ... how should I know !
Tell me WHAT I should save it as - and I hope this BOM or not could be set up automatic - where do I do that ?
I think I'll HAVE to spend more time looking at your lesson on this matter to get this BEEP up and running !
-
@ksor said:
@dan rathbun said:
@ksor said:
Now I can't use the danish special signs æøåÆØÅ instide a string without fooling the interpretor !
Are you saying that UTF-8 characters do not work inside scrambled rubies ???
Did you save your unscrambled rb file as "UTF-8 without BOM" (aka "ANSI as UTF-8"), before scrambling ???
What I say is that I used some ordinary danish characters æøåÆØÅ and the the interpretor crashed with a lot of errors !
If I saved with or without BOM ... how should I know !
It is on the Notepad++ Status Bar:
@ksor said:
Tell me WHAT I should save it as -
"UTF-8 without BOM" on the menu. (aka "ANSI as UTF-8" on the Statusbar):
@ksor said:
... and I hope this BOM or not could be set up automatic - where do I do that ?
see the topic on Notepad++:
[Info] Notepad++ : Tip, Tricks & Plugins -
Dan - again you are there right before the ship goes down - a really nice lesson you've done !
BUT ...
I tried to use it and create the folder structure and replaced my name for AUTHOR and my plugin name for WIDGET and when I run SU I get this completely non-sence error message, and I think I've carefully watched upper and lowercase - done the scrambling:
Error Loading File C:/Program Files/Google/Google SketchUp 8/Plugins/KSOR/Remskive/remskive_loader.rb
(eval):39:inrequire': uninitialized constant KSOR::Remskive::ABSDIRError Loading File KSOR_remskive_ext.rb (eval):39:in
require': uninitialized constant KSOR::Remskive::ABSDIRis it "remskive_loader.rb" that's wrong ? the file has 1 line !!!!!!!!!!!!!!!
OR
is it "KSOR_remskive_ext.rb" that's wrong ? line 39 is a COMMENT !!!!!!!!!!!!
OR
-
@dan rathbun said:
@ksor said:
@dan rathbun said:
@ksor said:
Now I can't use the danish special signs æøåÆØÅ instide a string without fooling the interpretor !
Are you saying that UTF-8 characters do not work inside scrambled rubies ???
Did you save your unscrambled rb file as "UTF-8 without BOM" (aka "ANSI as UTF-8"), before scrambling ???
What I say is that I used some ordinary danish characters æøåÆØÅ and the the interpretor crashed with a lot of errors !
If I saved with or without BOM ... how should I know !
It is on the Notepad++ Status Bar:
[attachment=1:1waa5u4s]<!-- ia1 -->NPP_Status_Bar.png<!-- ia1 -->[/attachment:1waa5u4s]@ksor said:
Tell me WHAT I should save it as -
"UTF-8 without BOM" on the menu. (aka "ANSI as UTF-8" on the Statusbar):
[attachment=0:1waa5u4s]<!-- ia0 -->Encode_Menu_NPP.png<!-- ia0 -->[/attachment:1waa5u4s]@ksor said:
... and I hope this BOM or not could be set up automatic - where do I do that ?
see the topic on Notepad++:
[Info] Notepad++ : Tip, Tricks & PluginsIt IS this encoding !
-
OK... in scrambled rbs files, both
__FILE__
and__LINE__
do NOT work. The Ruby standardException
classes (and all it's subclasses, includingLoadError
, use both of those functions.)SO... the info will be INCORRECT for rbs files, in any exception error message. (We have asked and asked Google to fix this.. but they have not yet done so.)
The first thing that happens is the reported error line numbers are off.
They are a sum of the number of lines into the first unscrambled file, plus the number of lines into the scrambled rbs file, where the actual error happened.But the reason for your specific error, is actually a
NameError
exception, that occured during a file load via arequire()
method call, sorequire()
re-raises the error as aLoadError
exception.Basically the problem is that a line in the rbs file.. cannot see the
**KSOR::Remskive::ABSDIR**
constant, so you must be sure that it is actually defined before ANY line tries to access it's value. -
@ksor said:
It IS this ["ANSI as UTF-8"] encoding !
OK.. so you believe that the scrambler cannot scramble and unscramble UTF-8 encoded files correctly ??
I have not yet tried it myself. (And never did say that it would work.)
All Google's extensions that they scramble, use a separate UTF-8 language strings file, that gets loaded with the
**LanguageHandler**
class (Hash
) wrappers. (It is defined in the "Tools/langhandler.rb" file.) -
@ksor said:
This code samples sucks more and more of just killing time ! ...
Dan - again you are there right before the ship goes down - ...Do not give up the ship !
You are learning a hell of a lot, in a very short period of time.
-
@ksor said:
Error Loading File C:/Program Files/Google/Google SketchUp 8/Plugins/KSOR/Remskive/remskive_loader.rb (eval):39:in
require': uninitialized constant KSOR::Remskive::ABSDIRError Loading File KSOR_remskive_ext.rb
(eval):39:inrequire': uninitialized constant KSOR::Remskive::ABSDIR
is it "remskive_loader.rb" that's wrong ? the file has 1 line !!!!!!!!!!!!!!!
Please post the one line "remskive_loader.rb" file (within a bbCode box.)
-
OH wait !!
I can see the problem... BANG! (shooting self.)
STUPID DUMB error on my part.
The constants need to be defined BEFORE the Sketchup's extension loader tries to load the
@path
file, in line 19 of the "_ext.rb" file !!I am sorry Keld.
I'll fix the example. Sheesh that was a dumb one.
(I had actually tested it with the "load on start" parameter, set tofalse
. So this error did not happen for me in testing.)DONE
-
@dan rathbun said:
OH wait !!
I'll fix the example. Sheesh that was a dumb one.
(I had actually tested it with the "load on start" parameter, set tofalse
. So this error did not happen for me in testing.)DONE
Now I see the contours of a TEMPLATE for future plugins made in THE RIGHT WAY in a HURRY - that's good practice I think !
Still I have some claims and I'll try figure it out myself before I seek you help
Advertisement