A few newbie questions...
-
1) It would be best if you separate each of your different questions into separate posts, with a specific "topical" question as the title.
2) But first... try to use the forum search box to see if there are already topic threads on each specific question. Read those first, and if you have more questions, reply post to the end of that thread (rather than start a new one.)
3) Visit my Ruby Newbie's Guide to Getting Started
Follow the advice, read the tutorials for standard Ruby, and those specific to Sketchup. Collect the references (CHMs and PDF books, etc.)
4) Look at the examples available through the Code Snippets sticky post, take note that I have a "work in process" By Subject index, as the 2nd post in that thread.
5) Read the Ruby code, written by the better authors (especially those who use modules to wrap their code.) Beware, many, if not all of the Google examples, do not follow best practices.
-
@frankn said:
First... I know how to add an item to a menu and even creat a submenu. But how do I add servel scripts/items to a menu I already created? Example... I created a series of 3(so far) ruby scripts but I'd like for all of them to be in the same submenu... Plugins -> SUBMENU -> ITEM1 -> ITEM2...
The best example for you to read, would be one I helped "cleanup" for another guy (Andrew,) who was experienced coding, but not in Ruby.
Get the plugin here: [Plugin] Voxelize
and:
-
Look at how it's double Module wrapped in a plugin namespace, within the author's toplevel namespace.
-
How we have constants at the top for "tweeking" the menus, and how we use module variables (they begin with "@@",) to hold a reference to the menus and submenus, that are used later to add items.
"Later" can also mean in other scripts by the same author, that are are wrapped within the same module namespace.
-
-
Thanks for all the links Dan I really do appreciate your help and time you took to show me how things work around here. Like they say, give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. Looks like I have a lot of reading to do.
In my defense I have zero programming experience and I've search a whole lot but just haven't been able to find answers that made sense to my newbie brain.
Frank
-
@frankn said:
In my defense I have zero programming experience and I've search a whole lot but just haven't been able to find answers that made sense to my newbie brain.
We all were newbies once. Take it slow and start by doing simple things first to gain confidence. Then experiment with more complex advanced projects. Sometimes it requires re-reading something several times until it "sinks" in.
BTW.. the Voxelize plugin has an example of creating Components also.
-
@frankn said:
Third... how can I call or the scripts from a subfolder within the plugins folder? I want to put all the scripts I create inside a sinlge folder for better organization.
To load something only once use the Ruby method
require()
Assume you have an author subdir named "FrankFolder", and a script in that folder named "cubeutil.rb":
require('FrankFolder/cubeutil.rb')
The
require()
method uses the$LOAD_PATH
array (aka$:
,) to find files. The paths to the standard Plugins and Tools folders are added to the$LOAD_PATH
by Sketchup.
The method also checks the$LOADED_FEATURES
array (aka$"
,) and does not reload the script if it has already been loaded.If you wished to reload a script, regardless of whether it had been loaded before, you would use the Ruby method
load()
(unless it's a scrambled rbs file, then you must use theSketchup.load()
method.):load('FrankFolder/cubeutil.rb')
or
Sketchup.load('FrankFolder/cubeutil.rbs')
-
Do you know if this is still the case?
I'm trying to reload an rbs file to perform a live patch of some methods;Sketchup.load('file_path.rbs') returns 0 the first time, then false on subsequent calls, same as Sketchup::require
Is there a global equivalent to $" that SU stores the list of files in, that I can delete the file name from to force a reload?
thanks
SU 8.0 M2, Mac
-
@archidave said:
Do you know if this is still the case?
I'm trying to reload an rbs file to perform a live patch of some methods;Sketchup.load('file_path.rbs') returns 0 the first time, then false on subsequent calls, same as Sketchup::require
Is there a global equivalent to $" that SU stores the list of files in, that I can delete the file name from to force a reload?
thanks
SU 8.0 M2, Mac
$loaded_files
-
The
$loaded_files
global is used as a "menu guard" to guard against duplicating menu items when re-loading plugins.Sketchup#load
does not look at$loaded_files
as far as I know.If I remember, Sketchup#load is an alias for Sketchup#require, so looks at $LOADED_FEATURES global for loaded files.
-
@jim said:
If I remember, Sketchup#load is an alias for Sketchup#require, so looks at $LOADED_FEATURES global for loaded files.
Correct. Annoyingly Sketchup::load call Sketchup::require - we have a bug filed for that.
And $LOADED_FEATURES is indeed where you want to remove the entry from the RBS you want to reload. -
And depending upon version, either the relative or absolute path, or both script path(s), (sometimes downcased,) were pushed into the
$LOADED_FEATURES
array.Sometimes we need a table to keep track of things like this from version to version.
Advertisement