[Plugin] Component Libraries Loader
-
Your menu_maker code ~line #50 was wrongly worded - it wasn't looking in the right folder IF the folder wasn't in Plugins with the .rb file !
Here's the module part of the code again...<span class="syntaxdefault"></span><span class="syntaxcomment">###..............<br /></span><span class="syntaxdefault">module Sm4rt_CL<br /> </span><span class="syntaxkeyword">class </span><span class="syntaxdefault">List_Menu_Load<br /> def initialize</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">rep</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">nil</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">nil</span><span class="syntaxkeyword">)<br /> return </span><span class="syntaxdefault">nil </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">not rep </span><span class="syntaxkeyword">or </span><span class="syntaxdefault">not menu </span><span class="syntaxkeyword">or </span><span class="syntaxdefault">not File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">exist</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">rep</span><span class="syntaxkeyword">) or </span><span class="syntaxdefault">not File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">ftype</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">rep</span><span class="syntaxkeyword">)==</span><span class="syntaxstring">'directory'<br /> </span><span class="syntaxdefault">skps</span><span class="syntaxkeyword">=[]; </span><span class="syntaxdefault">folders</span><span class="syntaxkeyword">=[]<br /> </span><span class="syntaxdefault">Dir</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entries</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">rep</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">f</span><span class="syntaxkeyword">|<br /> </span><span class="syntaxdefault">next </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">f</span><span class="syntaxkeyword">==</span><span class="syntaxstring">'.' </span><span class="syntaxkeyword">or </span><span class="syntaxdefault">f</span><span class="syntaxkeyword">==</span><span class="syntaxstring">'..'<br /> </span><span class="syntaxdefault">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">rep</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">f</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">skps </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">f </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">ftype</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">)!=</span><span class="syntaxstring">'directory' </span><span class="syntaxkeyword">and </span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">extname</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">f</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">downcase</span><span class="syntaxkeyword">==</span><span class="syntaxstring">'.skp'<br /> </span><span class="syntaxdefault">folders </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">f </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">ftype</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">)==</span><span class="syntaxstring">'directory'<br /> </span><span class="syntaxkeyword">}<br /> </span><span class="syntaxdefault">folders</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">folder</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">join</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">rep</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">folder</span><span class="syntaxkeyword">); </span><span class="syntaxdefault">smenu</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_submenu</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">folder</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">Sm4rt_CL</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">List_Menu_Load</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">smenu</span><span class="syntaxkeyword">) if </span><span class="syntaxdefault">smenu<br /> </span><span class="syntaxkeyword">}<br /> </span><span class="syntaxdefault">skps</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">skp</span><span class="syntaxkeyword">|<br /> </span><span class="syntaxdefault">skpc</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">basename</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">skp</span><span class="syntaxkeyword">, </span><span class="syntaxstring">".*"</span><span class="syntaxkeyword">); </span><span class="syntaxdefault">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">rep</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">skp</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_item</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">skpc</span><span class="syntaxkeyword">){</span><span class="syntaxdefault">Sm4rt_CL</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">List_Menu_Load</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">component_loader</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">)}<br /> }<br /> </span><span class="syntaxdefault">end</span><span class="syntaxcomment">#initialize<br /> </span><span class="syntaxdefault">def List_Menu_Load</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">component_loader</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">nil</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">import</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">true</span><span class="syntaxkeyword">) if </span><span class="syntaxdefault">path<br /> end</span><span class="syntaxcomment">#component_loader<br /> </span><span class="syntaxdefault">def List_Menu_Load</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">menu_maker</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">folder</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">nil</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">name</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">nil</span><span class="syntaxkeyword">)<br /> return </span><span class="syntaxdefault">nil </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">not folder </span><span class="syntaxkeyword">or </span><span class="syntaxdefault">not name<br /> Sm4rt_CL</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">List_Menu_Load</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">folder</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">menu</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Plugins"</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">add_submenu</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">name</span><span class="syntaxkeyword">))<br /> </span><span class="syntaxdefault">end</span><span class="syntaxcomment">#menu_maker<br /> </span><span class="syntaxdefault">end</span><span class="syntaxcomment">#class<br /></span><span class="syntaxdefault">end</span><span class="syntaxcomment">#module<br />### auto-run at startup<br /></span><span class="syntaxdefault">librariesNames</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">value</span><span class="syntaxkeyword">| </span><span class="syntaxdefault">Sm4rt_CL</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">List_Menu_Load</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">menu_maker</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">librariesFolders</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">value</span><span class="syntaxkeyword">], </span><span class="syntaxdefault">value</span><span class="syntaxkeyword">)}<br /></span><span class="syntaxcomment">### </span><span class="syntaxdefault"></span>
Also note that I removed a redundant "submenu=[]" line
-
No I was speaking about my version of the first post.... Because there is non sens there^^
Actually the last one I send works good for me... thanks to you^^ (and your last suggestion don't or is a good solution for declaring Absolute path personally I prefers Relative declaration like you did...
But I've suppressed "submenus=[]" though...
-
damn! still impressive TIG!
I've just modified it to treat folders before skps and added the ability to load more then one folder...
File in attachment for those who want
here is the log^^
@unknownuser said:
Copyright 2011 by sm4rt (No it's TIG one in fact)
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Name : Dynamic Component Loader 0.1.1rc1
Description : load full libraries of components you often use by creating a menu list of your component libraries
inside the Sketchup Plugins Menu
Author : sm4rt but TIG
Usage : Simply edit/add the name you want to give for your component libraries inside "librariesNames" declaration
edit/add the corresponding folder path inside "librariesFolders" declaration
And that's it !
you'll no longer have to search through your disk to find model you usually use
Just feed your model libs as time goes by
Script will load sub-folders too
Date : 8.Apr.2011
Type : Loader
History:
0.1.1rc1 (8.Apr.2011) - impressive fully versatile revision
0.1.1beta1 (7.Apr.2011) - loud dirty unefficient version
-
i use this plugin as an alternative to sketchup native component browser; but, even with only one subfolder in the component folder, it takes a lot of room on the screen
would it be possible to have a button, or a key shortcut, that would open a window with only the chosen folder in sketchup component folder; by clicking on this folder, it would show its content, and it would be possible to pick up a component; like this
less room on the screen, easier to follow the path to the chosen component with the mouse
-
Is there any way to access folders outside of the SketchUp root folder? It doesn't read a folder if I enter the address as "C:\Library" or anything without the "../Components" type of notation.
-
any chance to get it working with sketchup 15?
-
it kind of does,
the code looks for the comps in two folders but they must be where the plugin itself is (plugins folder usually).
require 'sketchup.rb' #order = ["Components", "MyLibrary"] librariesNames = ["MyLibrary", "Components"] librariesFolders = { "Components" => "Components", "MyLibrary" => "MyLibrary"} module Sm4rt_CL class List_Menu_Load def initialize(rep=nil, menu=nil) return nil if not rep or not menu or not File.exist?(rep) or not File.ftype(rep)=='directory' skps=[]; folders=[] Dir.entries(rep).each{|f| next if f=='.' or f=='..' path=File.join(rep, f) skps << f if File.ftype(path)!='directory' and File.extname(f).downcase=='.skp' folders << f if File.ftype(path)=='directory' } folders.each{|folder| path=File.join(rep, folder); smenu=menu.add_submenu(folder) Sm4rt_CL;;List_Menu_Load.new(path, smenu) if smenu } skps.each{|skp| skpc=File.basename(skp, ".*"); path=File.join(rep, skp) menu.add_item(skpc){Sm4rt_CL;;List_Menu_Load;;component_loader(path)} } end#initialize def List_Menu_Load;;component_loader(path=nil) Sketchup.active_model.import(path, true) if path end#component_loader def List_Menu_Load;;menu_maker(folder=nil, name=nil) return nil if not folder or not name Sm4rt_CL;;List_Menu_Load.new(File.join(File.dirname(__FILE__), folder), menu=UI.menu("Plugins").add_submenu(name)) end#menu_maker end#class end#module ### auto-run at startup librariesNames.each {|value| Sm4rt_CL;;List_Menu_Load;;menu_maker(librariesFolders[value], value)} ###
-
Thank you
i didn't notice any change from the version i already have though
it did work perfectly in SU8
it doesn't work for me anymore in SU15components are in the components folder, the plugin is in the plugins folder
in SU15, they are far apart, maybe that's why
adding this file in my plugins folder, i do have 2 more lines in the plugins menu
"Mylibray"
"components"
but they don't unfold, and Launchup doesn't propose me components anymore when i type the name -
yes, i posted the code so you'd be sure of the one i used.
notice i took out the '../' from the 2 folders paths (start of script) - which made the script look in the directory above to the comps folder. (so it only works on su8)
if you put the folders in the same directory as the script it works. at least it does for me (check the case matches too)
need to look more into to see why it doesn't when you change the path to full (ie. "c/Program Files/SketchUp...etc etc)
-
@cadfather said:
yes, i posted the code so you'd be sure of the one i used.
notice i took out the '../' from the 2 folders paths (start of script) - which made the script look in the directory above to the comps folder. (so it only works on su8)
if you put the folders in the same directory as the script it works. at least it does for me (check the case matches too)
need to look more into to see why it doesn't when you change the path to full (ie. "c/Program Files/SketchUp...etc etc)
OK now i understand
it works for me also
muchas gracias
i shall try to change the path too...
Advertisement