def checkDirectory(dirVal, ask=True): if len(dirVal.strip()) == 0: dirVal = '.' tempDir = Blender.sys.cleanpath(iUtils.filterDirPath(dirVal)) if not os.path.isdir(tempDir): if ask: result = Draw.PupMenu("Directory Doesn't Exist, Create?%t|Yes%x1|No%x0") if(result != 1): Draw.Redraw(1) return None os.makedirs(tempDir) return tempDir
def buttonEvent(evt): global mymsg, toggle, gSelectedOnly global bSelectedOnly, bCreateScene, gCreateScene global gMeshDir, gDebug global gTGAOutput, gORGOutput, gImageDir, gBaseDir global bWorld, gCreateWorld global gOutDir, gExportLights, bExportLights global gMeshDir, gOutDir, gImageDir, bWalkTest, gWalkTest global gExportCameras, bExportCameras, gLastSceneExported global gExportPhysics, bExportPhysics global gBinary, bBinary, gWarnings, gDisplayWarnings global gExportCancelled, gStatus global gIrrlichtVersion if evt == ID_SELECTDIR: Window.FileSelector(dirSelected,'Select Directory',gOutDir) Draw.Redraw(1) elif evt == ID_CANCEL: saveConfig() Draw.Exit() elif evt == ID_SELECTEDONLY: gSelectedOnly = bSelectedOnly.val Draw.Redraw(1) elif evt == ID_BINARY: gBinary = bBinary.val Draw.Redraw(1) elif evt == ID_CREATESCENE: gCreateScene = bCreateScene.val Draw.Redraw(1) elif evt == ID_EXPLIGHTS: gExportLights = bExportLights.val Draw.Redraw(1) elif evt == ID_EXPCAMERAS: gExportCameras = bExportCameras.val Draw.Redraw(1) elif evt == ID_EXPPHYSICS: gExportPhysics = bExportPhysics.val Draw.Redraw(1) elif evt == ID_WORLD: gCreateWorld = bWorld.val Draw.Redraw(1) elif evt == ID_WALKTEST: gWalkTest = bWalkTest.val Draw.Redraw(1) elif evt == ID_TEXDIR: tempDir = checkDirectory(bImageDir.val) if tempDir == None: return gImageDir = tempDir Draw.Redraw(1) elif evt == ID_OUTDIR: tempDir = checkDirectory(bSceneDir.val) if tempDir == None: return gOutDir = tempDir Draw.Redraw(1) elif evt == ID_BASEDIR: tempDir = checkDirectory(bBaseDir.val) if tempDir == None: return gBaseDir = tempDir Draw.Redraw(1) elif evt == ID_GENPROPS: iUtils.setIDProperties() elif evt == ID_EXPORT: saveConfig() gWarnings = [] gExportCancelled = False tempDir = iUtils.filterDirPath(gOutDir) baseDir = tempDir # if relative, make it relative to the .blend file location if not os.path.isabs(tempDir): baseDir = Blender.sys.dirname(Blender.Get('filename')) if not os.path.isabs(baseDir): baseDir = os.path.abspath(baseDir) # if no .blend name (not saved), use cwd if len(baseDir.strip()) == 0: baseDir = os.getcwd() baseDir = os.path.normpath( baseDir + \ Blender.sys.sep + tempDir) + Blender.sys.sep gSceneDir = iUtils.defScriptOptions['sceneOutDir'] if (gSceneDir[0] == '/') or (gSceneDir.find(':') >= 0): # absolute? gSceneDir = iUtils.filterDirPath(gSceneDir) else: gSceneDir = os.path.abspath(baseDir + gSceneDir) checkDirectory(gSceneDir, False) gMeshDir = iUtils.defScriptOptions['meshOutDir'] if (gMeshDir[0] == '/') or (gMeshDir.find(':') >= 0): # absolute? gMeshDir = iUtils.filterDirPath(gMeshDir) else: gMeshDir = os.path.abspath(baseDir + gMeshDir) checkDirectory(gMeshDir, False) gImageDir = iUtils.defScriptOptions['texOutDir'] if (gImageDir[0] == '/') or (gImageDir.find(':') >= 0): # absolute? gImageDir = iUtils.filterDirPath(gImageDir) else: gImageDir = os.path.abspath(baseDir + gImageDir) checkDirectory(gImageDir, False) exporter = iExporter.Exporter(gCreateScene, baseDir, gSceneDir, gMeshDir, gImageDir, '.???', gSelectedOnly, gExportLights, gExportCameras, gExportPhysics, gBinary, gDebug, gVersionList[gIrrlichtVersion]) Window.WaitCursor(1) exporter.doExport() if gExportCancelled: gStatus = 'Export Cancelled' elif exporter.gFatalError == None: if (gCreateScene and gWalkTest and gHaveWalkTest and (exporter.gSceneFileName !=None)): runWalkTest(exporter.gSceneFileName) gLastSceneExported = exporter.gSceneFileName Window.WaitCursor(0) exporter = None if len(gWarnings) > 0: gDisplayWarnings = True Draw.Redraw(1) elif evt == ID_BACK: gDisplayWarnings = False Draw.Redraw(1) elif evt == ID_SHOWWARNINGS: if len(gWarnings) > 0: gDisplayWarnings = True Draw.Redraw(1) elif evt == ID_REWALKTEST: if gHaveWalkTest and (gLastSceneExported != None): runWalkTest(gLastSceneExported) elif evt == ID_IVERSION: gIrrlichtVersion = bIrrlichtVersion.val Draw.Redraw(1)
def dirSelected(fileName): global gOutDir,bSceneDir gOutDir = iUtils.filterDirPath(Blender.sys.dirname(fileName)) bSceneDir.val = gOutDir