Instructor content
-
Can we get the path of the resource folder?
If so, then we could add ../ back references until we're back at the root, then apply the absolute path.
Though, how does one deal with different drive letters under Windows? -
-
@bentleykfrog said:
def getInstructorContentDirectory > plugin_folder = Sketchup.find_support_file test_file.html, "Tools/My Plugin/" > plugin_folder = plugin_folder.split("test_file.html") > plugin_folder_array = plugin_folder[0].split("/") > if(plugin_folder_array[1] == "Library") > #so the plugin/tool is stored in the main library > return "../../../../Tools/My Plugin/Instructor/" > elseif (plugin_folder_array[1] == "Program Files" || plugin_folder_array[1] == "Program Files (x86)") > #the operating system is PC, so only 1 location for tools/plugins > #there's probably a better way to do this > return "../../../../Tools/My Plugin/Instructor/" > else > #not sure about this, especially since it could be traversing drives > return "../../../../../../../../../"+plugin_folder+"Instructor/" > end > end
plugin_folder = Sketchup.find_support_file test_file.html, "Tools/My Plugin/"
This is not reliable way to find the location of where your plugin is installed. This is what breaks under OSX when users place them in incorrect locations - and it will also throw errors is people install plugins to custom locations, like TIG and I do.To get the path of your plugin:
plugin_path = File.dirname( __FILE__ )
To get SU Plugins path:
su_plugin_folder = Sketchup.find_support_file( 'Plugins' )
We can get the Resource folder by using:
plugin_folder = Sketchup.find_support_file( 'Resources' )
But then there's a folder named after the current locale...
-
@kirill2008 said:
Does anyone know how to find out how many slashes and dots are needed at certain end user comp ("..\..\..\..\"). I mean if someone has installed sketchup in a custom subdirectory it is necessary to add/remove one of "..\" I guess.
I think that because its relative to [sketchup folder]/Resources/[language]/helpcontent/tool/ that it shouldn't matter where sketchup is installed, as this will be constant. The parent directory "..\" folder just goes back through tool -> helpcontent -> [language] -> resources to get you to the base [sketchup folder].
@thomthom said:
And because some OSX users put their plugins in the user folder instead of the default, one can never rely to plugins to be at a fixed relative path.
You're right this is a huge issue. I'm guessing that on OSX this path will be relative to the main library folder (ie. [primary hard drive]/Library/Application Support/[sketchup folder]/Sketchup/Resources/[language]/helpcontent/tool/). So maybe you can do some comparison between
Sketchup.find_support_file "[some_file].html", "Tools/[your_plugin]/"
and the main library location, like this:def getInstructorContentDirectory plugin_folder = Sketchup.find_support_file test_file.html, "Tools/My Plugin/" plugin_folder = plugin_folder.split("test_file.html") plugin_folder_array = plugin_folder[0].split("/") if(plugin_folder_array[1] == "Library") #so the plugin/tool is stored in the main library return "../../../../Tools/My Plugin/Instructor/" elsif (plugin_folder_array[1] == "Program Files" || plugin_folder_array[1] == "Program Files (x86)") #the operating system is PC, so only 1 location for tools/plugins #there's probably a better way to do this return "../../../../Tools/My Plugin/Instructor/" else #not sure about this, especially since it could be traversing drives return "../../../../../../../../../"+plugin_folder+"Instructor/" end end
I'm not sure about the OSX support, but I'll check after I'm finished with my work on the PC.
What do you guys think?
-niall
-
Ah!!!
Sketchup.get_resource_path( 'helpcontent' )
returns:
C:/Program Files (x86)/Google/Google SketchUp 8/Resources/en-US/helpcontent
-
File.exist?( 'C:/temp/test.png' )
Returns:
true
<span class="syntaxdefault"><br />path </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">parts </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> path</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 />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 />file </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"> root</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'temp'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'test.png'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">exist</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> file </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span>
Returns:
true
(Updated it use
File::SEPARATOR
)(
file
=C:/Program Files (x86)/Google/Google SketchUp 8/Resources/en-US/helpcontent/../../../../../../../temp/test.png
)Restricted to the drive SketchUp is installed to.
Untested under OSX -
File.exist?( 'H:/temp/test.png' )
Returns:
true
<span class="syntaxdefault"> tfile </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'H;/temp/test.png'<br /></span><span class="syntaxdefault"> tdrive </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> tfile</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'/'</span><span class="syntaxkeyword">)[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault"> path </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"> patha </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> path</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'/'</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> patha</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> tdrive<br /> parts </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> patha</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">size </span><span class="syntaxkeyword">-</span><span class="syntaxdefault"> 1<br /> root </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'../'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">*</span><span class="syntaxdefault"> parts<br /> file </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"> patha</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'/'</span><span class="syntaxkeyword">),</span><span class="syntaxdefault"> root</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'temp'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'test.png'</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">exist</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> file </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span>
Returns:
true
( file = H:/Program Files (x86)/Google/Google SketchUp 8/Resources/en-US/helpcontent/../../../../../../../temp/test.png )
So you have to know the drive letter of the file you are testing and then cludge that into the tested path...
It will then work across drives on a network - unsure of a MAC though ??? -
But, does that work for the instructor?
-
@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 !
Advertisement