[code] Load Instructor v1.0.1

[code] Load Instructor v1.0.1

Postby bentleykfrog » Mon Mar 14, 2011 2:26 am

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.pdf


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
0
Last edited by bentleykfrog on Thu Mar 17, 2011 3:17 am, edited 2 times in total.

bentleykfrog 
 

Re: [code] Load Instructor

Postby Dan Rathbun » Mon Mar 14, 2011 5:22 am


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.
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: [code] Load Instructor

    Postby bentleykfrog » Mon Mar 14, 2011 9:39 pm

    Dan Rathbun wrote:
    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.)


    :oops: 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 ;)
    0

    bentleykfrog 
     

    Re: [code] Load Instructor

    Postby Dan Rathbun » Mon Mar 14, 2011 11:11 pm

    Woops .. another boo-boo in the PDF.

    Section 4.1
    The example will raise an exception, as you used attr_accessor() to create getter and setter methods.

    So in your example (below) instructor_folder and temp_folder are actually method calls instructor_folder() and temp_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.)
    Code: Select all
    # 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.
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: [code] Load Instructor

      Postby Dan Rathbun » Tue Mar 15, 2011 12:26 am

      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 the lins_setup() method.

      Then we can also add in Class method copies, ie:
      Code: Select all
          public
          
          def relative_instructor_path
              
      # lins_return_relative_path() <---< needs to be called at end of lins_setup()
            return @@relative_instructor_path
          end
          
          def temp_instructor_folder
              
      # lins_return_temp_instructor_folder_name()  <---< needs to be called at end of lins_setup()
            return @@temp_instructor_folder
          end

          
      # Create Public Class methods in Mixed-in Class
          #
          def included(obj_def)
            obj_def.class_eval %q{
              public
              
              def self
      .relative_instructor_path
                return 
      @@relative_instructor_path
              end

              def self
      .temp_instructor_folder
                return 
      @@temp_instructor_folder
              end
            
      }
          end

      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.
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: [code] Load Instructor v1.0.1

        Postby bentleykfrog » Thu Mar 17, 2011 3:24 am

        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.
        0

        bentleykfrog 
         

        SketchUcation One-Liner Adverts

        by Ad Machine » 5 minutes ago



        Ad Machine 
        Robot
         



         

        Return to Developers' Forum

        Who is online

        Users browsing this forum: No registered users and 11 guests

        Visit our sponsors: