Instructor content
-
@thomthom said:
But, does that work for the instructor?
My original idea works as the number of steps down the folder structure equals the number of steps up...
If I add in a drive letter cludge it fails - bamboozled... -
Yea, if we have to specify a path relative to a fixed one we're restrained to the drive the fixed path originates from.
(unless someone can show of a neat trick around that...?)So far, my wrapper looks like this:
<span class="syntaxdefault"><br /> </span><span class="syntaxcomment"># Get Instructor Path<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Tool.getInstructorContentDirectory expects a path relative to SketchUp's<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Resource/<locale>/helpcontent/ folder, despite the documentations use an<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># absolute path.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># This method is a wrapper that generates a path to the actual help content<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># which SketchUp can use.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># The given path must be under the same drive as SketchUp's help content.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># This quick exist in all current SketchUp versions.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Current; SketchUp 8 M1<br /></span><span class="syntaxdefault"> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_instructor_path</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> path </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> origin </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_resource_path</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'helpcontent'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Check if drive matches<br /></span><span class="syntaxdefault"> origin_drive </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> origin</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">match</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">/^(</span><span class="syntaxdefault">w</span><span class="syntaxkeyword">);/</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> if origin_drive<br /> origin_drive </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> origin_drive</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">downcase<br /> end<br /> path_drive </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> path</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">match</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">/^(</span><span class="syntaxdefault">w</span><span class="syntaxkeyword">);/</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> if path_drive<br /> path_drive </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> path_drive</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">downcase<br /> path </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> path</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">2.</span><span class="syntaxkeyword">..</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">size</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Trim drive letter<br /></span><span class="syntaxdefault"> end<br /> if path_drive </span><span class="syntaxkeyword">&&</span><span class="syntaxdefault"> origin_drive<br /> return nil unless origin_drive </span><span class="syntaxkeyword">==</span><span class="syntaxdefault"> path_drive<br /> end<br /> </span><span class="syntaxcomment"># Build relative path<br /></span><span class="syntaxdefault"> parts </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> origin</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">SEPARATOR </span><span class="syntaxkeyword">).</span><span class="syntaxdefault">size<br /> path_to_root </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"..#{File;;SEPARATOR}"</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">*</span><span class="syntaxdefault"> parts<br /> relative_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"> path_to_root</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> path </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> return relative_path<br /> end<br /></span>
Not tested under OSX.
-
@thomthom said:
Yea, if we have to specify a path relative to a fixed one we're restrained to the drive the fixed path originates from.
(unless someone can show of a neat trick around that...?)Ohhhh!!!! Just tested, Volume traversal on a mac!
plugin_path = File.dirname (__FILE__) root_dir_entries = Dir.entries(plugin_path+"/../../../../../../Volumes/") puts root_dir_entries
Hmm, if I save a model on my primary hard drive (the hard drive that my user folder is set on and sketchup is installed on) and run
model_path = Sketchup.active_model.path
in the Ruby console I get the following path:/Users/[my user name]/Desktop/Untitled.skp
. But if I save to another drive I get/Volumes/[drive namespace (not the letter)]/Untitled.skp
.Will have to check on pc.
-
Anyone with a non-English SketchUp?
Sketchup.get_resource_path( 'helpcontent' )
I'm wondering if the names of files and folders in the Resource folder depends on the current locale. -
@ThomThom: The base of the help content is:
Sketchup.get_resource_path( 'helpcontent/tool' )
-
@dan rathbun said:
@ThomThom: The base of the help content is:
Sketchup.get_resource_path( 'helpcontent/tool' )
The base for which
Tool.getInstructorContentDirectory
base that paths on is:
Sketchup.get_resource_path( 'helpcontent' )
See my earlier snippet: http://forums.sketchucation.com/posting.php?mode=quote&f=180&p=314120#pr314106
Tried and tested under Windows, English SketchUp locale. -
@thomthom said:
Anyone with a non-English SketchUp?
Sketchup.get_resource_path( 'helpcontent' )
I'm wondering if the names of files and folders in the Resource folder depends on the current locale.The files MUST be the same name, so that the
LangHandler
class can find them. (see the 'langhandler.rb' script in the Tools folder.)Beneath the 'helpcontent/tool' folder, all the subdirs have numerical names corresponding to tool_id, so they should be the same for all locales.
I cant see Google changing the names of direct subfolders of the locale folder (but who knows... I guess it's best to check. Perhaps PM Didier, he runs in French right?)
-
Full path on my computer:
C:\Program Files (x86)\Google\Google SketchUp 8\Resources\en-US\helpcontent
What I'm wondering is if the folders after
en-US
, the locale folder, might change. That maybe one needs to query the LangHandler forhelpcontent
?Just like to get it confirmed by a non-English user that the
helpcontent
folder remains as it is across locales. -
@thomthom said:
@dan rathbun said:
@ThomThom: The base of the help content is:
Sketchup.get_resource_path( 'helpcontent/tool' )
The base for which
Tool.getInstructorContentDirectory
base that paths on is:
Sketchup.get_resource_path( 'helpcontent' )
See my earlier snippet: http://forums.sketchucation.com/posting.php?mode=quote&f=180&p=314120#pr314106
Tried and tested under Windows, English SketchUp locale.Hmmm. why are Chris and the B'frog reporting 4 parent dirs up to the Sketchup dir ?
-
This returns the eraser tool on my system.
def getInstructorContentDirectory return "\\21019\\" end
Its a long way around but I'm thinking that it would be possible to write the required files and folders to the /temp/ folder on the C:/ drive before the tool loads, then use a relative path to the /temp/instructor/ directory in
getInstructorContentDirectory
. This would avoid the volume traversal problem but I think it would be a bit of a headache. -
My understanding is that it ia looking in the "tool" folder for content, so it 4 steps back to the base SU directory. This is the path on the machine I am on right now:
C:\Program Files\Google\Google SketchUp 7\Resources\en-US\helpcontent\tool
That worked for me, are you guys seeing differently?
-
Man.. I hate these crappy UI.inputboxes in the SU API !!
This is ridiculous !
-
@chris fullmer said:
That worked for me, are you guys seeing differently?
The snippet I posted work for me when I added it to Bezier Tools as a working example. I generate a relative path from
Sketchup.get_resource_path( 'helpcontent' )
-
@dan rathbun said:
PC:
VER = Sketchup.version.to_i USER_PLUGINS = File.expand_path("#{ENV['APPDATA']}\Google\Google SketchUp #{VER}\SketchUp\Plugins")
Sorry for the late reply Dan, but on my Windows 7 machine there's no Sketchup Folder, ie.
USER_PLUGINS = File.expand_path("#{ENV['APPDATA']}\Google\Google SketchUp #{VER}\Plugins")
would work. -
That is also what I have Niall. What is that extra folder you have there Dan?
-
@chris fullmer said:
That is also what I have Niall. What is that extra folder you have there Dan?
This is the APPDATA path guys, not the Program Files path (or Program Files(x86) if your on Windows 6+.)
In the APPDATA path, below the "Sketchup #{VER}" folder, for PRO, there are 3 applet folders:
"Sketchup" (where the session.dat file is kept,) "Layout" and "StyleBuilder" folders. Each one of these folders holds user settings and preference files.On Win7, the path should be:
"C:\Users\#{ENV['USERNAME']\AppData\Roaming\Google\Google SketchUp #{VER}\SketchUp\Plugins
"As I said, on the Mac the User's APPDATA "Plugins" folder is created by Sketchup, but on PC you need to create it yourself, and push the path onto the
$LOAD_PATH
array to use it forrequire()
orload()
calls.If you wish (on PC,) to have user scripts load from the APPDATA path on Sketchup startup, you need to have a script in the "Shared" Plugins folder (the one in the Program Files path,) that has a call using the
require_all()
method from the sketchup.rb file.
Ex:<span class="syntaxdefault"></span><span class="syntaxcomment"># !appdata_load.rb<br /></span><span class="syntaxkeyword">require(</span><span class="syntaxstring">'sketchup.rb'</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">VER </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">version</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_i<br />USER_PLUGINS </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">expand_path</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"#{ENV['APPDATA']}\Google\Google SketchUp #{VER}\SketchUp\Plugins"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">require_all</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> USER_PLUGINS </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span>
If you use it, the
require_all()
method will push the APPDATA plugins path onto the$LOAD_PATH
array for you.
I do have a Win7 machine in the other room, but have not yet installed Sketchup on it, so... I'm going by what "should be" according to published information. (May be that the Sketchup installer has a mind of it's own.)
Addendum: On Win7 (linix-like) you may see a symbolic link directly to AppData, in the My Computer tree that hides the "C:\Users#{ENV['USERNAME']}" prefix.
-
Sorry Dan, you lost me at "APPDATA". I never knew there was an alternate folder schema somewhere. I'm really not sure what appdata is.
-
@chris fullmer said:
Sorry Dan, you lost me at "APPDATA". I never knew there was an alternate folder schema somewhere. I'm really not sure what appdata is.
+1 on this, sorry for the confusion dan
Time to make a fool out of myself for a second time:
@thomthom said:
@chris fullmer said:
That worked for me, are you guys seeing differently?
The snippet I posted work for me when I added it to Bezier Tools as a working example. I generate a relative path from
Sketchup.get_resource_path( 'helpcontent' )
In the snippet you posted earlier, doesn't
parts = origin.split( File::SEPERATOR ).size
include the separator in the drive name (ie. C:/), so you get x+1 slashes to the root C:/ from helpcontent instead of x, which negates the/tool
folder?Also, just to double-check, is there meant to be an escaping character for w in
/^w:/
(ie./^\w:/
) or is something weird going on?sorry for the noob questions, I really appreciate the responses.
-
@bentleykfrog said:
In the snippet you posted earlier, doesn't parts = origin.split( File::SEPERATOR ).size include the separator in the drive name (ie. C:/), so you get x+1 slashes to the root C:/ from helpcontent instead of x, which negates the /tool folder?
That is a possibility... I might very well be wrong about where it base the path from. But the positive side-effect of my little bug is that it works.
@bentleykfrog said:
Also, just to double-check, is there meant to be an escaping character for w in /^w:/ (ie. /^\w:/) or is something weird going on?
You're right. And it's there in my original code - it seems that the forum ate the escape character!
Lemme try again:
Without PHP formatting:
# Get Instructor Path # # Tool.getInstructorContentDirectory expects a path relative to SketchUp's # Resource/<locale>/helpcontent/ folder, despite the documentations use an # absolute path. # # This method is a wrapper that generates a path to the actual help content # which SketchUp can use. # # The given path must be under the same drive as SketchUp's help content. # # This quick exist in all current SketchUp versions. # Current; SketchUp 8 M1 def self.get_instructor_path( path ) path = File.expand_path( path ) origin = Sketchup.get_resource_path( 'helpcontent' ) # Check if drive matches origin_drive = origin.match( /^(\w);/ ) if origin_drive origin_drive = origin_drive[1].downcase end path_drive = path.match( /^(\w);/ ) if path_drive path_drive = path_drive[1].downcase path = path[2...path.size] # Trim drive letter end if path_drive && origin_drive return nil unless origin_drive == path_drive end # Build relative path parts = origin.split( File;;SEPARATOR ).size path_to_root = "..#{File;;SEPARATOR}" * parts relative_path = File.join( path_to_root, path ) return relative_path end
With PHP formatting:
<span class="syntaxdefault"><br /> </span><span class="syntaxcomment"># Get Instructor Path<br /> #<br /> # Tool.getInstructorContentDirectory expects a path relative to SketchUp's<br /> # Resource/<locale>/helpcontent/ folder, despite the documentations use an<br /> # absolute path.<br /> #<br /> # This method is a wrapper that generates a path to the actual help content<br /> # which SketchUp can use.<br /> #<br /> # The given path must be under the same drive as SketchUp's help content.<br /> #<br /> # This quick exist in all current SketchUp versions.<br /> # Current; SketchUp 8 M1<br /> </span><span class="syntaxdefault">def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_instructor_path</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">path </span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">path </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">expand_path</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">path </span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">origin </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">get_resource_path</span><span class="syntaxkeyword">( </span><span class="syntaxstring">'helpcontent' </span><span class="syntaxkeyword">)<br /> </span><span class="syntaxcomment"># Check if drive matches<br /> </span><span class="syntaxdefault">origin_drive </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">origin</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">match</span><span class="syntaxkeyword">( /^(</span><span class="syntaxdefault">w</span><span class="syntaxkeyword">);/ )<br /> if </span><span class="syntaxdefault">origin_drive<br /> origin_drive </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">origin_drive</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">downcase<br /> end<br /> path_drive </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">path</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">match</span><span class="syntaxkeyword">( /^(</span><span class="syntaxdefault">w</span><span class="syntaxkeyword">);/ )<br /> if </span><span class="syntaxdefault">path_drive<br /> path_drive </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">path_drive</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">downcase<br /> path </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">path</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">2.</span><span class="syntaxkeyword">..</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">size</span><span class="syntaxkeyword">] </span><span class="syntaxcomment"># Trim drive letter<br /> </span><span class="syntaxdefault">end<br /> </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">path_drive </span><span class="syntaxkeyword">&& </span><span class="syntaxdefault">origin_drive<br /> </span><span class="syntaxkeyword">return </span><span class="syntaxdefault">nil unless origin_drive </span><span class="syntaxkeyword">== </span><span class="syntaxdefault">path_drive<br /> end<br /> </span><span class="syntaxcomment"># Build relative path<br /> </span><span class="syntaxdefault">parts </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">origin</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">File</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">SEPARATOR </span><span class="syntaxkeyword">).</span><span class="syntaxdefault">size<br /> path_to_root </span><span class="syntaxkeyword">= </span><span class="syntaxstring">"..#{File;;SEPARATOR}" </span><span class="syntaxkeyword">* </span><span class="syntaxdefault">parts<br /> relative_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">path_to_root</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">path </span><span class="syntaxkeyword">)<br /> return </span><span class="syntaxdefault">relative_path<br /> end<br /></span>
-
grrr.... the PHP formatter broke the code!
Advertisement