[code] Load Instructor v1.0.1
-
load_instructor is a Mixin Module that automates copying of instructor files to the temporary directory on pc to bypass the issue with getInstructorContentDirectory only accepting relative paths. Whether it needs to copy the files or not, it will provide a getInstructorContentDirectory method to your class that will return a relative path to your instructor folder. This means its possible to keep your script completely portable cross-platform and ensures that your instructor is loaded to the Instructor window.
A basic definition of use is included in the comments section of the script.
Installation instructions.
- Extract the zip file after downloading
- Copy the /mixin/ directory to your Plugins or Tools folder
- Read the code comments or the Users Guide attached to this post for integration with your script
File structure:
- [Plugins OR Tools Folder]/mixin/
- [Plugins OR Tools Folder]/mixin/load_instructor.rb
Users Guide
Load Instructor - Users Guide [Updated 2011-03-15]Changelog
-
v 1.0.1 (2011-03-17)
-
Added folder in temp path creation if folders in path don't exist
-
Added proper temp file deletion (fix to File Not Found Error)
Attached is the Module
-
Excellent Help File Niall !!!!
A little boo-boo, help file says version 1.0 which it should be, but the script header still has beta 0.2 listed.
A few clarifications for section 5
(You missed the 'b' in my surname. Rathbun is a version of Rathbone, but the immigrant to America was illiterate.)- Calling getInstructorContentDirectory from within the Module
"Calling" should read "Defining"
strike the word "from"The mixin module defines the instance method(s) to be "mixed-in" to a custom class definition. The actual method that gets called or executed, is the instance copy that gets created when a custom Tool class is used, via the standard constructor
new()
. So Sketchup Ruby calls the tool instance's copy of the method, not the defintion in the Tool class, and not the defintion the Tool class inherited from the mixin module.
-
@dan rathbun said:
Excellent Help File Niall !!!!
A little boo-boo, help file says version 1.0 which it should be, but the script header still has beta 0.2 listed.
A few clarifications for section 5
(You missed the 'b' in my surname. Rathbun is a version of Rathbone, but the immigrant to America was illiterate.)Sorry for incorrectly spelling your name Dan. I've updated the pdf and the load_instructor.rb file to fix all that you've picked up on. Hopefully there's no more spelling errors
-
Woops .. another boo-boo in the PDF.
Section 4.1
The example will raise an exception, as you usedattr_accessor()
to create getter and setter methods.So in your example (below)
instructor_folder
andtemp_folder
are actually method callsinstructor_folder()
andtemp_folder()
, which is why I personally use empty () for method calls that have no args. It clarifys things.. helps the reader realize that it's a method call and not a local variable.)# Returning the folder variables instructor_folder = @instructor_folder.dup temp_folder = @temp_folder.dup # Setting the folder variables @instructor_folder = instructor_folder @temp_folder = temp_folder
(The setting examples will not raise an exception, but do nothing but set the values to the values they already have.)
The user should be told to use the attribute getters and setters created by the
attr_accessor()
method.
You may consider having a "Issue" or "Revsion" number for the PDF document, that uses the module version as a prefix.
-
I think you need some changes in the public section:
The 2 public instance methods call instance methods that init the two class variables.
I think these init calls need to move to the end of thelins_setup()
method.Then we can also add in Class method copies, ie:
<span class="syntaxdefault"> public<br /> <br /> def relative_instructor_path<br /> </span><span class="syntaxcomment"># lins_return_relative_path() <---< needs to be called at end of lins_setup()<br /></span><span class="syntaxdefault"> return </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">relative_instructor_path<br /> end<br /> <br /> def temp_instructor_folder<br /> </span><span class="syntaxcomment"># lins_return_temp_instructor_folder_name() <---< needs to be called at end of lins_setup()<br /></span><span class="syntaxdefault"> return </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">temp_instructor_folder<br /> end<br /><br /> </span><span class="syntaxcomment"># Create Public Class methods in Mixed-in Class<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> def included</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">obj_def</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> obj_def</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">class_eval </span><span class="syntaxkeyword">%</span><span class="syntaxdefault">q</span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault"> public<br /> <br /> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">relative_instructor_path<br /> return </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">relative_instructor_path<br /> end<br /><br /> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">temp_instructor_folder<br /> return </span><span class="syntaxkeyword">@@</span><span class="syntaxdefault">temp_instructor_folder<br /> end<br /> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> end<br /></span>
The Class methods cannot call the instance methods in the instance(s) unless a handle to each instance is stored at the class level. In practice.. most Sketchup Tools should be written as Singletons, and only one instance should be in existance at a given time.
-
Just updated the code with a very quick fix.
In the previous version on PC, there was an error produced in the ruby console along the lines of "Directory Not Empty". In early beta versions the temporary folder name was created from a unique string using a timestamp. In the current version, consistent temporary folder names was implemented, so any previous directories needed to be deleted.. I've expanded the delete method in the script to search the subdirectories of the temporary folder if it exists and clear them out before deletion. This stops the error.
Also, when the temporary location was more than one folder deep (ie. my_script/instructor), the folder 'my_script' was not being created. V 1.0.1 searches each folder in your custom temporary path and creates the folder if it doesn't exist, removing this error.
This update is essential for proper implementation of Load Instructor.
Advertisement