def json_audit(): project = Project() environment = Environment() asset_dir = project.get_assets_dir() failed_str = "" for i, asset in enumerate(project.list_assets(AssetType.PROP)): try: asset_obj = project.get_body(asset) element_obj = asset_obj.get_element(Department.MODEL, force_create=True) element_path = element_obj.checkout( environment.get_current_username()) checkout.non_gui_open(element_path, asset) json_exporter_non_gui.exportProp(asset_obj) except Exception, err: error_str = "" error_str += "\nError exporting JSON for {0}".format(asset) error_str += "\n" + traceback.format_exc() print error_str failed_str += error_str continue
def confirmWritePropReference(body=None): filePath = pm.sceneName() fileDir = os.path.dirname(filePath) project = Project() if not body: checkout = project.get_checkout(fileDir) bodyName = checkout.get_body_name() body = project.get_body(bodyName) if body.is_asset() and body.get_type() == AssetType.PROP: element = body.get_element(Department.MODEL) filePath = os.path.join(project.get_assets_dir(), element.get_cache_dir()) assemblies = pm.ls(assemblies=True) pm.select(pm.listCameras(), replace=True) cameras = pm.selected() pm.select([]) non_cameras = [ assembly for assembly in assemblies if assembly not in cameras ] exportPropJSON(filePath, non_cameras[0], isReference=False, name=body.get_name()) showSuccessPopup()
def audit(): project = Project() environment = Environment() asset_dir = project.get_assets_dir() for i, asset in enumerate(project.list_assets(AssetType.PROP)): asset_obj = project.get_body(asset) element_obj = asset_obj.get_element(Department.MODEL, force_create=True) element_path = element_obj.checkout(environment.get_current_username()) #cmds.file(rename='/tmp/lol'+str(i)+'.mb') #cmds.file(save=True) checkout.non_gui_open(element_path, asset) print 'Done'
def exportProp(body): project = Project() element = body.get_element(Department.MODEL) filePath = os.path.join(project.get_assets_dir(), element.get_cache_dir()) assemblies = pm.ls(assemblies=True) pm.select(pm.listCameras(), replace=True) cameras = pm.selected() pm.select([]) non_cameras = [ assembly for assembly in assemblies if assembly not in cameras ] if len(non_cameras) > 0: exportPropJSON(filePath, non_cameras[0], isReference=False, name=body.get_name()) else: print "No non-camera assets found. Most likely this is a camera asset."
def writeXML(assetName='None', context='OBJ'): project = Project() asset_body = project.get_body(assetName) icon = os.path.join('$JOB', 'byu-pipeline-tools', 'assets', 'images', 'icons', 'tool-icons', '2.png') if not asset_body.is_asset(): print('error me this') raise Exception('Failed to generate XML for: ' + assetName + ' \n Object is not an Asset') global baseXML xml = Template(baseXML).substitute(NAME=assetName, LABEL=assetName.replace('_', ' ').title(), ICON=icon, CONTEXT=context) try: path = os.path.join(project.get_assets_dir(), assetName) path = os.path.join(path, assetName + '.shelf') file = open(path, 'w') file.write(xml) file.close() if not os.path.exists(project.get_tabs_dir()): os.makedirs(project.get_tabs_dir()) sym = os.path.join(project.get_tabs_dir(), assetName + '.shelf') if os.path.exists(sym): os.unlink(sym) os.link(path, sym) except Exception as e: print e raise Exception('Failed to generate XML for: ' + assetName)