def execute(self, context): startLog(self) messages = {} dic = robotdictionary.buildRobotDictionary() validator.check_dict(dic, defs.dictConstraints, messages) defs.checkMessages = messages if len(list(messages.keys())) > 0 else {"NoObject": []} for entry in messages: log("Errors in object " + entry + ":", 'INFO') for error in messages[entry]: log(error, 'INFO') endLog() return {'FINISHED'}
def execute(self, context): startLog(self) messages = {} dic = robotdictionary.buildRobotDictionary() validator.check_dict(dic, defs.dictConstraints, messages) defs.checkMessages = messages if len(list(messages.keys())) > 0 else { "NoObject": [] } for entry in messages: log("Errors in object " + entry + ":", 'INFO') for error in messages[entry]: log(error, 'INFO') endLog() return {'FINISHED'}
def execute(self, context): """Executes the operator and unifies the selected objects meshes :param context: The blender context to work with :return: Blender result """ startLog(self) messages = {} dic = robotdictionary.buildRobotDictionary() validator.check_dict(dic, defs.dictConstraints, messages) defs.checkMessages = messages if len(list(messages.keys())) > 0 else {"NoObject": []} for entry in messages: log("Errors in object " + entry + ":", 'INFO') for error in messages[entry]: log(error, 'INFO') endLog() return {'FINISHED'}
def execute(self, context): startLog(self) objs = context.selected_objects robot = robotdictionary.buildRobotDictionary() selectionUtils.selectObjects(objs) outpath = "" if bpy.data.worlds[0].relativePath: outpath = exporter.securepath(os.path.expanduser(os.path.join(bpy.path.abspath("//"), bpy.data.worlds[0].path))) else: outpath = exporter.securepath(os.path.expanduser(bpy.data.worlds[0].path)) #expPath = os.path.join(outpath, robot["modelname"] + "_bake") #exporter.export(path=expPath, robotmodel=robot) exporter.bakeModel(objs, outpath, robot["modelname"]) with open(os.path.join(outpath, "info.bake"), "w") as f: f.write(yaml.dump({"name": robot["modelname"]})) endLog() return {'FINISHED'}
def execute(self, context): startLog(self) objs = context.selected_objects robot = robotdictionary.buildRobotDictionary() selectionUtils.selectObjects(objs) outpath = "" if bpy.data.worlds[0].relativePath: outpath = exporter.securepath( os.path.expanduser( os.path.join(bpy.path.abspath("//"), bpy.data.worlds[0].path))) else: outpath = exporter.securepath( os.path.expanduser(bpy.data.worlds[0].path)) #expPath = os.path.join(outpath, robot["modelname"] + "_bake") #exporter.export(path=expPath, robotmodel=robot) exporter.bakeModel(objs, outpath, robot["modelname"]) with open(os.path.join(outpath, "info.bake"), "w") as f: f.write(yaml.dump({"name": robot["modelname"]})) endLog() return {'FINISHED'}
def execute(self, context): startLog(self) objs = context.selected_objects robot = robotdictionary.buildRobotDictionary() selectionUtils.selectObjects(objs) tmpdir = tempfile.gettempdir() expPath = os.path.join(tmpdir, robot["modelname"] + "_bake") exporter.export(path=expPath, robotmodel=robot) exporter.bakeModel(objs, expPath, robot["modelname"]) zipfilename = os.path.join(tmpdir, robot["modelname"] + ".bake") file = zipfile.ZipFile(zipfilename, mode="w") for filename in os.listdir(expPath): file.write(os.path.join(expPath, filename), arcname=filename) file.close() shutil.rmtree(expPath) outpath = "" if bpy.data.worlds[0].relativePath: outpath = exporter.securepath(os.path.expanduser(os.path.join(bpy.path.abspath("//"), bpy.data.worlds[0].path))) else: outpath = exporter.securepath(os.path.expanduser(bpy.data.worlds[0].path)) shutil.copy(zipfilename, outpath) endLog() return {'FINISHED'}
def export(path='', robotmodel=None): """This function does the actual exporting of the robot model. :return: Nothing. """ #TODO: check if all selected objects are on visible layers (option bpy.ops.object.select_all()?) if path == '': if bpy.data.worlds[0].relativePath: outpath = securepath(os.path.expanduser(os.path.join(bpy.path.abspath("//"), bpy.data.worlds[0].path))) else: outpath = securepath(os.path.expanduser(bpy.data.worlds[0].path)) else: outpath = path if not outpath.endswith(os.path.sep): outpath += os.path.sep meshoutpath = securepath(os.path.join(outpath, bpy.data.worlds[0].meshpath)) yaml = bpy.data.worlds[0].exportYAML urdf = bpy.data.worlds[0].exportURDF srdf = bpy.data.worlds[0].exportSRDF smurf = bpy.data.worlds[0].exportSMURF mars = bpy.data.worlds[0].exportMARSscene meshexp = bpy.data.worlds[0].exportMesh objexp = bpy.data.worlds[0].useObj bobjexp = bpy.data.worlds[0].useBobj stlexp = bpy.data.worlds[0].useStl daeexp = bpy.data.worlds[0].useDae objectlist = bpy.context.selected_objects robot = robotmodel if robotmodel else robotdictionary.buildRobotDictionary() if yaml or urdf or smurf or mars: if yaml: exportModelToYAML(robot, outpath + robot["modelname"] + "_dict.yml") if mars: exportModelToMARS(robot, outpath + robot["modelname"] + "_mars.scene") if srdf: exportModelToSRDF(robot, outpath + robot["modelname"] + ".srdf") if smurf: if bpy.data.worlds[0].structureExport: securepath(os.path.join(outpath, 'smurf')) securepath(os.path.join(outpath, 'urdf')) exportModelToSMURF(robot, os.path.join(outpath, 'smurf/')) else: exportModelToSMURF(robot, outpath) elif urdf: if bpy.data.worlds[0].structureExport: securepath(os.path.join(outpath, 'urdf')) exportModelToURDF(robot, os.path.join(outpath, 'urdf', robot["modelname"] + ".urdf")) else: exportModelToURDF(robot, outpath + robot["modelname"] + ".urdf") if meshexp: show_progress = bpy.app.version[0] * 100 + bpy.app.version[1] >= 269 if show_progress: wm = bpy.context.window_manager total = float(len(objectlist)) wm.progress_begin(0, total) i = 1 print("Exporting meshes to " + meshoutpath + "...\n") for obj in objectlist: if ((obj.phobostype == 'visual' or obj.phobostype == 'collision') and obj['geometry/type'] == 'mesh' and 'filename' not in obj and 'geometry/'+defs.reservedProperties['SHAREDMESH'] not in obj): if objexp: exportObj(meshoutpath, obj) if bobjexp: exportBobj(meshoutpath, obj) if stlexp: exportStl(meshoutpath, obj) if daeexp: exportDae(meshoutpath, obj) if show_progress: wm.progress_update(i) i += 1 if show_progress: wm.progress_end()