#!BPY """ Registration info for Blender menus: Name: 'Blender Library' Blender: 241 Group: 'Object' Tooltip: 'Library to store and catalog all your materials, objects, textures, etc' """ # -------------------------------------------------------------------------- # ***** BEGIN GPL LICENSE BLOCK ***** # # Copyright (C) 2006 Mariano Hidalgo AKA uselessdreamer # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # ***** END GPL LICENCE BLOCK ***** # -------------------------------------------------------------------------- __author__ = "Mariano Hidalgo AKA uselessdreamer" __url__ = ("http:\\uselessdreamer.byethost32.com\blender_library_intro.html", "http:\\blender-stuff.byethost32.com") __version__ = "1.3.3" __bpydoc__ = """ Blender Library 1.3.3 With this script you can easily store and retrieve all your materials, objects, textures, etc. You can also quickly share your stuff with other Blender users by using the built in import/ export functionality. For more information please go to: http:\\uselessdreamer.byethost32.com/blender_library_intro.html """ import Blender from Blender import * import webbrowser try: import nt os = nt os.sep='\\' except: import posix os = posix os.sep='/' from os import path try: import tarfile COMPRESSION = 1 except: COMPRESSION = 0 def first_setup(rootFolder): global DefaultAuthorName, DefaultAuthorEmail, DefaultAuthorWebPage libFolder = sys.dirname(rootFolder) libs = ["objectLib","materialLib","ipoLib","pathLib","lampLib","worldLib","cameraLib","textureLib","particleLib","actionLib","armatureLib","poseLib","latticeLib","sceneLib","logicLib"] cats = [] cats.append("Vehicles,Buildings,Furniture,Mechanical,Characters,Clothing,Weapons,Nature,Props,Tools,Aircrafts,Misc") cats.append("Skin,Terrain,Building,Abstract,Mechanical,Stone,Fabric,Organic,Metals,Technical,Water,Wood,Misc,Nature") cats.append("Simple,Complex,Misc") cats.append("Simple,Complex,Misc") cats.append("Portrait,Outdoors,Indoors,FX,Colored") cats.append("Skies,Enviroment,Grids,Abstract,Technical,Water") cats.append("Static,Motion,Misc,FX") cats.append("ColorBands,Patterns,Skin,Terrain,Building,Abstract,Mechanical,Stone,Fabric,Organic,Metals,Technical,Water,Wood,Misc,Nature") cats.append("Hair,Fur,Static,Special Fx,Motion,Physics") cats.append("Simple,Complex,Misc") cats.append("Humanoid,Mechanical,Animals,Simple") cats.append("Simple,Complex,Misc") cats.append("Simple,Complex,Misc") cats.append("Concepts,Enviroment,Demos,Tutorials") cats.append("Concepts,Game,Demos") if libFolder: if not sys.exists(sys.dirname(libFolder) + os.sep + "BlenderLib" + os.sep + "library.txt") and not sys.exists(sys.dirname(libFolder) + os.sep + "library.txt"): libFolder = sys.dirname(rootFolder) + os.sep + "BlenderLib" os.mkdir(libFolder) txt = open(libFolder + os.sep + "library.txt","w") txt.write("Blender Library Folder 1.3\n") txt.close() count = 0 for lib in libs: where = libFolder + os.sep + lib os.mkdir(where) for cat in cats[count].split(","): os.mkdir(where + os.sep + cat) count = count + 1 set_registry(libFolder) get_registry() init("material") else: if sys.exists(libFolder + os.sep + "library.txt"): txt = open(libFolder + os.sep + "library.txt","r") text = txt.readline() txt.close() if text != "Blender Library Folder 1.3\n": c = Draw.PupMenu("Old library format (1.2.1 or below). Upgrade?%t|Yes (You wont lose your content)%x1|No, let me choose another folder%x2") if c == 1: txt = open(libFolder + os.sep + "library.txt","w") txt.write("Blender Library Folder 1.3\n") txt.close() count = 0 for lib in libs: where = sys.dirname(rootFolder) + os.sep + lib if not sys.exists(where): os.mkdir(where) for cat in cats[count].split(","): if not sys.exists(where + os.sep + cat): os.mkdir(where + os.sep + cat) count = count + 1 set_registry(sys.dirname(libFolder)) get_registry() init("material") Draw.PupMenu("Now we are about to import your old content%t|Ok, go ahead...") for lib in libs: where = sys.dirname(rootFolder) + os.sep + lib + os.sep for f in os.listdir(where): if f[-3:] == "txt" or f[-3:] == "jpg" or f[-5:] == "blend": os.rename(where + f,where + lib.upper()[:-3] + "-" + f) elif f[-3:] == "dat" or f[-3:] == "bak": os.remove(where + f) import_folder(where) Draw.PupMenu("All done.%t|Itīs now safe to delete the files in the root of each lib|OBJECT-*.* ,MATERIAL-*.*, etc.") else: set_registry(sys.dirname(libFolder + os.sep)) get_registry() init("material") def init(lib): global LIB, LIB_FOLDER, LIB_FILE, LIB_TH, LIB_DAT, LIB_CATS, LIB_FAVS, FILE_NAME, setNAMEstr, DefaultDescription, MENU_MAT_SCENE, LIC, LICENSE global LIBS, IMG, BROWSING,TOTAL_CATS, TOTAL_ITEMS, CURRENT_CAT, CURRENT_ITEM, PACK, CURRENT_SUBCAT,TOTAL_SUBCATS global ITEMS, AUTHORS, DESCS, MAILS, WEBPAGES, ONAMES, SHAPE, NAMEstr, RAY, LibraryDir, DefaultName global DefaultAuthorName, DefaultAuthorEmail, DefaultAuthorWebPage, LIBmenu, CURRENT_LIB, TEXFACE, SEARCHstr global BATCH_MODE, BATCH_ALL # Init filesystem variables. LIB = lib LIB_FOLDER = LibraryDir + os.sep + LIB + "Lib" + os.sep LIB_FAVS = LIB_FOLDER + "favourites.dat" FILE_NAME = Blender.Get("filename") LIBS = ["material","object","lamp","path","ipo","world","camera","texture","particle","armature","lattice","scene","action","pose","logic"] LIBS.sort() CURRENT_LIB = LIBS.index(lib) +1 # Try to load the libThumb image; is not yet loaded, create a new one. try: IMG = Image.Get("libThumb") except: IMG = Image.New("libThumb",240,240,24) # check if Blender version can pack images via python. try: IMG.pack PACK = 1 except: PACK = 0 LIBmenu = "" for l in LIBS: LIBmenu += l.capitalize() + "s|" # Init browsing variables. TOTAL_CATS = 0 TOTAL_SUBCATS = 0 TOTAL_ITEMS = 0 CURRENT_SUBCAT = 1 CURRENT_CAT = 1 CURRENT_ITEM = 1 LIC = 1 LICENSE ="" ITEMS = [] AUTHORS = [] DESCS = [] MAILS = [] WEBPAGES = [] ONAMES = [] NAMEstr = "" setNAMEstr = "" DefaultName = "" SEARCHstr = "" MENU_MAT_SCENE = 0 SHAPE = 3 RAY = 0 TEXFACE = 0 BATCH_MODE = 0 BATCH_ALL = 0 ShowWarnigns = 1 # Init unkown author data DefaultName = "" DefaultAuthorName = "Unkown" DefaultAuthorEmail = "Not available" DefaultAuthorWebPage = "Not available" DefaultDescription = "Just some " + LIB.capitalize() get_categories() get_buffer() get_favs() get_items() def get_registry(): global DefaultAuthorName, DefaultAuthorEmail, DefaultAuthorWebPage, BROWSING,LibraryDir,ShowWarnings global AuthorName, AuthorEmail, AuthorWebPage, BROWSING,LibraryDir, SHOW_HELP rdict = Registry.GetKey('BlenderLibrary', True) if rdict: AuthorName = rdict['Default_Author_Name'] AuthorEmail = rdict['Default_Author_Email'] AuthorWebPage = rdict['Default_Author_WebPage'] DefaultDescription = rdict['Default_Description'] DefaultUsageDoc = rdict['Default_Usage_Doc'] DefaultBackground = rdict['Default_Background'] DefaultLicenseText = rdict['Default_License_File'] LibraryDir = rdict['Library_DIR'].rstrip(os.sep) ShowWarnings = rdict['Show_Warnings'] if ShowWarnings: SHOW_HELP = 1 else: SHOW_HELP = 0 if sys.exists(LibraryDir + os.sep + "library.txt"): BROWSING = 1 where = LibraryDir + os.sep +"sceneLib" if not sys.exists(where): sceneCats = ["Concepts","Enviroment","Demos","Tutorials"] os.mkdir(where) for sC in sceneCats: if not sys.exists(where + os.sep + sC): os.mkdir(where + os.sep + sC) where = LibraryDir + os.sep + "logicLib" if not sys.exists(where): logicCats = ["Concepts","Game","Demos"] os.mkdir(where) for sC in logicCats: if not sys.exists(where + os.sep + sC): os.mkdir(where + os.sep + sC) else: BROWSING = 2 else: BROWSING = 2 def set_registry(libFolder): global AuthorName, AuthorEmail, AuthorWebPage, ShowWarnings d = {} d['Default_Author_Name'] = AuthorName d['Default_Author_Email'] = AuthorEmail d['Default_Author_WebPage'] = AuthorWebPage d['Default_Description'] = "Just some " d['Default_Usage_Doc'] = "None" d['Default_Background'] = "Grid" d['Default_License_File'] = "license.txt" d['Library_DIR'] = libFolder #+ os.sep d['Show_Warnings'] = ShowWarnings Blender.Registry.SetKey('BlenderLibrary', d, True) def event(evt, val): global CURRENT_ITEM, TOTAL_ITEMS, SHOW_HELP if evt == Draw.ESCKEY or evt == Draw.QKEY: Draw.Exit() return elif evt == Draw.RIGHTMOUSE: if BROWSING != 2: if SHOW_HELP == 1: SHOW_HELP = 2 Draw.Redraw() Window.RedrawAll() show_libs() if SHOW_HELP == 2: SHOW_HELP = 1 else: c = Draw.PupMenu("Setup Menu%t|Quit%x20") if c: Draw.Exit() # Previous Item Buttom elif evt == Draw.WHEELUPMOUSE: if CURRENT_ITEM != 1: CURRENT_ITEM = CURRENT_ITEM - 1 update_thumb() Draw.Redraw(1) # Next Item Buttom elif evt == Draw.WHEELDOWNMOUSE: if CURRENT_ITEM != TOTAL_ITEMS: CURRENT_ITEM = CURRENT_ITEM + 1 update_thumb() Draw.Redraw(1) def button_event(evt): global CURRENT_CAT, CURRENT_ITEM, MENU_CAT, TOTAL_ITEMS, TOTAL_CATS, ITEMS, AUTHORS, BROWSING, NAMEstr, FAVmenu, FAVlist, MENU_MAT_SCENE, SCENE_ITEMS, SHAPE, MENU_SHAPE, setNAMEstr, MENU_LIC, LIC, LICENSE, LICS, ITEMlist global AUTHORstr,DESCstr,EMAILstr, WEBPAGEstr, DefaultAuthorName, DefaultAuthorEmail, DefaultAuthorWebPage,DefaultDescription, LIB, LIBS, RAY, obITEMS, DefaultName, CURRENT_SUBCAT, CURRENT_LIB, MENU_SUBCAT global AuthorName, AuthorEmail, AuthorWebPage, LibraryDir, MENU_LIB, TEXFACE, SEARCHstr , SearchString global BATCH_MODE, BATCH_ALL, SHOW_HELP # Load items and Favorites Menu # if evt == 1: if SHOW_HELP == 1: SHOW_HELP = 4 Draw.Redraw() Window.RedrawAll() if LIB == "material": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|Load into selected object|%l|" + FAVmenu) if LIB == "texture": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|%l|" + FAVmenu) elif LIB == "particle": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load with " + LIB + " object|Load into selected object%x122|%l|" + FAVmenu) elif LIB == "world": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|Load and set current%x99|%l|" + FAVmenu) elif LIB == "ipo": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|Load and set on this object%x121|%l|" + FAVmenu) elif LIB == "object": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|Load at 3D Cursor Position%x124|%l|" + FAVmenu) elif LIB == "path": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|%l|" + FAVmenu) elif LIB == "lamp": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "s|%l|" + FAVmenu) elif LIB == "action": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|Load and set in Armature%x136|%l|" + FAVmenu) elif LIB == "camera": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|Load and set current%x120|%l|" + FAVmenu) elif LIB == "pose": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|%l|" + FAVmenu) elif LIB == "armature": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|%l|" + FAVmenu) elif LIB == "lattice": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|%l|" + FAVmenu) elif LIB == "scene": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load this " + LIB + "|Load and set current%x127|%l|" + FAVmenu) if LIB == "logic": c = Draw.PupMenu("Load " + LIB.capitalize() + "%t|Load with " + LIB + " object|Load into selected object%x137|%l|" + FAVmenu) if SHOW_HELP == 4: SHOW_HELP = 1 # Just Load the item # if c == 1: if LIB != "pose": load_item(ITEMS[CURRENT_ITEM-1],AUTHORS[CURRENT_ITEM-1],ONAMES[CURRENT_ITEM-1],0,0) else: load_pose(ITEMS[CURRENT_ITEM-1],AUTHORS[CURRENT_ITEM-1],ONAMES[CURRENT_ITEM-1],0) # Load material and set in object # elif c == 2: load_item(ITEMS[CURRENT_ITEM-1],AUTHORS[CURRENT_ITEM-1],ONAMES[CURRENT_ITEM-1],0,0) ob = Object.GetSelected() if ob: if ob[0].getType() == "Mesh": me = NMesh.GetRaw(ob[0].getData(1)) mat = Material.Get(ITEMS[CURRENT_ITEM-1]) mats = me.getMaterials() newmats = [mat] if len(mats) <= 1: me.setMaterials(newmats) else: c = Draw.PupMenu("Replace material index?%t|1|2|3|4|5|6") mats[c-1] = mat me.setMaterials(mats) me.update() else: Draw.PupMenu("Canīt set material into this object!%t|The selected object is not a mesh.") else: Draw.PupMenu("No object selected!") # Load object at 3D Cursor. # elif c == 124: load_item(ITEMS[CURRENT_ITEM-1],AUTHORS[CURRENT_ITEM-1],ONAMES[CURRENT_ITEM-1],0,1) # Load camera and set current. # elif c == 120: load_item(ITEMS[CURRENT_ITEM-1],AUTHORS[CURRENT_ITEM-1],ONAMES[CURRENT_ITEM-1],0,0) scn = Scene.GetCurrent() scn.setCurrentCamera(Object.Get(ITEMS[CURRENT_ITEM-1])) Window.CameraView(0) Window.Redraw() # Load world and set current # elif c == 99: load_item(ITEMS[CURRENT_ITEM-1],AUTHORS[CURRENT_ITEM-1],ONAMES[CURRENT_ITEM-1],0,0) cWorld = World.Get(ITEMS[CURRENT_ITEM-1]) cWorld.setCurrent() # Load IPO and set in select object # elif c == 121: load_item(ITEMS[CURRENT_ITEM-1],AUTHORS[CURRENT_ITEM-1],ONAMES[CURRENT_ITEM-1],0,0) ob = Object.GetSelected()[0] ipo = Ipo.Get(ITEMS[CURRENT_ITEM-1]) ob.setIpo(ipo) elif c == 127: load_item(ITEMS[CURRENT_ITEM-1],AUTHORS[CURRENT_ITEM-1],ONAMES[CURRENT_ITEM-1],0,0) scn = Scene.Get(ITEMS[CURRENT_ITEM-1]) scn.makeCurrent() elif c == 136: load_item(ITEMS[CURRENT_ITEM-1],AUTHORS[CURRENT_ITEM-1],ONAMES[CURRENT_ITEM-1],0,0) actions = Armature.NLA.GetActions() for a in actions: if a == ONAMES[CURRENT_ITEM-1]: action = actions[a] ob = Object.GetSelected()[0] if ob.getType() == "Armature": action.setActive(ob) else: Draw.PupMenu("Error.%t|Please select an Armature.") Window.RedrawAll() elif c == 137: load_item(ITEMS[CURRENT_ITEM-1],AUTHORS[CURRENT_ITEM-1],ONAMES[CURRENT_ITEM-1],0,0) scn = Scene.GetCurrent() obs = scn.getChildren() logOb = Object.Get(ITEMS[CURRENT_ITEM-1]) destOb = Object.GetSelected()[0] for o in obs: o.sel = 0 destOb.sel = 1 logOb.sel = 1 Draw.PupMenu("Important!%t|Please selec Logic Bricks in the following menu.") for win in Window.GetScreenInfo(): if win["type"] == 1: winId = win["id"] Window.SetKeyQualifiers(48) Window.QAdd(winId,Draw.CKEY,1) Window.QHandle(winId) Window.QRead() Window.SetKeyQualifiers(0) for o in obs: o.sel = 0 destOb.sel = 1 logOb.copyAllPropertiesTo(destOb) Draw.Redraw() scn.unlink(logOb) scn.update() Window.RedrawAll() # Load particle setting and materials into selected object # elif c == 122: scn = Scene.GetCurrent() ob = Object.GetSelected()[0] if ob: if ob.getType() == "Mesh": load_item(ITEMS[CURRENT_ITEM-1],AUTHORS[CURRENT_ITEM-1],ONAMES[CURRENT_ITEM-1],0,0) obName = ob.getName() obMatrix = ob.getMatrix() ob.setName("libraryTemp") me = ob.getData() parOb = Object.Get(ONAMES[CURRENT_ITEM-1]) parMe = parOb.getData() parMats = parMe.getMaterials() cc = Draw.PupMenu("Add particle materials too?%t|Yes%x1|No%x2") if cc == 1: me.materials = parMats me.update() parOb.link(me) parOb.setMatrix(obMatrix) scn.unlink(ob) scn.update(1) parOb.makeDisplayList() parOb.setName(obName) Blender.Redraw() else: Draw.PupMenu("Canīt load particle settings!%t|The selected object is not a mesh.") else: Draw.PupMenu("No object selected!") # Load or remove a favourite from the menu # elif c > 2 and Window.GetKeyQualifiers() != 48: f = FAVlist[c-4].split(",") tcat = f[3].split("|") if len(tcat) == 1: f[3] = tcat[0] + os.sep elif len(tcat) == 2: f[3] = tcat[0] + os.sep + tcat[1] + os.sep if sys.exists(LIB_FOLDER + f[3] +prepare_item(f[0]) + "-" + prepare_item(f[1]) + ".blend"): load_item(f[0],f[1],f[2],f[3],0) else: cf = Draw.PupMenu(LIB.capitalize() + " no longer seems to be in your library. Remove from Favourites?%t|Yes%x1|No%x2") if cf == 1: remove_fav(f[0]+","+f[1]+","+f[2]) elif c > 2 and Window.GetKeyQualifiers() == 48: f = FAVlist[c-4].split(",") remove_fav(f[0]+","+f[1]+","+f[2]) Draw.Redraw(1) # Info Button elif evt == 2: if SHOW_HELP == 1: SHOW_HELP = 3 Draw.Redraw() Window.RedrawAll() show_info() if SHOW_HELP == 3: SHOW_HELP = 1 Draw.Redraw(1) # Manage Button elif evt == 3: if SHOW_HELP == 1: SHOW_HELP = 5 Draw.Redraw() Window.RedrawAll() t = "Manage " + LIB.capitalize() + "%t|Rename%x1|Delete%x2|Add to favourites%x4|Move to category%x3|%l|Custom preview image...%x9|%l|Import " + LIB.capitalize() + "s...%x5|Export this " + LIB.capitalize() + "...%x6" if LIB != "pose" : t += "|%l|Open " + LIB + " .blend%x7" c = Draw.PupMenu(t) manage(c) if SHOW_HELP == 5: SHOW_HELP = 1 # Categories Menu elif evt == 12: LIC = MENU_LIC.val LICENSE = LICS[LIC-1] elif evt == 10: if MENU_CAT.val <= TOTAL_CATS and not Window.GetKeyQualifiers(): CURRENT_CAT = MENU_CAT.val Blender.Wc = MENU_CAT.val get_buffer() get_items() elif MENU_CAT.val <= TOTAL_CATS and Window.GetKeyQualifiers() == 48: cc = Draw.PupMenu("Delete this categorie?%t|Yes%x1|No%x2") if cc == 1: delete_categorie(MENU_CAT.val) elif MENU_CAT.val <= TOTAL_CATS and Window.GetKeyQualifiers() == 12: c = Draw.PupStrInput("New Name:", "", 25) if c: rename_categorie(MENU_SUBCAT.val,c,0) elif not Window.GetKeyQualifiers(): c = Draw.PupStrInput("Name:", "", 25) if c: add_new_categorie(c) Draw.Redraw(1) # Sub Categories Menu elif evt == 500: if MENU_SUBCAT.val <= TOTAL_SUBCATS and not Window.GetKeyQualifiers(): CURRENT_SUBCAT = MENU_SUBCAT.val get_buffer2() get_items() elif MENU_SUBCAT.val <= TOTAL_SUBCATS and Window.GetKeyQualifiers() == 48: c = Draw.PupMenu("Delete this sub categorie?%t|Yes%x1|No%x2") if c == 1: delete_subcat(MENU_SUBCAT.val) elif MENU_SUBCAT.val <= TOTAL_SUBCATS and Window.GetKeyQualifiers() == 12: c = Draw.PupStrInput("NewName:", "", 25) if c: rename_categorie(MENU_SUBCAT.val,c,1) elif not Window.GetKeyQualifiers(): c = Draw.PupStrInput("Name:", "", 25) if c: add_new_categorie(CATlist[CURRENT_CAT-1] + os.sep + c) Draw.Redraw(1) # Libraries Menu elif evt == 600: Blender.Wb=LIBS[MENU_LIB.val-1] CURRENT_LIB = MENU_LIB.val init(LIBS[MENU_LIB.val-1]) Draw.Redraw(1) # Items Menu elif evt == 11: CURRENT_ITEM = MENU_MAT.val update_thumb() Draw.Redraw(1) # Previous Item Buttom elif evt == 5: if CURRENT_ITEM != 1: CURRENT_ITEM = CURRENT_ITEM - 1 update_thumb() Draw.Redraw(1) # Next Item Buttom elif evt == 6: if CURRENT_ITEM != TOTAL_ITEMS: CURRENT_ITEM = CURRENT_ITEM + 1 update_thumb() Draw.Redraw(1) # Previous Category Buttom elif evt == 7: if CURRENT_CAT != 1: CURRENT_CAT = CURRENT_CAT - 1 Blender.Wc = CURRENT_CAT get_buffer() get_items() Draw.Redraw(1) # Next Category Buttom elif evt == 8: if CURRENT_CAT != TOTAL_CATS: CURRENT_CAT = CURRENT_CAT + 1 Blender.Wc = CURRENT_CAT get_buffer() get_items() Draw.Redraw(1) # Previous Category Buttom elif evt == 77: if CURRENT_SUBCAT != 1: CURRENT_SUBCAT = CURRENT_SUBCAT - 1 get_buffer2() get_items() Draw.Redraw(1) # Next Category Buttom elif evt == 88: if CURRENT_SUBCAT != TOTAL_SUBCATS: CURRENT_SUBCAT = CURRENT_SUBCAT + 1 get_buffer2() get_items() Draw.Redraw(1) # Prev Library Button elif evt == 777: if CURRENT_LIB != 1: init(LIBS[CURRENT_LIB -2]) Draw.Redraw(1) # Next Library Button elif evt == 888: if CURRENT_LIB != len(LIBS): init(LIBS[CURRENT_LIB]) Draw.Redraw(1) # Shape Menu for Material Library elif evt == 13: SHAPE = MENU_SHAPE.val Draw.Redraw(1) elif evt == 60: BATCH_MODE = 1 - BATCH_MODE Draw.Redraw(1) elif evt == 61: BATCH_ALL = 1 - BATCH_ALL Draw.Redraw(1) # Items Drop Down Menu elif evt == 14: scene_items() c = Draw.PupMenu(SCENE_ITEMSmenu) if c != -1 and LIB != "object" and LIB != "lamp": NAMEstr = SCENE_ITEMS[c-1] MENU_MAT_SCENE = c-1 elif c != -1 and (LIB == "object" or LIB == "lamp"): DefaultName = SCENE_ITEMS[c-1] MENU_MAT_SCENE = c-1 Draw.Redraw(1) # Set Name Label elif evt == 520: DefaultName = setNAMEstr.val Draw.Redraw(1) # Description Label elif evt == 21: DefaultDescription = DESCstr.val Draw.Redraw(1) # Author Label elif evt == 22: DefaultAuthorName = AUTHORstr.val Draw.Redraw(1) # E-mail Label elif evt == 23: DefaultAuthorEmail = EMAILstr.val Draw.Redraw(1) # Website Label elif evt == 24: DefaultAuthorWebPage = WEBPAGEstr.val Draw.Redraw(1) # Add stuff to the library Button elif evt == 31: BROWSING = 0 #if LIB == "object": # Blender.Redraw() # if ShowWarnings: # Draw.PupMenu("Select the "+ LIB.capitalize() +"s you want to save by|SELECTING THEM ON SCENE, then type a name for them.|You CAN select several " + LIB.capitalize() + "s.|Frame them with the active camera to get a nice preview.|Save the .blend first if you have unsaved changes,|it will be reopened after adding the " + LIB.capitalize() +".") #elif LIB == "lamp": # Blender.Redraw() # if ShowWarnings: # Draw.PupMenu("Select the "+ LIB.capitalize() +"s you want to save by|SELECTING THEM ON SCENE, then type a name for them.|You CAN select several " + LIB.capitalize() + "s.|Save the .blend first if you have unsaved changes,|it will be reopened after adding the " + LIB.capitalize() +".") #elif LIB == "pose": # Blender.Redraw() # if ShowWarnings: # Draw.PupMenu("Select the armature with the pose by|SELECTING IT ON SCENE, then type a name for the pose.|Frame the figure with the active camera to get a nice preview.|After adding the pose there is no need to save the .blend|You can continue working as usual.") #elif LIB == "logic": # Blender.Redraw() # if ShowWarnings: # Draw.PupMenu("Select the object with " + LIB.capitalize() + " Bricks you want to save by|CLICKING IN THE UPPER ARROW BUTTON.|You can only select one object from the list.|Save this .blend first if you have unsaved changes,|it will be reopened after adding the object.") #else: # Blender.Redraw() # if ShowWarnings: # Draw.PupMenu("Select the " + LIB.capitalize() + " you want to save by|CLICKING IN THE UPPER ARROW BUTTON.|You can only select one " + LIB.capitalize() +" from the list.|Save this .blend first if you have unsaved changes,|it will be reopened after adding the " + LIB.capitalize() +".") Draw.Redraw(1) # Cancel add form and go back to browse the library # Reset labels to they defaults elif evt == 33: DefaultAuthorName = "Unkown" DefaultAuthorEmail = "Not available" DefaultAuthorWebPage = "Not available" BROWSING = 1 Draw.Redraw(1) # Add the item to the library. elif evt == 34: if (NAMEstr != "" or DefaultName != "") or BATCH_MODE: if checkforview(): if LIB == "object" or LIB == "lamp": scene_items() if LIB == "material": save_mat(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "texture": save_tex(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "particle": save_particle(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "world": save_world(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "object": save_object(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE,obITEMS,DefaultName) elif LIB == "lamp": save_lamp(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE,obITEMS,DefaultName) elif LIB == "ipo": save_ipo(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "action": save_action(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "image": save_image(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "camera": save_camera(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "path": save_path(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "armature": save_armature(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "lattice": save_lattice(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "scene": save_scene(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) elif LIB == "pose": save_pose(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE,DefaultName) elif LIB == "logic": save_logic(CATlist[CURRENT_CAT-1],NAMEstr,DefaultAuthorName,DefaultAuthorEmail,DefaultAuthorWebPage,DefaultDescription,SHAPE,MENU_MAT_SCENE) else: Draw.PupMenu("No 3dView!%t|Please have at least one 3dView displayed along with the Script Window.") elif NAMEstr == "" and LIB != "object" and LIB != "lamp": Draw.PupMenu("No " + LIB.capitalize() +"!%t|Please select a " + LIB.capitalize() + " to add.") else: Draw.PupMenu("No set name!%t|Please type a Name if the upper NAME: field.") # Main Menu Button elif evt == 50: show_libs() Draw.Redraw(1) # Enable Raytrace Button elif evt == 51: RAY = 1 - RAY Draw.Redraw(1) # Enable Texface Button elif evt == 53: TEXFACE = 1 - TEXFACE Draw.Redraw(1) # Fill Button elif evt == 52: AUTHORstr.val = AuthorName EMAILstr.val = AuthorEmail WEBPAGEstr.val = AuthorWebPage DefaultAuthorName = AuthorName DefaultAuthorEmail = AuthorEmail DefaultAuthorWebPage = AuthorWebPage Draw.Redraw(1) # Search Button elif evt == 54: if SEARCHstr: #print "\nSearching for " + SEARCHstr + "!" ITEMlist =[] path.walk(LIB_FOLDER,search,SEARCHstr) if TOTAL_ITEMS > 0: CURRENT_ITEM = 1 update_thumb() else: Draw.PupMenu("Search error.%t|Please enter some text to search for.") Draw.Redraw(1) elif evt == 55: SEARCHstr = SearchString.val if SEARCHstr: ITEMlist =[] path.walk(LIB_FOLDER,search,SEARCHstr) if TOTAL_ITEMS > 0: CURRENT_ITEM = 1 update_thumb() else: Draw.PupMenu("Search error.%t|Please enter some text to search for.") elif evt == 57: ITEMlist =[] BROWSING = 1 get_buffer() get_items() Draw.Redraw(1) # First Setup FileSelector elif evt == 99: Window.FileSelector(first_setup, 'CHOOSE FOLDER') Draw.Redraw(1) elif evt == 101: SHOW_HELP = 1 - SHOW_HELP Draw.Redraw(1) def draw_square(x,y,w,h,r,g,b,a): BGL.glEnable(BGL.GL_BLEND) BGL.glBlendFunc(BGL.GL_SRC_ALPHA, BGL.GL_ONE_MINUS_SRC_ALPHA) BGL.glColor4f(r,g,b,a) BGL.glBegin(BGL.GL_POLYGON) BGL.glVertex2i(x, y) BGL.glVertex2i(x, y + h) BGL.glVertex2i(x + w, y + h) BGL.glVertex2i(x + w, y) BGL.glEnd() BGL.glDisable(BGL.GL_BLEND) def INTtoFLOAT(rgba): r = float(rgba[0] *10 /254) /10 g = float(rgba[1] *10 /254) /10 b = float(rgba[2] *10 /254) /10 a = float(rgba[3] *10 /254) /10 return [r,g,b,a] def gui(): global MENU_MAT, MENU_CAT, TOTAL_ITEMS, BROWSING, NAMEstr, MENU_MAT_SCENE, SCENE_ITEMSmenu, SHAPE, MENU_SHAPE, setNAMEstr, MENU_SUBCAT,MENU_LIC, TOTAL_SUBCATS, CURRENT_SUBCAT global AUTHORstr,DESCstr,EMAILstr, WEBPAGEstr,LIB, RAY, DefaultName, MENU_LIB, CURRENT_LIB, LIC, TEXFACE, TEXFACE global DefaultAuthorName, DefaultAuthorEmail, DefaultAuthorWebPage, SEARCHstr , SearchString global BATCH_MODE, BATCH_ALL, SHOW_HELP theme = Window.Theme.Get()[0] buts = theme.get('buts') r,g,b,a = INTtoFLOAT(buts.back) BGL.glClearColor(r+0.05,g+0.05,b+0.05,a) BGL.glClear(BGL.GL_COLOR_BUFFER_BIT) r,g,b,a = INTtoFLOAT(buts.panel) draw_square(5,5,170,340,r,g,b,a+0.1) r,g,b,a = INTtoFLOAT(buts.header) draw_square(5,340,170,16,r-0.1,g-0.1,b-0.1,a) if BROWSING != 2: r,g,b,a = INTtoFLOAT(buts.text_hi) BGL.glColor4f(r,g,b,a) BGL.glRasterPos2i(10,344) Draw.Text("Blender Library 1.3.3", "small") #Draw.PushButton("", 50, 165, 340, 5,5 , "Change Library") Draw.Toggle("?", 101,150,338, 15,15,SHOW_HELP , "Show Help") r,g,b,a = INTtoFLOAT(buts.text) BGL.glColor4f(r,g,b,a) # Buttons and thumbnail in the BROWSE LIBRARY form if BROWSING == 1: if SHOW_HELP == 5: text = "In this menu you will find options to manage your library items.||If you add an item to favourites it will be listed in the Load menu.||You can also import a custom preview image.||The last option will allow you to open the item's .blend, for editing or to redone the preview image." elif SHOW_HELP == 4: text = "From this menu you can load an item to the current .blend||Depending on the kind of item youīll get diferent loading options.||Below these options there is a list with all the items you have added to your favourites. Just click on one and it will be load, or CRTL-Click to remove it from the list." elif SHOW_HELP == 3: text = "This menu displays info about the current item.||If you CRTL-Click in item's name or description you can edit them.||If you click in author's website you will go to his webpage." elif SHOW_HELP == 2: text = "Use the first two options to import a single item or a folder full of items you may have downloaded from the net.||" text += "The third one will launch your web-browser and redirect you to Blender Stuff, where you can download lots of ready to use items.||" text += "With the fourth one you can run a search for certain matching items in the current library.||" text += "Click in Preferences... and you can enter your personal info to use the auto fill button in the Add Panel." elif SHOW_HELP == 1: text = "This is browsing mode. By using the three drop-down menus on top you can explore your library.||The first one is the library. The two below are categories and subcategories.|You can quickly navigate thru the content by using the arrow buttons on the right of the menus.||The button at the bottom will allow you to add content to the current library." if SHOW_HELP >= 1: paragraph([r,g,b],text,140,"small",182,316,14,1) staX, staY = 0,20 r,g,b,a = INTtoFLOAT(buts.text) BGL.glColor4f(r,g,b,a) if TOTAL_ITEMS > 0: # Write current item / total items. r,g,b,a = INTtoFLOAT(buts.header) draw_square(9,224,26,16,r,g,b,a) BGL.glColor3f(0,0,0) BGL.glRasterPos2i(9,229) Draw.Text(str(CURRENT_ITEM) + " / " + str(TOTAL_ITEMS), "tiny") if TOTAL_SUBCATS > 1: # Write current subcat / total subcats. r,g,b,a = INTtoFLOAT(buts.header) draw_square(9,274,26,16,r,g,b,a) BGL.glColor3f(0,0,0) BGL.glRasterPos2i(9,279) Draw.Text(str(CURRENT_SUBCAT) + " / " + str(TOTAL_SUBCATS), "tiny") if TOTAL_ITEMS > 0 : try: if IMG.getMaxXY() == [240,240]: Draw.Image(IMG, 10, 35,0.67,0.67) else: Draw.Image(IMG, 10, 35,1,1) except: print "No preview image for this item!" Draw.PushButton("Load", 1, staX + 10, staY + 180, 50,16 , "Load this " + LIB.capitalize()) Draw.PushButton("Info", 2, staX + 65, staY + 180, 50,16 , "Info about this " + LIB.capitalize()) Draw.PushButton("Manage", 3, staX + 120, staY + 180, 50,16 , "Manage your" + LIB.capitalize() +"s") MENU_MAT = Draw.Menu(ITEMmenu, 11, staX + 10, staY + 226, 120, 16, CURRENT_ITEM, "Select a " + LIB.capitalize()) if CURRENT_ITEM != 1 : Draw.PushButton("<", 5, staX + 134, staY + 226, 16,16 , "Prev " + LIB.capitalize()) if CURRENT_ITEM != TOTAL_ITEMS : Draw.PushButton(">", 6, staX + 150, staY + 226, 16,16 , "Next " + LIB.capitalize()) BGL.glRasterPos2i(staX + 38,staY + 208) if len(DESCS[CURRENT_ITEM-1]) < 23: if DESCS[CURRENT_ITEM-1][-1:] == "." or DESCS[CURRENT_ITEM-1][-1:] == "?": Draw.Text(DESCS[CURRENT_ITEM-1].replace("#",","),"small") else: Draw.Text(DESCS[CURRENT_ITEM-1].replace("#",",") +".","small") else: Draw.Text(DESCS[CURRENT_ITEM-1][:23].replace("#",",") + "...","small") MENU_CAT = Draw.Menu(CATmenu, 10, staX + 25, staY + 274, 105, 16, CURRENT_CAT, "Select a Category.") Draw.PushButton("<", 7, staX + 134, staY + 274, 16,16 , "Prev Category") Draw.PushButton(">", 8, staX + 150, staY + 274, 16,16 , "Next Category") MENU_SUBCAT = Draw.Menu(SUBCATmenu, 500, staX + 40, staY + 254, 90, 16, CURRENT_SUBCAT, "Select a Sub Category.") if CURRENT_SUBCAT != 1 :Draw.PushButton("<", 77, staX + 134, staY + 254, 16,16 , "Prev Sub Category") if CURRENT_SUBCAT != TOTAL_SUBCATS :Draw.PushButton(">", 88, staX + 150, staY + 254, 16,16 , "Next Sub Category") MENU_LIB = Draw.Menu(LIBmenu, 600, staX + 10, staY + 294, 120, 16, CURRENT_LIB, "Select a Library.") Draw.PushButton("<", 777, staX + 134, staY + 294, 16,16 , "Prev Library") Draw.PushButton(">", 888, staX + 150, staY + 294, 16,16 , "Next Library") Draw.PushButton("Add " + LIB.capitalize() + "s to Library", 31, 10, 12, 160,16 , "Add " + LIB.capitalize() + " to the Library") elif BROWSING == 0: staX, staY = 0,60 scene_items() get_licenses() # Labels and buttons for the ADD ITEM form if LIB != "lamp" and LIB != "object" and LIB != "pose": Draw.String("Name: ", 20, staX + 10, staY + 220, 135, 16, NAMEstr, 30, "The " + LIB.capitalize() + " Name") else: setNAMEstr = Draw.String("Set Name: ", 520, staX + 10, staY + 220, 135, 16, DefaultName, 30, "The " + LIB.capitalize() + " Set Name") DESCstr = Draw.String("Desc: ", 21, staX + 10, staY + 200, 155, 16, DefaultDescription, 90, "The " + LIB.capitalize() + " Description") AUTHORstr = Draw.String("Author: ", 22, staX + 10, staY + 160, 155, 16, DefaultAuthorName, 30, "The" + LIB.capitalize() + "Author Name") EMAILstr = Draw.String("Email: ", 23, staX + 10, staY + 140, 155, 16, DefaultAuthorEmail, 50, "The " + LIB.capitalize() + " Author E-mail") WEBPAGEstr= Draw.String("Site: ", 24, staX + 10, staY + 120, 155, 16, DefaultAuthorWebPage, 50, "The " + LIB.capitalize() + " Author Site") MENU_LIC = Draw.Menu(LICmenu, 12, staX + 80, staY + 95, 85, 16, LIC, "Select a License Text.") if LIB == "material": MENU_SHAPE = Draw.Menu("Plane%x1|Cube%x2|Sphere%x3", 13, staX + 90, staY + 70, 75, 16, SHAPE, "Select a Shape.") if LIB == "material" or LIB == "object" or LIB == "lamp": Draw.Toggle("Enable Ray", 51, staX + 70,staY + 50,95,16, RAY, "Enable raytracer for preview.") if LIB == "object": Draw.Toggle("Enable TEXFACE", 53, staX + 70,staY + 30,95,16, TEXFACE, "Enable TEXFACE for preview.") if LIB == "object" or LIB == "lamp": Draw.PushButton(">", 14, staX + 145, staY + 220, 20, 16, "Selected " + LIB.capitalize() + "s.") else: if LIB != "pose": Draw.PushButton(">", 14, staX + 145, staY + 220, 20, 16, "Select a " + LIB.capitalize() + ".") Draw.PushButton("Cancel", 33, 120, 15, 50,16 , "Cancel Operation") Draw.PushButton("Add "+ LIB.capitalize(), 34, 40, 15, 80,16 , "Adds the " + LIB.capitalize()) Draw.PushButton("Fill", 52, staX + 136, staY + 178, 28,15 , "Fill with your data") # Text for the ADD ITEM form BGL.glRasterPos2i(staX + 16,staY + 98) Draw.Text("License text:", "small") if LIB == "material": BGL.glRasterPos2i(staX + 16,staY + 73) Draw.Text("Preview shape:", "small") BGL.glRasterPos2i(staX + 10,staY + 242) Draw.Text("Requiered information :", "small") BGL.glRasterPos2i(staX + 10,staY + 182) Draw.Text("Optional information :", "small") BGL.glRasterPos2i(staX + 10,staY + 261) Draw.Text("Add " + LIB.capitalize()+ " to Library", "small") #Batch Mode if LIB == "material" or LIB == "texture": Draw.Toggle("Batch Mode", 60, staX + 10,staY + 10,85,16, BATCH_MODE, "Enable Batch Mode.") if BATCH_MODE: Draw.Toggle("Add All", 61, staX + 120,staY + 10,45,16, BATCH_ALL, "Add every " + LIB.capitalize() + " in this blend.") if SHOW_HELP: if LIB == "object": text = "Choose the "+ LIB.capitalize() +"s you want to save by SELECTING THEM ON SCENE, then type a name for them.|You CAN select several " + LIB.capitalize() + "s.|Frame them with the active camera to get a nice preview.||Save the .blend first if you have unsaved changes,|it will be reopened after adding the " + LIB.capitalize() +"." elif LIB == "lamp": text = "Choose the "+ LIB.capitalize() +"s you want to save by SELECTING THEM ON SCENE, then type a name for them.|You CAN select several " + LIB.capitalize() + "s.||Save the .blend first if you have unsaved changes,|it will be reopened after adding the " + LIB.capitalize() +"." elif LIB == "pose": text = "Choose the armature with the pose you want to save by SELECTING IT ON SCENE, then type a name for the pose in the label on the left.||Frame the figure with the active camera to get a nice preview.||After adding the pose there is no need to reopen the .blend, You can continue working as usual." elif LIB == "logic": text = "Select the object with " + LIB.capitalize() + " Bricks you want to save by CLICKING IN THE ARROW BUTTON on the left.|You can only select one object from the list.||Save this .blend first if you have unsaved changes, it will be reopened after adding the object." else: text = "Select the " + LIB.capitalize() + " you want to save by CLICKING IN THE ARROW BUTTON on the left.|You can select only one " + LIB.capitalize() +" from the list.||You can use the FILL button to auto enter your personal info.||If you wish to include a license text to bundle with the item, select it from the list.||Save this .blend first if you have unsaved changes, it will be reopened after adding the " + LIB.capitalize() +"." paragraph([r,g,b],text,140,"small",182,316,14,1) # Text to display in first run or lost library. elif BROWSING == 2: r,g,b,a = INTtoFLOAT(buts.text_hi) BGL.glColor4f(r,g,b,a) BGL.glRasterPos2i(10,310) Draw.Text("Welcome to Blender Library") #BGL.glColor3f(0.2,0.2,0.2) r,g,b,a = INTtoFLOAT(buts.text) BGL.glColor4f(r,g,b,a) BGL.glRasterPos2i(10,290) Draw.Text("It seems this is the first time") BGL.glRasterPos2i(10,275) Draw.Text("you run the script so please") BGL.glRasterPos2i(10,260) Draw.Text("choose a folder for the Lib.") BGL.glRasterPos2i(10,230) Draw.Text("The Library will be common") BGL.glRasterPos2i(10,215) Draw.Text("to all your Blender versions") BGL.glRasterPos2i(10,200) Draw.Text("installed on this system, so") BGL.glRasterPos2i(10,185) Draw.Text("if you 've already done the") BGL.glRasterPos2i(10,170) Draw.Text("setup in other installation") BGL.glRasterPos2i(10,155) Draw.Text("just point to the folder you") BGL.glRasterPos2i(10,140) Draw.Text("choosed that time.") BGL.glRasterPos2i(10,115) Draw.Text("Please choose a folder as") BGL.glRasterPos2i(10,100) Draw.Text("close as your root as posible") BGL.glRasterPos2i(10,85) Draw.Text("in order to avoid unexpected") BGL.glRasterPos2i(10,70) Draw.Text("errors due to some bugs in") BGL.glRasterPos2i(10,55) Draw.Text("bpython path handling.") Draw.PushButton("Choose Folder", 99, 70, 20, 95,20 , "Choose a folder for the library") elif BROWSING == 3: if SHOW_HELP: text = "By tiping some text in the Search label you can quickly search for matching items by both item's name and author'name.||If the search is succesfull this panel will display the items found just like in browsing mode." paragraph([r,g,b],text,140,"small",180,316,14,1) staX, staY = 0,80 BGL.glColor3f(0.1,0.1,0.1) BGL.glRasterPos2i(10,staY +235) Draw.Text("Search for " + LIB.capitalize() + "s","small") SearchString = Draw.String("Search: ", 55, staX + 10, staY + 214, 132, 16, SEARCHstr, 30, "Type your search text here") Draw.PushButton("Go", 54, staX + 146, staY + 214, 24,16 , "Perform the search") Draw.PushButton("Close Search", 57, 10, 12, 160,16 , "Close the search panel") if TOTAL_ITEMS > 0 : BGL.glRasterPos2i(10,staY +188) Draw.Text(str(TOTAL_ITEMS) + " " + LIB.capitalize() + "s found!","small") update_thumb() try: if IMG.getMaxXY() == [240,240]: Draw.Image(IMG, 10, 35,0.67,0.67) else: Draw.Image(IMG, 10, 35,1,1) except: print "No preview image for this item!" Draw.PushButton("Load", 1, staX + 10, staY + 120, 50,16 , "Load this " + LIB.capitalize()) Draw.PushButton("Info", 2, staX + 65, staY + 120, 50,16 , "Info about this " + LIB.capitalize()) MENU_MAT = Draw.Menu(ITEMmenu, 11, staX + 10, staY + 166, 120, 16, CURRENT_ITEM, "Select a " + LIB.capitalize()) if CURRENT_ITEM != 1 : Draw.PushButton("<", 5, staX + 134, staY + 166, 16,16 , "Prev " + LIB.capitalize()) if CURRENT_ITEM != TOTAL_ITEMS : Draw.PushButton(">", 6, staX + 150, staY + 166, 16,16 , "Next " + LIB.capitalize()) BGL.glRasterPos2i(staX + 12,staY + 148) if len(DESCS[CURRENT_ITEM-1]) < 33: if DESCS[CURRENT_ITEM-1][-1:] == ".": Draw.Text(DESCS[CURRENT_ITEM-1].replace("#",","),"small") else: Draw.Text(DESCS[CURRENT_ITEM-1].replace("#",",") +".","small") else: Draw.Text(DESCS[CURRENT_ITEM-1][:30].replace("#",",") + "...","small") else: BGL.glRasterPos2i(10,staY +188) Draw.Text("No " + LIB.capitalize() + "s found.","small") def paragraph(color,text,width,size,staX,staY,spacing,square): lines = [] i = 0 while i <= 1000: if i >= len(text): lines.append(text) break i += 1 length = Draw.GetStringWidth(text[:i],size) if text[i:i+1] == "|": lines.append(text[:i].lstrip(" ").rstrip("|")) if text[i+1:i+2] == "|": lines.append("") text = text[i:].lstrip("|") elif length > width: c = 0 while 1: if text[i-c-1:i-c] == " ": lines.append(text[:i-c].lstrip(" ")) text = text[i-c:] break else: c += 1 i = 0 h = len(lines)*spacing if square: draw_square(staX-10,staY - h+5,width+20,h+15,1,0.6,0,1) BGL.glColor3f(color[0],color[1],color[2]) c = 0 for l in lines: BGL.glRasterPos2i(staX,staY - (c*spacing)) Draw.Text(l,"small") c+= 1 def get_licenses(): global LICmenu, LICS LICS = ["None"] txts = Text.Get() LICmenu = "None" for t in txts: LICmenu += "|" + t.getName() LICS.append(t.getName()) def get_buffer(): global ITEMlist, SUBCATlist, SUBCATmenu, TOTAL_SUBCATS, CURRENT_SUBCAT, MENU_SUBCAT, SUB, CURRENT_CAT SUBCATlist=["."] ITEMlist =[] if CURRENT_CAT-1 > len(CATlist)-1: CURRENT_CAT = 1 items = os.listdir(LIB_FOLDER + CATlist[CURRENT_CAT-1]) for item in items: if item[-4:] == ".txt": txt = open(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + item,"r") t = txt.readline().rstrip("\n") txt.close() ITEMlist.append(t) for item in items: if path.isdir(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + item): SUBCATlist.append(item) SUBCATlist.sort() SUBCATmenu = "" for i in SUBCATlist: SUBCATmenu = SUBCATmenu + "|" + i TOTAL_SUBCATS = len(SUBCATlist) SUBCATmenu = SUBCATmenu + "| Add new..." CURRENT_SUBCAT = 1 SUB = "" def get_buffer2(): global ITEMlist, SUBCATlist, SUBCATmenu, TOTAL_SUBCATS, CURRENT_SUBCAT, MENU_SUBCAT, SUB ITEMlist =[] items = os.listdir(LIB_FOLDER + CATlist[CURRENT_CAT-1]+ os.sep + SUBCATlist[CURRENT_SUBCAT-1]) for item in items: if item[-4:] == ".txt": txt = open(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUBCATlist[CURRENT_SUBCAT-1] + os.sep+ item,"r") t = txt.readline().rstrip("\n") txt.close() ITEMlist.append(t) SUB = SUBCATlist[CURRENT_SUBCAT-1] + os.sep # These three deals with category management def get_categories(): global CATlist, CATmenu, TOTAL_CATS CATlist = [] files = os.listdir(LIB_FOLDER) for f in files: if path.isdir(LIB_FOLDER + f): CATlist.append(f) CATlist.sort() CATmenu = "" for i in CATlist: CATmenu = CATmenu + "|" + i TOTAL_CATS = len(CATlist) CATmenu = CATmenu + "| Add new..." def add_new_categorie(name): if not sys.exists(LIB_FOLDER + name): os.mkdir(LIB_FOLDER + name) else: Draw.PupMenu("Sorry%t|There is already a categorie with that name") get_categories() get_buffer() get_items() def delete_categorie(name): if sys.exists(LIB_FOLDER + CATlist[name-1]): if not os.listdir(LIB_FOLDER + CATlist[name-1]): os.rmdir(LIB_FOLDER + CATlist[name-1]) else: c = Draw.PupMenu("Categorie " + CATlist[name-1] + " is not empty. Delete anyway?%t|Yes%x1|No%x2") if c == 1: files = os.listdir(LIB_FOLDER + CATlist[name-1]) for f in files: if not path.isdir(LIB_FOLDER + CATlist[name-1] + os.sep + f): os.remove(LIB_FOLDER + CATlist[name-1] + os.sep + f) else: morefiles = os.listdir(LIB_FOLDER + CATlist[name-1] + os.sep + f) if not morefiles: os.rmdir(LIB_FOLDER + CATlist[name-1] + os.sep + f) else: for mf in morefiles: os.remove(LIB_FOLDER + CATlist[name-1] + os.sep + f + os.sep +mf) os.rmdir(LIB_FOLDER + CATlist[name-1]) else: Draw.PupMenu("Error%t|Categorie seems to be already deleted") CURRENT_CAT = 1 get_categories() def rename_categorie(cat,name,sub): if not sub: if sys.exists(LIB_FOLDER + CATlist[cat]): os.rename(LIB_FOLDER + CATlist[cat],LIB_FOLDER + name) else: Draw.PupMenu("Error%t|Categorie seems to be already deleted") else: if sys.exists(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUBCATlist[cat-1]): os.rename(LIB_FOLDER + CATlist[CURRENT_CAT-1]+ os.sep + SUBCATlist[cat-1] ,LIB_FOLDER + CATlist[CURRENT_CAT-1] +os.sep + name) else: Draw.PupMenu("Error%t|Sub Categorie seems to be already deleted") get_categories() get_buffer() get_items() def delete_subcat(name): global CURRENT_CAT if sys.exists(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUBCATlist[name-1]): if not os.listdir(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUBCATlist[name-1]): os.rmdir(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUBCATlist[name-1]) else: c = Draw.PupMenu("SubCategorie " + SUBCATlist[name-1] + "is not empty. Delete anyway?%t|Yes%x1|No%x2") if c == 1: files = os.listdir(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUBCATlist[name-1]) for f in files: os.remove(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUBCATlist[name-1]+ os.sep + f) os.rmdir(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUBCATlist[name-1]) else: Draw.PupMenu("Error%t|SUBCategorie seems to be already deleted") CURRENT_CAT = 1 get_categories() get_buffer() get_items() # This loads the current library favorites database into a list. # It also creates the favorites menu. # def get_favs(): global FAVlist, FAVmenu, TOTAL_FAVS try: txt = Text.Load(LIB_FAVS) FAVlist = txt.asLines() FAVlist.sort() Text.unlink (txt) FAVmenu = "" for i in FAVlist: b = i.replace(","," by ",1) b = b[0:b.find(",")] FAVmenu = FAVmenu + "|" + b TOTAL_FAVS = len(FAVlist) except: FAVlist = [] FAVmenu = "" # This gets all the items in the current library # and populates several lists with their info. # def get_items(): global CATlist, ITEMlist, ITEMmenu, ITEMS, AUTHORS, DESCS, MAILS, WEBPAGES, ONAMES, CURRENT_ITEM, TOTAL_ITEMS, ITEMCATS CURRENT_ITEM = 1 ITEMmenu = "" ITEMS = [] AUTHORS = [] DESCS = [] MAILS = [] WEBPAGES = [] ONAMES = [] ITEMCATS = [] for i in ITEMlist: row = i.split(",") ITEMmenu = ITEMmenu + "|" + row[1] ITEMCATS.append(row[0]) ITEMS.append(row[1]) AUTHORS.append(row[2]) MAILS.append(row[3]) WEBPAGES.append(row[4]) DESCS.append(row[5]) ONAMES.append(row[6]) TOTAL_ITEMS = len(ITEMS) if TOTAL_ITEMS > 0: CURRENT_ITEM = 1 update_thumb() def search(arg,dirname,names): global ITEMlist for name in names: if name[-3:] == "txt": if name[:-4].find(arg.lower()) != -1: txt = open(dirname + os.sep + name,"r") data = txt.readline().rstrip("\n") #.split(",") txt.close() ITEMlist.append(data) get_items() Draw.Redraw(1) # This updates the preview thumbnail as the user browses the library # def update_thumb(): global TOTAL_ITEMS,CURRENT_ITEM, IMG, ITEMS, AUTHORS, SUB if TOTAL_ITEMS > 0: # Prepare the names by stripping the undesirable characters. m = prepare_item(ITEMS[CURRENT_ITEM-1]) a = prepare_item(AUTHORS[CURRENT_ITEM-1]) if BROWSING == 1: try: IMG.setFilename(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB + m +"-"+ a +".jpg") except: IMG.setFilename(LIB_TH) # If we lack the image show an empty one else: try: IMG.setFilename(LIB_FOLDER + ITEMCATS[CURRENT_ITEM-1].replace("|",os.sep) + os.sep + m +"-"+ a +".jpg") except: IMG.setFilename(LIB_TH) # If we lack the image show an empty one IMG.reload() def change_description(old,new): folder = LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB file = prepare_item(ITEMS[CURRENT_ITEM-1]) + "-" + prepare_item(AUTHORS[CURRENT_ITEM-1]) + ".txt" if sys.exists(folder + file): txt = open(folder + file,"r") text = txt.readline().replace(old,new) txt.close txt = open(folder + file,"w") txt.write(text) txt.close() get_buffer() get_items() else: Draw.PupMenu("Sorry%t|Cant find the file for editing") # Show the info menu and launch webbrowser if the user clicks in website info. # def show_info(): c = Draw.PupMenu("About this "+ LIB.capitalize() + "%t|" + ITEMS[CURRENT_ITEM-1] + "%x6|"+ DESCS[CURRENT_ITEM-1].replace("#",",") +"%x4|%l|Author: " + AUTHORS[CURRENT_ITEM-1] + "%x5|E-mail: " + MAILS[CURRENT_ITEM-1]+ "%x2|Website: " + WEBPAGES[CURRENT_ITEM-1]+"%x3") if c == 2: print "Launching Mail Client" # Can be done? elif c == 3: if WEBPAGES[CURRENT_ITEM-1][:7] == "http:\\\\": webbrowser.open(WEBPAGES[CURRENT_ITEM-1]) # Launch webbrowser else: webbrowser.open("http:\\\\" + WEBPAGES[CURRENT_ITEM-1]) # Launch webbrowser elif c == 4: newDesc = Draw.PupStrInput("Desc: ", DESCS[CURRENT_ITEM-1].replace("#",",") , 100) if newDesc: change_description(DESCS[CURRENT_ITEM-1].replace("#",","),newDesc.replace(",","#")) elif c == 6: newName = Draw.PupStrInput("Name: ", ITEMS[CURRENT_ITEM-1] , 30) if newName: rename_item(ITEMS[CURRENT_ITEM-1],newName) def checkforview(): view = 0 for win in Window.GetScreenInfo(): if win["type"] == 1: view = 1 return view def load_pose(mat,author,oname,where): global LIB # Prepare the names. item = prepare_item(mat) author = prepare_item(author) txt = open(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB + item + "-" + author + ".blend","r") ob = Object.GetSelected()[0] if ob.getType() == "Armature": pose = ob.getPose() lines = txt.readlines() for line in lines: data = line.rstrip("\n").split(",") bone = pose.bones[data[0]] if bone: locVec = Mathutils.Vector(data[1],data[2],data[3]) bone.loc = locVec quat = Mathutils.Quaternion(data[4],data[5],data[6],data[7]) bone.quat = quat sizeVec = Mathutils.Vector(data[8],data[9],data[10]) bone.size = sizeVec else: menu = "Select a bone for bone: " + data[0] + "%t" bones = pose.bones.keys() bones.sort() for b in bones: menu += "|" + b c = Draw.PupMenu(menu) if c != -1: bone = pose.bones[bones[c-1]] locVec = Mathutils.Vector(data[1],data[2],data[3]) bone.loc = locVec quat = Mathutils.Quaternion(data[4],data[5],data[6],data[7]) bone.quat = quat sizeVec = Mathutils.Vector(data[8],data[9],data[10]) bone.size = sizeVec c = Draw.PupMenu("Insert pose keys for this frame?%t|Yes%x1|No%x2") if c == 1: if not ob.getAction(): action = Armature.NLA.NewAction("Action") action.setActive(ob) bones = pose.bones.values() for b in bones: b.insertKey(ob,Blender.Get("curframe"),Object.Pose.LOC) b.insertKey(ob,Blender.Get("curframe"),Object.Pose.ROT) b.insertKey(ob,Blender.Get("curframe"),Object.Pose.SIZE) txt.close() pose.update() ob.makeDisplayList() else: Draw.PupMenu("Error.%t|Please select an Armature") Blender.Redraw() # Generic function to load items for each particular library. # def load_item(mat,author,oname,where,cursor): global LIB # Prepare the names. item = prepare_item(mat) author = prepare_item(author) if BROWSING != 1: where = os.sep + ITEMCATS[CURRENT_ITEM-1].replace("|",os.sep) + os.sep if where: Library.Open(LIB_FOLDER + where + item + "-" + author + ".blend") # Open Library. else: Library.Open(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB + item + "-" + author + ".blend") # Open Library. Library.Load("License.txt", "Text", 0) if LIB == "material": # Standard load procedure. Single Item. Library.Load(oname, LIB.capitalize(), 0) print oname if oname != mat: tren = Material.Get(oname) tren.setName(mat) elif LIB == "world": # Standard load procedure. Single Item. Library.Load(oname, LIB.capitalize(), 0) if oname != mat: tren = World.Get(oname) tren.setName(mat) elif LIB == "scene": # Standard load procedure. Single Item. Library.Load(oname, LIB.capitalize(), 0) elif LIB == "object": # Load every object except the ones with the noLoad name. for obname in Library.Datablocks('Object'): if obname[:6] != "noLoad": if cursor: ready = 0 while ready < 100: try: if ready == 0: tempOb = Object.Get(obname) else: if ready > 9: tempOb = Object.Get(obname + ".0" + str(ready)) else: tempOb = Object.Get(obname + ".00" + str(ready)) ready += 1 except: break Library.Load(obname, 'Object', 1) if ready != 0 and ready < 10: ob = Object.Get(obname + ".00" + str(ready)) ob.setLocation(Window.GetCursorPos()) elif ready != 0 and ready >= 10: ob = Object.Get(obname + ".0" + str(ready)) ob.setLocation(Window.GetCursorPos()) elif ready == 0: ob = Object.Get(obname) ob.setLocation(Window.GetCursorPos()) else: Library.Load(obname, 'Object', 1) scn = Scene.GetCurrent() scn.update() obs = scn.getChildren() for ob in obs: ob.makeDisplayList() elif LIB == "texture": # Standard load procedure. Single Item. Library.Load(oname, LIB.capitalize(), 0) if oname != mat: tren = Texture.Get(oname) tren.setName(mat) elif LIB == "ipo": # Standard load procedure. Single Item. Library.Load(oname, LIB.capitalize(), 0) if oname != mat: tren = Ipo.Get(oname) tren.setName(mat) elif LIB == "action": # Standard load procedure. Single Item. Library.Load(oname, LIB.capitalize(), 0) # NLA is somehow non standard module. Need different code here. #if oname != mat: # tren = Armature.NLA.Get(oname) # tren.setName(mat) elif LIB == "path": # Standard load procedure. Single Item. Library.Load(oname, "Object", 0) if oname != mat: tren = Object.Get(oname) tren.setName(mat) elif LIB == "logic": # Standard load procedure. Single Item. Library.Load(oname, "Object", 0) if oname != mat: tren = Object.Get(oname) tren.setName(mat) elif LIB == "armature": # Standard load procedure. Single Item. Library.Load(oname, "Object", 0) if oname != mat: tren = Object.Get(oname) tren.setName(mat) elif LIB == "lattice": # Standard load procedure. Single Item. Library.Load(oname, "Object", 0) if oname != mat: tren = Object.Get(oname) tren.setName(mat) elif LIB == "particle": # Standard load procedure. Single Item. Library.Load(oname, "Object", 0) for obname in Library.Datablocks('Object'): if obname[:len(oname)+1] == oname + ".": Library.Load(obname, 'Object', 0) elif LIB == "lamp": # Special load procedure. Multiple Items. for obname in Library.Datablocks('Object'): if obname[:7] != "library" and obname != "Mesh": Library.Load(obname, 'Object', 0) elif LIB == "camera": # Standard load procedure. Single Item. Library.Load(oname, "Object", 0) if oname != mat: tren = Object.Get(oname) tren.setName(mat) try: # Try to load the empty if camera is tracking one. Library.Load(oname + ".Track", "Object", 0) if oname != mat: tren = Object.Get(oname + ".Track") tren.setName(mat + ".Track") except: print "No Empty to load!" try: # Try to load the path if camera is following one. Library.Load(oname + ".Path", "Object", 0) if oname != mat: tren = Object.Get(oname + ".Path") tren.setName(mat + ".Path") except: print "No Follow Path to load!" Library.Update() Library.Close() Draw.PupMenu( "Loaded into this .blend!%t|" + LIB.capitalize() + " " + mat + " by " + author) try: LICtext = Text.Get("License.txt") LICtext.setName(mat + " License.txt") Draw.PupMenu("This " + LIB.capitalize() + " comes with License text.%t|Check for \"" + mat + " Licence.txt\" in the text window") except: pass Window.Redraw(-1) # Appends info to the single text file each item has. # def append_database(cat,mat,author,email,webpage,description,oname): cat = CATlist[CURRENT_CAT-1] + os.sep + SUBCATlist[CURRENT_SUBCAT-1] txt = open(LIB_FOLDER + cat + os.sep + prepare_item(mat) + "-" + prepare_item(author) + ".txt","w") txt.write(cat.replace(os.sep,"|") + ",") txt.write(mat + ",") txt.write(author + ",") txt.write(email + ",") txt.write(webpage + ",") txt.write(description.replace(",","#") + ",") txt.write(oname + "\n") txt.close() # Set default render options for the renderer preview image. # def prepare_scene(frame): global newscn, rc, RAY rc = newscn.getRenderingContext() if LIB == "pose" or LIB == "scene": oldPath = rc.getRenderPath() oldSta = rc.startFrame() oldEnd = rc.endFrame() oldSizeX = rc.imageSizeX() oldSizeY = rc.imageSizeY() rc.setRenderPath(LIB_FOLDER) rc.imageSizeX(160) rc.imageSizeY(160) if LIB != "pose" and LIB != "scene": rc.enableOversampling(1) rc.enableRayTracing(RAY) rc.enableShadow(1) rc.enableEnvironmentMap(1) rc.enableUnifiedRenderer(1) rc.setRenderWinSize(100) rc.enableExtensions(0) rc.setImageType(Scene.Render.JPEG) rc.quality(95) rc.startFrame(frame) rc.endFrame(frame) Blender.Set("curframe",frame) rc.enableSky() rc.enableRGBColor() Scene.Render.EnableDispWin() rc.renderAnim() Scene.Render.CloseRenderWindow() if LIB == "pose" or LIB == "scene": rc.startFrame(oldSta) rc.endFrame(oldEnd) rc.setRenderPath(oldPath) rc.imageSizeX(oldSizeX) rc.imageSizeY(oldSizeY) # This takes care of the final part of the adding process # It unlinks the unnecesary stuff and also renames the rendered # preview image to its proper name. # It unlinks all Text files too. # def export_files(mat,author,cat): global scns, CURRENT_CAT,CATlist, CURRENT_SUBCAT,SUBCATlist, POSEDATA cat = CATlist[CURRENT_CAT-1] + os.sep + SUBCATlist[CURRENT_SUBCAT-1] count = 0 mat = prepare_item(mat) author = prepare_item(author) if LIB != "pose": f = Blender.Get("curframe") else: f = 1 if len(str(f)) == 1: frame = "000" + str(f) elif len(str(f)) == 2: frame = "00" + str(f) elif len(str(f)) == 3: frame = "0" + str(f) if LIB != "pose" and LIB != "scene": FILE_ORIG = rc.getRenderPath() + frame else: FILE_ORIG = LIB_FOLDER + frame FILE_DEST = LIB_FOLDER + cat + os.sep + mat + "-" + author print FILE_ORIG if not sys.exists(FILE_DEST + ".jpg"): os.rename(FILE_ORIG,FILE_DEST + ".jpg") else: free = 1 while free == 1: count = count + 1 free = sys.exists(LIB_FOLDER + cat + os.sep + mat + ".00" + str(count) + "-" + author + ".jpg") FILE_DEST = LIB_FOLDER + cat + os.sep + mat + ".00" + str(count) + "-" + author os.rename(FILE_ORIG,FILE_DEST + ".jpg") # If Object Library, unlink the possible remaining scenes. if LIB != "object" and LIB != "scene" and LIB != "pose": if not BATCH_MODE: for scn in scns: Scene.Unlink(scn) # Unlink all texts before saving. if LIB != "pose" and LIB != "scene": texts = Text.Get() for text in texts: if text.getName() != LICENSE: Text.unlink(text) try: texts = Text.Get()[0] texts.setName("License.txt") except: pass else: try: texts = Text.Get() for text in texts: if text.getName() == LICENSE: text.setName("License.txt") except: pass # Save the itemīs blend. if LIB != "pose": FOLDER = sys.dirname(LIB_FOLDER.rstrip(os.sep)) + os.sep try: Blender.Save(FOLDER + "l.blend") if count: os.rename(FOLDER + "l.blend",LIB_FOLDER + cat + os.sep + mat + ".00" + str(count) + "-" + author + ".blend") #Blender.Save(LIB_FOLDER + cat + os.sep + mat + ".00" + str(count) + "-" + author + ".blend") else: os.rename(FOLDER + "l.blend",LIB_FOLDER + cat + os.sep + mat + "-" + author + ".blend") #Blender.Save(LIB_FOLDER + cat + os.sep + mat + "-" + author + ".blend") except: Draw.PupMenu("Path to the library too long!%t|Please move your library to a shorter path.") else: if count: text = open(LIB_FOLDER + cat + os.sep + mat + ".00" + str(count) + "-" + author + ".blend","w") else: text = open(LIB_FOLDER + cat + os.sep + mat + "-" + author + ".blend","w") text.write(POSEDATA) text.close() Blender.Wc = CURRENT_CAT return count # This reloads the blend at the end of the adding process. # If not done this way, when the script runs again it will show error: # "Draw is not defined" :/ # This also explain why in the gui events there are so many Draw.Redraw() # scattered all the way. Itīs needed that way to avoid the error. # def reload_blend(): if ShowWarnings: c = Draw.PupMenu("This .blend needs to be reopened now%t|Ok, reopen .blend%x1|NOOOO, I have unsaved changes going on%x2") else: c = 1 if c == 1: Draw.Exit() Blender.Load(FILE_NAME) else: Draw.Exit() def save_mat(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns scns = Scene.Get() newscn = Scene.New("libraryScene") newscn.makeCurrent() if shape == 1: add_plane_tex() oblib = "libraryPlane" elif shape == 2: add_cube(1,1,1,"libraryCube") oblib = "libraryCube" elif shape == 3: add_sphere(1,1,1,"librarySphere") oblib = "librarySphere" add_lamps() add_camera_tex() add_world_darkgrey() wrld = World.Get("libraryWorld") wrld.setCurrent() newOb = Object.Get(oblib) if oblib == "librarySphere": newOb.setSize(1.8, 1.8, 1.8) newOb.setLocation(0.0, 0.0, -0.26549938321113586) elif oblib == "libraryCube": newOb.setSize(1.6, 1.6, 1.6) newOb.setLocation(0.0, 0.0, 0.2) if not BATCH_MODE and not BATCH_ALL: newOb.setMaterials([Material.Get(mat)]) newOb.colbits = 0x01 # Set OB materials. check_pack(mat) Blender.Redraw() prepare_scene(1) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) else: mats = Material.Get() for m in mats: mat = m.getName() newOb.setMaterials([Material.Get(mat)]) newOb.colbits = 0x01 # Set OB materials. check_pack(mat) Blender.Redraw() prepare_scene(1) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) reload_blend() def check_pack(mat): # Check if materialīs textures uses image textures. If so, pack them. texs = Material.Get(mat).getTextures() if texs: for t in texs: if t != None: if t.tex.getType() == "Image" and PACK: img = t.tex.getImage() if not img.packed: #print "PACKING IMAGE!" img.pack() def save_particle(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns scns = Scene.Get() obs = Object.Get() newscn = Scene.New("libraryScene") newscn.makeCurrent() add_lamps() add_camera_tex() add_world_grey() wrld = World.Get("libraryWorld") wrld.setCurrent() partOb = Object.Get(mat) newscn.link(partOb) partOb.layers = [1] for ob in obs: if ob.getName()[:len(mat)+1] == mat + ".": newscn.link(ob) Blender.Redraw() p = Effect.Get(partOb.getName(),0) frm = int((p.getEndTime() / 2) + p.getStartTime()) prepare_scene(frm) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) reload_blend() def save_lattice(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns scns = Scene.Get() newscn = Scene.New("libraryScene") newscn.makeCurrent() add_camera_tex() add_world_grey() wrld = World.Get("libraryWorld") wrld.setCurrent() latOb = Object.Get(mat) newscn.link(latOb) latOb.setLocation(0,0,0) latOb.layers = [1] me=NMesh.New() lat = latOb.getData() for p in range(lat.latSize): x,y,z = lat.getPoint(p) me.verts.append(NMesh.Vert(x,y,z)) me.update() NMesh.PutRaw(me,"libraryLattice") ob = Object.Get("Mesh") ob.setName("libraryLattice") ob.setSize(latOb.getSize()) add_mat_halo() tmat = Material.Get("libraryHalo") ob.colbits = 0x01 ob.setMaterials([tmat]) Blender.Redraw() prepare_scene(1) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) reload_blend() def save_tex(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns scns = Scene.Get() newscn = Scene.New("libraryScene") newscn.makeCurrent() add_camera_tex() add_plane_tex() add_mat_tex() tmat = Material.Get("libraryMaterial") tmat.setTexture(0, Texture.Get(mat)) ob= Object.Get("libraryPlane") ob.colbits = 0x01 ob.setMaterials([tmat]) tex = Texture.Get(mat) if tex.getType() == "Image" and PACK: img = tex.getImage() if not img.packed: #print "PACKING IMAGE!" img.pack() Blender.Redraw() prepare_scene(1) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) reload_blend() def save_armature(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns, DefaultName scn = Scene.GetCurrent() cam = scn.getCurrentCamera() ob = Object.Get(mat) scns = Scene.Get() newscn = Scene.New("libraryScene") newscn.makeCurrent() add_mat_shadeless() add_mat_wire() add_world_grey() wrld = World.Get("libraryWorld") wrld.setCurrent() newscn.link(cam) newscn.link(ob) arm = Armature.Get(ob.getData(1)) for bone in arm.bones.items(): add_cube(0.1,0.1,0.1,bone[0]) ob = Object.Get(bone[0]) me = ob.getData() head = bone[1].head["ARMATURESPACE"] tail = bone[1].tail["ARMATURESPACE"] count = 1 for v in me.verts: if count == 1: v.co[0] = head[0] + 0.1 #x v.co[1] = -head[2] + 0.1 #y v.co[2] = head[1] #z elif count == 2: v.co[0] = head[0] - 0.1 #x v.co[1] = -head[2] +0.1 #y v.co[2] = head[1] #z elif count == 3: v.co[0] = head[0] - 0.1 #x v.co[1] = -head[2] - 0.1 #y v.co[2] = head[1] #z elif count == 4: v.co[0] = head[0] + 0.1 #x v.co[1] = -head[2] - 0.1 #y v.co[2] = head[1] #z elif count > 4: v.co[0] = tail[0] v.co[1] = -tail[2] v.co[2] = tail[1] count += 1 me.update() tmat = Material.Get("libraryWire") ob.setMaterials([tmat]) ob.colbits = 0x01 Blender.Redraw() prepare_scene(1) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) reload_blend() def save_camera(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns, DefaultName cam = Object.Get(mat) cam.layers = [1] try: track = Object.Get(mat +".Track") track.layers = [1] tracking = 1 except: tracking = 0 try: follow = Object.Get(mat +".Path") follow.layers = [1] following = 1 except: following = 0 scns = Scene.Get() newscn = Scene.New("libraryScene") newscn.makeCurrent() add_mat_shadeless() add_mat_wire() add_plane_view() add_world_grey() wrld = World.Get("libraryWorld") wrld.setCurrent() add_axes() newscn.link(cam) if tracking: newscn.link(track) if following: newscn.link(follow) Blender.Redraw() prepare_scene(1) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) reload_blend() # We lack bPtyhon ability to set dupliframes ON :( # def save_ipo(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns scns = Scene.Get() newscn = Scene.New("libraryScene") newscn.makeCurrent() add_mat_shadeless() add_mat_wire() add_cube(1,1,1,"libraryCube") add_plane_view() add_camera_ipo() add_world_grey() add_axes() wrld = World.Get("libraryWorld") wrld.setCurrent() newOb = Object.Get("libraryCube") newM = Material.Get("libraryWire") newIpo = Ipo.Get(mat) newOb.setIpo(newIpo) newOb.setMaterials([newM]) newOb.colbits = 0x01 Blender.Redraw() prepare_scene(1) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) reload_blend() def save_logic(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns scns = Scene.Get() newscn = Scene.New("libraryScene") newscn.makeCurrent() add_mat_wire() add_plane_view() add_camera_ipo() add_world_grey() wrld = World.Get("libraryWorld") wrld.setCurrent() ob = Object.Get(mat) newscn.link(ob) ob.layers = [1] Blender.Redraw() prepare_scene(1) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) reload_blend() def save_path(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns scns = Scene.Get() newscn = Scene.New("libraryScene") newscn.makeCurrent() ob = Object.Get(mat) ob.layers = [1] cob = ob.getData() newscn.link(ob) add_camera_ipo() add_mat_wire() add_mat_shadeless() add_plane_view() add_curvecircle() add_axes() add_world_grey() wrld = World.Get("libraryWorld") wrld.setCurrent() bO = Object.Get("libraryCircle") cob.setBevOb(bO) ob.makeDisplayList() newM = Material.Get("libraryShadeless") ob.setMaterials([newM]) ob.colbits = 0x01 Blender.Redraw() prepare_scene(1) cob.setBevOb(None) ob.setMaterials([]) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) reload_blend() def save_action(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns, POSEDATA, BROWSING scns = Scene.Get() scn = Scene.GetCurrent() actions = Armature.NLA.GetActions() for a in actions: if a == mat: action = actions[a] add_world_grey() wrld = World.Get("libraryWorld") wrld.setCurrent() newscn = scn prepare_scene(1) newscn = Scene.New("libraryScene") newscn.makeCurrent() newOb = Object.New("Armature","libraryArmature") newscn.link(newOb) scn.update() action.setActive(newOb) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) reload_blend() def save_pose(cat,mat,author,email,webpage,description,shape,newmat,setName): global newscn, rc, scns, POSEDATA, BROWSING mat = setName scn = Scene.GetCurrent() oldWrld = World.GetCurrent() add_world_grey() wrld = World.Get("libraryWorld") wrld.setCurrent() ob = Object.GetSelected()[0] pose = ob.getPose() poseText = "" for b in pose.bones.values(): poseText += b.name + "," poseText += str(b.loc[0]) + "," +str(b.loc[1]) + "," + str(b.loc[2]) + "," poseText += str(b.quat[0]) + "," + str(b.quat[1]) + "," +str(b.quat[2]) + "," + str(b.quat[3]) + "," poseText += str(b.size[0]) + "," +str(b.size[1]) + "," + str(b.size[2]) + "\n" Blender.Redraw() newscn = scn prepare_scene(1) POSEDATA = poseText free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,setName,author,email,webpage,description,omat) BROWSING = 1 oldWrld.setCurrent() get_buffer() get_items() def save_lamp(cat,mat,author,email,webpage,description,shape,newmat,lamps,setName): global newscn, rc, scns, DefaultName scns = Scene.Get() newscn = Scene.New("libraryScene") newscn.makeCurrent() add_camera_lamp() add_world_grey() add_sphere(0.5,0.5,0.5,"librarySphere") ob = Object.Get("librarySphere") ob.setLocation(0,0,0.5) add_cube(0.1,0.1,0.1,"libraryCube") ob = Object.Get("libraryCube") ob.setLocation(2,-1,1) add_cone(0.4,0.4,0.4,"libraryCone") ob = Object.Get("libraryCone") ob.setLocation(-1.4,-2,1) wrld = World.Get("libraryWorld") wrld.setCurrent() add_mat_wire() add_plane_view() add_plane_big() for lamp in lamps: newscn.link(lamp) Blender.Redraw() prepare_scene(1) free = export_files(setName,author,cat) if free: setName = setName + ".00" + str(free) append_database(cat,setName,author,email,webpage,description,setName) reload_blend() def save_scene(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns, PACK, TEXFACE, RAY scn = Scene.Get(mat) scn.makeCurrent() newscn = scn prepare_scene(Blender.Get("curframe")) free = export_files(mat,author,cat) if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,mat) reload_blend() def save_object(cat,mat,author,email,webpage,description,shape,newmat,objs,setName): global newscn, rc, scns, PACK, TEXFACE, RAY scn = Scene.GetCurrent() add_world_grey() wrld = World.Get("libraryWorld") wrld.setCurrent() obs = Object.Get() for ob in obs: if ob.isSelected() == 0 and ob.getType() != "Lamp" and ob.getType() != "Camera": ob.setName("noLoad") scn.unlink(ob) elif ob.isSelected() and (ob.getType() == "Mesh" or ob.getType() == "Curve"): if PACK: pmats= ob.getMaterials() if not pmats: pmats= ob.getData().getMaterials() for m in pmats: if TEXFACE: #print "MATERIAL FLAGS:" curmodes = m.getMode() m.setMode("TexFace") ptexs = m.getTextures() for t in ptexs: if t: if t.tex.getType() == "Image" and PACK: img = t.tex.getImage() if not img.packed: #print "PACKING IMAGE!" img.pack() Blender.Redraw() newscn = scn prepare_scene(1) if PACK: for m in pmats: if TEXFACE: m.setMode(curmodes) for ob in obs: if ob.getType() == "Lamp" or ob.getType() == "Camera": ob.setName("noLoad") ob.layers = [1] else: ob.layers = [1] if setName == "": setName = Object.GetSelected()[0].getName() Blender.Redraw() scn.update(1) free = export_files(setName,author,cat) if free: setName = setName + ".00" + str(free) append_database(cat,setName,author,email,webpage,description,setName) reload_blend() def save_world(cat,mat,author,email,webpage,description,shape,newmat): global newscn, rc, scns scns = Scene.Get() cam = scns[0].getCurrentCamera() newscn = Scene.New("libraryScene") newscn.makeCurrent() newscn.link(cam) wrld = World.Get(mat) wrld.setCurrent() newscn.update(1) Blender.Redraw() prepare_scene(1) free = export_files(mat,author,cat) omat = mat if free: mat = mat + ".00" + str(free) append_database(cat,mat,author,email,webpage,description,omat) reload_blend() # This makes the list of items of the desired type when you add something. # def scene_items(): global SCENE_ITEMS,SCENE_ITEMSmenu, obITEMS, LIB SCENE_ITEMS = [] if LIB == "material": mText = LIB.capitalize() + "s in this .blend%t|" obITEMS = Material.Get() for m in obITEMS: mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "texture": mText = LIB.capitalize() + "s in this .blend%t|" obITEMS = Texture.Get() for m in obITEMS: mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "world": mText = LIB.capitalize() + "s in this .blend%t|" obITEMS = World.Get() for m in obITEMS: mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "particle": mText = LIB.capitalize() + "s in this .blend%t|" obITEMS = Object.Get() for m in obITEMS: if m.getType() == "Mesh" and m.effects: mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "logic": mText = "Objects in this .blend%t|" obITEMS = Object.Get() for m in obITEMS: mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "object": mText = "Selected " + LIB.capitalize() + "s%t|" obITEMS = Object.GetSelected() for m in obITEMS: if m.getType() == "Mesh" or m.getType() == "Curve" or m.getType() == "Armature": mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "lamp": mText = "Selected " + LIB.capitalize() + "s%t|" obITEMS = Object.GetSelected() for m in obITEMS: if m.getType() == "Lamp": mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "ipo": mText = LIB.capitalize() + "s in this .blend%t|" obITEMS = Ipo.Get() for m in obITEMS: mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "action": mText = LIB.capitalize() + "s in this .blend%t|" obITEMS = Armature.NLA.GetActions() for m in obITEMS: mText = mText + "|" + m #.getName() SCENE_ITEMS.append(m) SCENE_ITEMSmenu = mText elif LIB == "camera": mText = LIB.capitalize() + "s in this .blend%t|" obITEMS = Object.Get() for m in obITEMS: if m.getType() == "Camera": mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "armature": mText = LIB.capitalize() + "s in this .blend%t|" obITEMS = Object.Get() for m in obITEMS: if m.getType() == "Armature": mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "pose": mText = "Armatures in this .blend%t|" obITEMS = Object.Get() for m in obITEMS: if m.getType() == "Armature": mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "path": mText = LIB.capitalize() + "s in this .blend%t|" obITEMS = Object.Get() for m in obITEMS: if m.getType() == "Curve": mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB == "scene": mText = LIB.capitalize() + "s in this .blend%t|" obITEMS = Scene.Get() for m in obITEMS: mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText elif LIB== "lattice": mText = LIB.capitalize() + "s in this .blend%t|" obITEMS = Object.Get() for m in obITEMS: if m.getType() == "Lattice": mText = mText + "|" + m.getName() SCENE_ITEMS.append(m.getName()) SCENE_ITEMSmenu = mText def manage(c): global LIB # Rename Item if c == 1: m = Draw.PupStrInput("New Name:", ITEMS[CURRENT_ITEM-1] , 30) if m: rename_item(ITEMS[CURRENT_ITEM-1],m) # Delete Item elif c == 2: m = Draw.PupMenu("Delete " + LIB + " " + ITEMS[CURRENT_ITEM-1] +"?%t|Yes|No") if m == 1: delete_item(ITEMS[CURRENT_ITEM-1]) # Move to Category elif c == 3: m = Draw.PupMenu("Choose a category%t|" + CATmenu[:-1]) if m != -1: if m <= TOTAL_CATS: subdirs = os.listdir(LIB_FOLDER + CATlist[m-1]) subs = ["."] submenu ="." for s in subdirs: if path.isdir(LIB_FOLDER + CATlist[m-1] + os.sep + s): subs.append(s) submenu += "|" + s if submenu != ".": where = Draw.PupMenu("Choose a sub category%t|" + submenu) if where == 1: move_item(CATlist[m-1]) elif where != -1: move_item(CATlist[m-1] + os.sep + subs[where-1]) else: move_item(CATlist[m-1]) # Add to favorites elif c == 4: if SUB: add_fav(ITEMS[CURRENT_ITEM-1] + "," + AUTHORS[CURRENT_ITEM-1]+ "," + ONAMES[CURRENT_ITEM-1] + "," + CATlist[CURRENT_CAT-1] + "|" + SUB[:-1]) else: add_fav(ITEMS[CURRENT_ITEM-1] + "," + AUTHORS[CURRENT_ITEM-1]+ "," + ONAMES[CURRENT_ITEM-1] + "," + CATlist[CURRENT_CAT-1]) # Import Item elif c == 5: Window.FileSelector (import_item, 'CHOOSE FILE') # Export Item elif c == 6: Window.FileSelector (export_item, 'CHOOSE FOLDER') # Import custom preview image elif c == 9: if ShowWarnings: Draw.PupMenu("Please select a custom image for the preview.%t|It has to be a 160 x 160 pixels JPG image.") Window.FileSelector (custom_preview, 'CHOOSE FILE') Draw.Redraw(1) # Open Itemīs .blend file if c == 7: open_item(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB + prepare_item(ITEMS[CURRENT_ITEM-1]) + "-" + prepare_item(AUTHORS[CURRENT_ITEM-1]) +".blend") # This deletes an item from the database # and also remove its files from disk. # def delete_item(mat): global ITEMlist, SUB item = prepare_item(mat) author = prepare_item(AUTHORS[CURRENT_ITEM-1]) filename = LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB + item + "-" + author if sys.exists(filename + ".txt"): os.remove(filename + ".txt") if sys.exists(filename + ".blend"): os.remove(filename + ".blend") if sys.exists(filename + ".jpg"): os.remove(filename + ".jpg") get_buffer() get_items() # This renames an item in the database # and also in it .txt backup data. # def rename_item(mat,newname): filename = LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB + prepare_item(mat) + "-" + prepare_item(AUTHORS[CURRENT_ITEM-1]) newfilename = LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB + prepare_item(newname) + "-" + prepare_item(AUTHORS[CURRENT_ITEM-1]) if not sys.exists(newfilename + ".txt"): os.rename(filename +".jpg", newfilename +".jpg") os.rename(filename +".blend", newfilename +".blend") txt = open(filename +".txt","r") temptext = txt.readline().replace(mat,newname,1) txt.close txt = open(filename +".txt","w") txt.write(temptext + "\n") txt.close() os.rename(filename +".txt", newfilename +".txt") else: Draw.PupMenu("Sorry%t|There is already a " + LIB.capitalize() + " with that name") get_buffer() get_items() # Move item to other category # def move_item(cat): global ITEMlist filename = LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB + prepare_item(ITEMS[CURRENT_ITEM-1]) + "-" + prepare_item(AUTHORS[CURRENT_ITEM-1]) destname = LIB_FOLDER + cat + os.sep + prepare_item(ITEMS[CURRENT_ITEM-1]) + "-" + prepare_item(AUTHORS[CURRENT_ITEM-1]) if not sys.exists(destname + ".txt"): os.rename(filename + ".txt", destname + ".txt") os.rename(filename + ".jpg", destname + ".jpg") os.rename(filename + ".blend", destname + ".blend") txt = open(destname +".txt","r") tData = txt.readline().split(",") txt.close try: cat.index(os.sep) tData[0] = cat.replace("\\","|") except: tData[0] = cat txt = open(destname +".txt","w") txt.write(tData[0] + "," + tData[1] + "," + tData[2] + "," + tData[3] + "," + tData[4] + "," + tData[5] + "," + tData[6] + "\n") txt.close() get_buffer() get_items() Draw.PupMenu("Moved %t|" + LIB.capitalize() + " from category " + CATlist[CURRENT_CAT-1] + " to category " + cat) # Strip unwanted characters from names. # def prepare_item(item): item = item.lower() item = item.replace(" ","_") item = item.replace("/","_") item = item.replace("\\","_") item = item.replace("\"","_") item = item.replace(":","_") item = item.replace("*","_") item = item.replace(">","_") item = item.replace("<","_") return item ######################################################################## ### This functions are taken from the shutil module # def copyfileobj(fsrc, fdst, length=16*1024): """copy data from file-like object fsrc to file-like object fdst""" while 1: buf = fsrc.read(length) if not buf: break fdst.write(buf) def copyfile(src, dst): """Copy data from src to dst""" #if _samefile(src, dst): # raise Error, "`%s` and `%s` are the same file" % (src, dst) fsrc = None fdst = None try: fsrc = open(src, 'rb') fdst = open(dst, 'wb') copyfileobj(fsrc, fdst) finally: if fdst: fdst.close() if fsrc: fsrc.close() # ######################################################################## ######################################################################## # Adds a favorite and checks if item is already in favs. # def add_fav(fav): try: txt = Text.Load(LIB_FAVS) temptext = txt.asLines() Text.unlink(txt) except: temptext = [] already = 0 for item in temptext: if item.count(fav): already = 1 if already: Draw.PupMenu("Oops%t|" + LIB.capitalize() +" already in your Favs!") else: if sys.exists(LIB_FAVS + ".bak"): os.remove(LIB_FAVS + ".bak") if sys.exists(LIB_FAVS): os.rename(LIB_FAVS,LIB_FAVS + ".bak") txt = open(LIB_FAVS,"w") for item in temptext: if item != "" : txt.write(item + "\n") txt.write(fav + "\n") txt.close() get_favs() # Removes a favorite from the fav list. # def remove_fav(fav): txt = Text.Load(LIB_FAVS) temptext = txt.asLines() Text.unlink(txt) count = 0 for item in temptext: count = count + 1 if item.count(fav): already = count if already: temptext.pop(already-1) if sys.exists(LIB_FAVS + ".bak"): os.remove(LIB_FAVS + ".bak") os.rename(LIB_FAVS,LIB_FAVS + ".bak") txt = open(LIB_FAVS,"w") for item in temptext: txt.write(item + "\n") txt.close() get_favs() else: Draw.PupMenu("Oops%t|" + LIB.capitalize() +" somehow not in your Favs!") def import_folder(folder): folder = sys.dirname(folder) files = os.listdir(folder) count = 0 #print "\nIMPORTING ITEMS TO THE LIBRARY" for f in files: if f[-3:] == "tar" or f[-3:] == "TAR": #print "Importing compressed item " + f failed = import_item(folder + os.sep + f) if not failed: count += 1 elif f[-3:] == "txt": if sys.exists(folder + os.sep + f[:-4] + ".blend") and sys.exists(folder + os.sep + f[:-4] + ".jpg"): #print "Importing uncompressed item " + f failed = import_item(folder + os.sep + f) if not failed: count += 1 Draw.PupMenu("Done!%t|" + str(count) + " items imported to the library.") def import_item(file): failed = 0 LIB = sys.basename(file).split("-")[0].lower() LIB_FOLDER = LibraryDir + os.sep + LIB + "Lib" + os.sep if file[-3:] == "txt": # We are importing an uncompressed item. No need to unpack. txt = open(file,"r") data = txt.readline().split(",") txt.close() try: data[0].index("|") d = LIB_FOLDER + data[0].split("|")[0] + os.sep + data[0].split("|")[1] except: d = LIB_FOLDER + data[0] folder = sys.dirname(file) + os.sep filename = sys.basename(file) filename = filename.replace(LIB.upper() + "-","") filename = filename.replace(".txt","") if not sys.exists(d): os.mkdir(d) if sys.exists(d + os.sep + filename + ".txt"): c = Draw.PupMenu("Item " + filename.replace("_"," ").replace("-"," by ").capitalize() +" already exist. Overwrite?%t|Yes%x1|No%x2") if c == 1: copyfile(folder + LIB.upper() + "-" + filename + ".blend", d + os.sep + filename + ".blend") copyfile(folder + LIB.upper() + "-" + filename + ".jpg", d + os.sep + filename + ".jpg") copyfile(folder + LIB.upper() + "-" + filename + ".txt", d + os.sep + filename + ".txt") else: failed = 1 else: copyfile(folder + LIB.upper() + "-" + filename + ".blend", d + os.sep + filename + ".blend") copyfile(folder + LIB.upper() + "-" + filename + ".jpg", d + os.sep + filename + ".jpg") copyfile(folder + LIB.upper() + "-" + filename + ".txt", d + os.sep + filename + ".txt") get_buffer() get_items() Blender.Redraw() if not failed: Draw.PupMenu("Imported OK!%t|" + LIB.capitalize() + " " + data[1] + " by " + data[2] + ", into category " + data[0].replace("|","\\")) elif file[-3:] == "tar": # We are importing a compressed item. The TAR module is needed here. if COMPRESSION: d = LIB_FOLDER folder = sys.dirname(file) + os.sep filename = sys.basename(file) filename = filename.replace(LIB.upper() + "-","") filename = filename.replace(".tar","") tar = tarfile.open(file, "r") for member in tar.getmembers(): # Get the files in this TAR package. tar.extract(member,d) txt = open(d + filename + ".txt","r") data = txt.readline().split(",") txt.close() tar.close() try: data[0].index("|") dd = LIB_FOLDER + data[0].split("|")[0] + os.sep + data[0].split("|")[1] except: dd = LIB_FOLDER + data[0] if not sys.exists(dd): os.mkdir(dd) if sys.exists(dd + os.sep + filename + ".txt"): c = Draw.PupMenu("Item "+ filename.replace("_"," ").replace("-"," by ").capitalize() +" already exist. Overwrite?%t|Yes%x1|No%x2") if c == 1: try: os.remove(dd + os.sep + filename + ".blend") os.remove(dd + os.sep + filename + ".jpg") os.remove(dd + os.sep + filename + ".txt") except: pass os.rename(d + filename + ".blend", dd + os.sep + filename + ".blend") os.rename(d + filename + ".jpg", dd + os.sep + filename + ".jpg") os.rename(d + filename + ".txt", dd + os.sep + filename + ".txt") else: failed = 1 else: os.rename(d + filename + ".blend", dd + os.sep + filename + ".blend") os.rename(d + filename + ".jpg", dd + os.sep + filename + ".jpg") os.rename(d + filename + ".txt", dd + os.sep + filename + ".txt") get_buffer() get_items() Blender.Redraw() if not failed: Draw.PupMenu("Imported OK!%t|Compressed " + LIB.capitalize() + " " + data[1] + " by " + data[2] + ", into category " + data[0].replace("|","\\")) return failed else: Draw.PupMenu("Error!%t|You need a full python installation to open compressed " + LIB.capitalize() + "s.|Please uncompress the TAR file manually into a folder and then import the TEXT file.") else: # Something went wrong. Warn the user he needs to select the right file to import. if COMPRESSION: Draw.PupMenu("Error importing!%t|Please select the TAR file with the " + LIB.capitalize()) else: Draw.PupMenu("Error importing!%t|Please select the Text file wich came with the " + LIB.capitalize()) # This allows the user to import a custom image for the preview. # def custom_preview(file): destFile = LIB_FOLDER + "custompreview.jpg" if file[-3:] == "jpg" or file[-4:] == "jpeg": try: img = Image.Get("custompreview.jpg") img.setFilename(file) img.reload() except: img = Image.Load(file) if img.size == [160,160]: if sys.exists(destFile): os.remove(destFile) copyfile(file,destFile) item = prepare_item(ITEMS[CURRENT_ITEM-1]) author = prepare_item(AUTHORS[CURRENT_ITEM-1]) if sys.exists(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB + item + "-" + author + ".jpg"): os.remove(LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB +item + "-" + author + ".jpg") os.rename(destFile,LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB + item + "-" + author + ".jpg") get_buffer() get_items() else: Draw.PupMenu("Sorry%t|Selected image is not the right size") else: Draw.PupMenu("Sorry%t|Only JPG images are allowed") def export_item(folder): global CATlist, CURRENT_CAT, SUB d = LIB_FOLDER + CATlist[CURRENT_CAT-1] + os.sep + SUB folder = sys.dirname(folder) + os.sep item = prepare_item(ITEMS[CURRENT_ITEM-1]) + "-" + prepare_item(AUTHORS[CURRENT_ITEM-1]) copyfile(d + item + ".blend",folder + LIB.upper() + "-" + item + ".blend") copyfile(d + item + ".jpg",folder + LIB.upper() + "-" + item + ".jpg") txt = open(folder + LIB.upper() + "-" + item + ".txt","a") if SUB: txt.write(CATlist[CURRENT_CAT-1] + "|" + SUB[:-1] + ",") else: txt.write(CATlist[CURRENT_CAT-1] + ",") txt.write(ITEMS[CURRENT_ITEM-1] + ",") txt.write(AUTHORS[CURRENT_ITEM-1] + ",") txt.write(MAILS[CURRENT_ITEM-1] + ",") txt.write(WEBPAGES[CURRENT_ITEM-1] + ",") txt.write(DESCS[CURRENT_ITEM-1] + ",") txt.write(ONAMES[CURRENT_ITEM-1] + "\n") txt.close() if COMPRESSION: # Compress the items with the TAR module and delete the now unnecesary files. tar = tarfile.open(folder + LIB.upper() + "-" + item + ".tar", "w:gz") tar.add(folder + LIB.upper() + "-" + item + ".blend",item + ".blend") tar.add(folder + LIB.upper() + "-" + item + ".jpg",item + ".jpg") tar.add(folder + LIB.upper() + "-" + item + ".txt",item + ".txt") tar.close() os.remove(folder + LIB.upper() + "-" + item + ".blend") os.remove(folder + LIB.upper() + "-" + item + ".txt") Blender.Redraw() Draw.PupMenu("Exported OK!%t|" + LIB.capitalize() + " " + ITEMS[CURRENT_ITEM-1] + " by " + AUTHORS[CURRENT_ITEM-1] + ", into directory " + folder) def open_item(f): try: Blender.Load(f) except: Draw.PupMenu("Path too long bug!%t|Please open the item manually.") # This shows Blender Library preferences using the new PUPBLOCK. # Allows to unclutter a bit the gui stuff block :) # def show_prefs(): global AuthorName, AuthorEmail, AuthorWebPage, LibraryDir, ShowWarnings prefAuthor = Blender.Draw.Create(AuthorName) prefEmail = Blender.Draw.Create(AuthorEmail) prefWebPage = Blender.Draw.Create(AuthorWebPage) libFolder = Blender.Draw.Create(LibraryDir) tog = Blender.Draw.Create(ShowWarnings) block = [] block.append("Personal Data:") block.append(("Author: ", prefAuthor, 0, 100, "Type your Name here")) block.append(("Email: ", prefEmail, 0, 100, "Type your E-mail here")) block.append(("Website: ", prefWebPage, 0, 100, "Type your Website here")) block.append("Misc Options:") block.append(("Help and Warnings", tog, "Disable if you are tired of these")) block.append("Path to Library:") block.append(("Folder: ", libFolder, 0, 100, "Folder in wich the library resides")) retval = Blender.Draw.PupBlock("Blender Library Preferences", block) if retval: AuthorName = prefAuthor.val AuthorEmail = prefEmail.val AuthorWebPage = prefWebPage.val ShowWarnings = tog.val LibraryDir = libFolder.val.rstrip(os.sep) set_registry(LibraryDir) # Function to show the main menu with RMB and deal with some options. def show_libs(): global BROWSING, ITEMlist, TOTAL_ITEMS if BROWSING: c = Draw.PupMenu("Options%t|Import an item...%x21|Import a folder...%x35|%l|Download " + LIB.capitalize() + "s..." + "%x25|Search for "+ LIB.capitalize() + "s...%x27|%l|Preferences...%x22|%l|Quit%x20") else: c = Draw.PupMenu("Options%t|Quit%x20") # Small if we are not browsing. # Quit the script if c == 20: Draw.Exit() return # Import Item elif c == 21: Window.FileSelector (import_item, 'CHOOSE FILE') # Download Items elif c == 25: webbrowser.open("http://blender-stuff.byethost32.com/" + LIB + "s.html") # Launch webbrowser # Show Preferences Dialog elif c == 22: show_prefs() # Show the search panel elif c == 27: ITEMlist =[] TOTAL_ITEMS = 0 BROWSING = 3 Draw.Redraw(1) elif c == 35: # Import Folder of items Window.FileSelector (import_folder, 'CHOOSE FOLDER') # Adds two simple lamps to light most of the preview renders. # def add_lamps(): scn = Scene.getCurrent() l01 = Lamp.New("Lamp","libraryLamp01") l01.setDist(30) lOb01 = Object.New('Lamp',"libraryLamp01") lOb01.link(l01) l02 = Lamp.New("Lamp","libraryLamp02") l02.setDist(30) lOb02 = Object.New('Lamp',"libraryLamp02") lOb02.link(l02) scn.link(lOb01) scn.link(lOb02) lOb01.setLocation(0,-10,6) lOb02.setLocation(7,7,6) scn.update() # Adds a camera framing the preview object for materials, textures... # def add_camera_tex(): scn = Scene.getCurrent() cam01 = Camera.New("persp","libraryCamera") camOb01 = Object.New("Camera","libraryCamera") camOb01.link(cam01) scn.link(camOb01) camOb01.setLocation(4.0458760261535645, -3.7044022083282471, 2.4295172691345215) camOb01.setEuler([1.109319, 0.010817, 0.814928]) scn.update() # Adds a camera for the IPOs and paths previews. # def add_camera_ipo(): scn = Scene.getCurrent() cam02 = Camera.New("persp","libraryCamera") camOb02 = Object.New("Camera","libraryCamera") camOb02.link(cam02) scn.link(camOb02) camOb02.setLocation((5.9604644775390625e-008, -20.568927764892578, 8.5717878341674805)) camOb02.setEuler([1.308997, 0.000000, 0.000000]) scn.update() # Adds a camera for the lamps preview. # def add_camera_lamp(): scn = Scene.getCurrent() cam02 = Camera.New("persp","libraryCamera") camOb02 = Object.New("Camera","libraryCamera") camOb02.link(cam02) scn.link(camOb02) camOb02.setLocation((5.9604644775390625e-008, -7.568927764892578, 3.5717878341674805)) camOb02.setEuler([1.308997, 0.000000, 0.000000]) scn.update() # Adds a plane for the Material and Texture preview. # def add_plane(): v1=NMesh.Vert(1,1,0) v2=NMesh.Vert(1,-1,0) v3=NMesh.Vert(-1,-1,0) v4=NMesh.Vert(-1,1,0) f=NMesh.Face() f.v.append(v1) f.v.append(v2) f.v.append(v3) f.v.append(v4) me=NMesh.New() me.verts.append(v1) me.verts.append(v2) me.verts.append(v3) me.verts.append(v4) me.faces.append(f) NMesh.PutRaw(me) # Adds a plane for Lamps preview. # def add_plane_big(): v1=NMesh.Vert(4,4,0.1) v2=NMesh.Vert(4,-4,0.1) v3=NMesh.Vert(-4,-4,0.1) v4=NMesh.Vert(-4,4,0.1) f=NMesh.Face() f.v.append(v1) f.v.append(v2) f.v.append(v3) f.v.append(v4) me=NMesh.New() me.verts.append(v1) me.verts.append(v2) me.verts.append(v3) me.verts.append(v4) me.faces.append(f) NMesh.PutRaw(me) ob = Object.Get("Mesh") ob.setName("libraryPlane") # Adds a plane for the material and texture preview. # def add_plane_tex(): v1=NMesh.Vert(1,1,0) v2=NMesh.Vert(1,-1,0) v3=NMesh.Vert(-1,-1,0) v4=NMesh.Vert(-1,1,0) f=NMesh.Face() f.v.append(v1) f.v.append(v2) f.v.append(v3) f.v.append(v4) me=NMesh.New() me.verts.append(v1) me.verts.append(v2) me.verts.append(v3) me.verts.append(v4) me.faces.append(f) me.update() NMesh.PutRaw(me,"libraryPlane") ob = Object.Get("Mesh") ob.setName("libraryPlane") ob.setEuler([1.109319, 0.010817, 0.814928]) ob.setLocation(0.86442756652832031, -0.72015130519866943, 0.25754207372665405) ob.setSize(2.24,2.24,2.24) # Adds the fake wire plane for the previews # def add_plane_view(): v1=NMesh.Vert(1,1,0) v2=NMesh.Vert(1,-1,0) v3=NMesh.Vert(-1,-1,0) v4=NMesh.Vert(-1,1,0) f=NMesh.Face() f.v.append(v1) f.v.append(v2) f.v.append(v3) f.v.append(v4) me=NMesh.New() me.verts.append(v1) me.verts.append(v2) me.verts.append(v3) me.verts.append(v4) me.faces.append(f) NMesh.PutRaw(me,"MeshPlane") ob = Object.Get("Mesh") ob.setName("libraryView") ob.setSize(10,10,10) tmat = Material.Get("libraryWireDark") ob.colbits = 0x01 ob.setMaterials([tmat]) newMe = Mesh.Get("MeshPlane") for v in newMe.verts: v.sel = 1 for r in range(4): newMe.subdivide() # Adds a cube for material preview # Need better code here. I suck with NMesh stuff. :( # def add_cube(x,y,z,name): v1=NMesh.Vert(x,y,-1) v2=NMesh.Vert(x,-1,-1) v3=NMesh.Vert(-1,-1,-1) v4=NMesh.Vert(-1,y,-1) v5=NMesh.Vert(x,y,z) v6=NMesh.Vert(x,-1,z) v7=NMesh.Vert(-1,-1,z) v8=NMesh.Vert(-1,y,z) f1=NMesh.Face() f2=NMesh.Face() f3=NMesh.Face() f4=NMesh.Face() f5=NMesh.Face() f6=NMesh.Face() f1.v.append(v1) f1.v.append(v2) f1.v.append(v3) f1.v.append(v4) f2.v.append(v5) f2.v.append(v6) f2.v.append(v7) f2.v.append(v8) f3.v.append(v2) f3.v.append(v3) f3.v.append(v7) f3.v.append(v6) f4.v.append(v1) f4.v.append(v4) f4.v.append(v8) f4.v.append(v5) f5.v.append(v1) f5.v.append(v2) f5.v.append(v6) f5.v.append(v5) f6.v.append(v3) f6.v.append(v4) f6.v.append(v8) f6.v.append(v7) me=NMesh.New() me.verts.append(v1) me.verts.append(v2) me.verts.append(v3) me.verts.append(v4) me.verts.append(v5) me.verts.append(v6) me.verts.append(v7) me.verts.append(v8) me.faces.append(f1) me.faces.append(f2) me.faces.append(f3) me.faces.append(f4) me.faces.append(f5) me.faces.append(f6) NMesh.PutRaw(me) ob = Object.Get("Mesh") ob.setName(name) def add_cone(x,y,z,name): v1=NMesh.Vert(x,y,-1) v2=NMesh.Vert(x,-y,-1) v3=NMesh.Vert(-x,-y,-1) v4=NMesh.Vert(-x,y,-1) v5=NMesh.Vert(0,0,z) v6=NMesh.Vert(0,0,z) v7=NMesh.Vert(0,0,z) v8=NMesh.Vert(0,0,z) f1=NMesh.Face() f2=NMesh.Face() f3=NMesh.Face() f4=NMesh.Face() f5=NMesh.Face() f6=NMesh.Face() f1.v.append(v1) f1.v.append(v2) f1.v.append(v3) f1.v.append(v4) f2.v.append(v5) f2.v.append(v6) f2.v.append(v7) f2.v.append(v8) f3.v.append(v2) f3.v.append(v3) f3.v.append(v7) f3.v.append(v6) f4.v.append(v1) f4.v.append(v4) f4.v.append(v8) f4.v.append(v5) f5.v.append(v1) f5.v.append(v2) f5.v.append(v6) f5.v.append(v5) f6.v.append(v3) f6.v.append(v4) f6.v.append(v8) f6.v.append(v7) me=NMesh.New() me.verts.append(v1) me.verts.append(v2) me.verts.append(v3) me.verts.append(v4) me.verts.append(v5) me.verts.append(v6) me.verts.append(v7) me.verts.append(v8) me.faces.append(f1) me.faces.append(f2) me.faces.append(f3) me.faces.append(f4) me.faces.append(f5) me.faces.append(f6) NMesh.PutRaw(me,"libraryCone") ob = Object.Get("Mesh") ob.setName(name) # Adds a sphere for material and lamps preview. # I seriously need better code here!!! :( # What Iīm doing here is adding a cube, then # subdividing it a few times and finally using # the new toSphere method to turn it into a sphere. # def add_sphere(x,y,z,name): v1=NMesh.Vert(x,y,-1) v2=NMesh.Vert(x,-1,-1) v3=NMesh.Vert(-1,-1,-1) v4=NMesh.Vert(-1,y,-1) v5=NMesh.Vert(x,y,z) v6=NMesh.Vert(x,-1,z) v7=NMesh.Vert(-1,-1,z) v8=NMesh.Vert(-1,y,z) f1=NMesh.Face() f2=NMesh.Face() f3=NMesh.Face() f4=NMesh.Face() f5=NMesh.Face() f6=NMesh.Face() f1.v.append(v1) f1.v.append(v2) f1.v.append(v3) f1.v.append(v4) f2.v.append(v5) f2.v.append(v6) f2.v.append(v7) f2.v.append(v8) f3.v.append(v2) f3.v.append(v3) f3.v.append(v7) f3.v.append(v6) f4.v.append(v1) f4.v.append(v4) f4.v.append(v8) f4.v.append(v5) f5.v.append(v1) f5.v.append(v2) f5.v.append(v6) f5.v.append(v5) f6.v.append(v3) f6.v.append(v4) f6.v.append(v8) f6.v.append(v7) me=NMesh.New() me.verts.append(v1) me.verts.append(v2) me.verts.append(v3) me.verts.append(v4) me.verts.append(v5) me.verts.append(v6) me.verts.append(v7) me.verts.append(v8) me.faces.append(f1) me.faces.append(f2) me.faces.append(f3) me.faces.append(f4) me.faces.append(f5) me.faces.append(f6) NMesh.PutRaw(me,"librarySphere") ob = Object.Get("Mesh") ob.setName(name) newMe = Mesh.Get("librarySphere") for v in newMe.verts: v.sel = 1 for r in range(3): newMe.subdivide() newMe.toSphere() newMe.recalcNormals() for f in newMe.faces: f.smooth = 1 # Adds the colored axes in the center of the space for some previews. # def add_axes(): scale = 0.1 add_cube(1,1,20,"libraryZ") ob= Object.Get("libraryZ") ob.setSize(scale,scale,scale) mat = Material.Get("libraryShadelessB") ob.colbits = 0x01 ob.setMaterials([mat]) add_cube(20,1,1,"libraryX") ob= Object.Get("libraryX") ob.setSize(scale,scale,scale) mat = Material.Get("libraryShadelessR") ob.colbits = 0x01 ob.setMaterials([mat]) add_cube(1,20,1,"libraryY") ob= Object.Get("libraryY") ob.setSize(scale,scale,scale) mat = Material.Get("libraryShadelessG") ob.colbits = 0x01 ob.setMaterials([mat]) # Adds a simple Nurb circle to use as taper object. # Itīs needed to make the path visible in the preview. # def add_curvecircle(): c = Curve.New() c.appendNurb([0.0, -1.0, 0.0, 1.0, 0.0]) c[0].append([-1.0, -1.0, 0.0, 0.35355338454246521, 0.0]) c[0].append([-1.0, 0.0, 0.0, 1.0, 0.0]) c[0].append([-1.0, 1.0, 0.0, 0.35355338454246521, 0.0]) c[0].append([0.0, 1.0, 0.0, 1.0, 0.0]) c[0].append([1.0, 1.0, 0.0, 0.35355338454246521, 0.0]) c[0].append([1.0, 0.0, 0.0, 1.0, 0.0]) c[0].append([1.0, -1.0, 0.0, 0.35355338454246521, 0.0]) c[0].setFlagU(1) cur = Scene.getCurrent() ob = Object.New("Curve",'libraryCircle') scale = 0.02 ob.link(c) cur.link(ob) ob.setSize(scale,scale,scale) # The following adds simple materials used by several other functions # when generating the preview scene. # def add_mat_halo(): matHalo = Material.New("libraryHalo") matHalo.rgbCol = [1, 1, 1] matHalo.setHaloSize(0.1) matHalo.setMode("Shadeless","Halo") def add_mat_wire(): matWire = Material.New("libraryWire") matWire.rgbCol = [1, 1, 1] matWire.setMode("Shadeless","Wire") matWireDark = Material.New("libraryWireDark") matWireDark.rgbCol = [0.15, 0.15, 0.15] matWireDark.setMode("Shadeless","Wire") def add_mat_shadeless(): matShadeless = Material.New("libraryShadeless") matShadeless.rgbCol = [1, 1, 1] matShadeless.setMode("Shadeless") matShadelessR = Material.New("libraryShadelessR") matShadelessR.rgbCol = [1, 0, 0] matShadelessR.setMode("Shadeless") matShadelessG = Material.New("libraryShadelessG") matShadelessG.rgbCol = [0, 1, 0] matShadelessG.setMode("Shadeless") matShadelessB = Material.New("libraryShadelessB") matShadelessB.rgbCol = [0, 0, 1] matShadelessB.setMode("Shadeless") def add_mat_tex(): matTex = Material.New("libraryMaterial") matTex.setMode("Shadeless") # Adds the background worlds for the preview. # Itīs no posible to set a texture on a world using python :( # so no checkerboard background for now. # def add_world_grey(): if sys.exists(LibraryDir + os.sep + "library.blend") and (LIB == "object" or LIB == "particle" or LIB == "armature"): Library.Open(LibraryDir + os.sep + "library.blend") try: Library.Load(LIB.capitalize() + " World","World", 1) Library.Update() Library.Close w = World.Get(LIB.capitalize() + " World").setName("libraryWorld") except: w = World.New("libraryWorld") w.setHor([0.3,0.3,0.3]) w.setZen([0.2,0.2,0.2]) else: w = World.New("libraryWorld") w.setHor([0.3,0.3,0.3]) w.setZen([0.2,0.2,0.2]) def add_world_darkgrey(): if sys.exists(LibraryDir + os.sep + "library.blend"): Library.Open(LibraryDir + os.sep + "library.blend") try: Library.Load("Material World","World", 1) Library.Update() Library.Close w = World.Get("Material World").setName("libraryWorld") except: w = World.New("libraryWorld") w.setHor([0.0,0.0,0.0]) w.setZen([0.1,0.1,0.1]) else: w = World.New("libraryWorld") w.setHor([0.0,0.0,0.0]) w.setZen([0.1,0.1,0.1]) AuthorName = "Unkown" AuthorEmail = "Not available" AuthorWebPage = "Not available" ShowWarnings = 1 get_registry() if BROWSING != 2: try: init(Blender.Wb) CURRENT_LIB = LIBS.index(Blender.Wb)+1 except: init("material") CURRENT_LIB = 8 try: CURRENT_CAT = Blender.Wc except: CURRENT_CAT = 1 get_buffer() get_items() Draw.Register(gui, event, button_event)