def open_get_path_dialog(init_directory=None): """ Opens standard 3ds Max get path dialog :param init_directory: str, init directory to browse :return: str """ result = MaxPlus.FPValue() if init_directory is None: MaxPlus.Core.EvalMAXScript( 'getSavePath caption:"Export directory" initialDir:(getDir #maxroot)', result) else: MaxPlus.Core.EvalMAXScript( 'getSavePath caption:"Export directory" initialDir:"{}"'.format( path.clean_path(init_directory)), result) try: selected_path = result.Get() return selected_path except Exception: return ""
def _run_commands_raise_errors(commands): command = ';'.join(commands) maybe_error = MaxPlus.FPValue() if not MaxPlus.Core.EvalMAXScript(command, maybe_error): raise RuntimeError(str(maybe_error))
# :copyright: Copyright (c) 2016 ftrack import os import MaxPlus import sys # Discover 3dsmax version. raw_max_version = MaxPlus.FPValue() MaxPlus.Core.EvalMAXScript('getFileVersion "$max/3dsmax.exe"', raw_max_version) max_version = int(raw_max_version.Get().split(',')[0]) if max_version < 19: # Max 2015 & 2016 require this patch to avoid crashing during print and logging. # https://help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__files_GUID_B3FF3632_F177_4A90_AE3D_D36603B7A2F3_htm sys.stdout = _old_stdout sys.stderr = _old_stderr import functools from QtExt import QtCore from ftrack_connect_3dsmax.connector import Connector from ftrack_connect_3dsmax.connector.maxcallbacks import * try: import ftrack ftrack.setup() except: pass
def getPythonCoreDir(): result = MaxPlus.FPValue() evaluation_success = MaxPlus.Core.EvalMAXScript('micra.CorePyDir', result) dir = result.Get().rstrip('\\') #remove last slash return dir
def get_vars(nim=None): 'Gets NIM settings from the defaultRenderGlobals node in 3dsMax.' P.info( '3dsMax Getting information from NIM attributes on the defaultRenderGlobals node...' ) # User : ''' if mc.objExists( 'defaultRenderGlobals.nim_user' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_user' ) P.debug( 'User = %s' % value ) nim.set_user( userName=value ) ''' nim_user = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_user", nim_user) if success: nim.set_user(nim_user.Get()) P.info('Reading userName') else: P.error('Failed reading userName') # User ID : ''' if mc.objExists( 'defaultRenderGlobals.nim_userID' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_userID' ) P.debug( 'User ID = %s' % value ) nim.set_userID( userID=value ) ''' nim_userID = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_userID", nim_userID) if success: nim.set_userID(nim_userID.Get()) P.error('Reading nim_userID') else: P.error('Failed reading nim_userID') # Tab/Class : ''' if mc.objExists( 'defaultRenderGlobals.nim_class' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_class' ) P.debug( 'Tab = %s' % value ) nim.set_tab( value ) ''' nim_class = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_class", nim_class) if success: nim.set_tab(nim_class.Get()) P.error('Reading nim_class') else: P.error('Failed reading nim_class') # Server : ''' if mc.objExists( 'defaultRenderGlobals.nim_server' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_server' ) P.debug( 'Server = %s' % value ) nim.set_server( path=value ) ''' nim_server = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_server", nim_server) if success: nim.set_server(path=nim_server.Get()) P.error('Reading nim_server') else: P.error('Failed reading nim_server') # Server ID : ''' if mc.objExists( 'defaultRenderGlobals.nim_serverID' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_serverID' ) P.debug( 'Server ID = %s' % value ) nim.set_ID( elem='server', ID=value ) ''' nim_serverID = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_serverID", nim_serverID) if success: nim.set_ID(elem='server', ID=nim_serverID.Get()) P.error('Reading nim_serverID') else: P.error('Failed reading nim_serverID') # Job : ''' if mc.objExists( 'defaultRenderGlobals.nim_jobName' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_jobName' ) P.debug( 'Job = %s' % value ) nim.set_name( elem='job', name=value ) ''' nim_jobName = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_jobName", nim_jobName) if success: nim.set_name(elem='job', name=nim_jobName.Get()) P.error('Reading nim_jobName') else: P.error('Failed reading nim_jobName') # Job ID : ''' if mc.objExists( 'defaultRenderGlobals.nim_jobID' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_jobID' ) P.debug( 'Job ID = %s' % value ) nim.set_ID( elem='job', ID=value ) ''' nim_jobID = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_jobID", nim_jobID) if success: nim.set_ID(elem='job', ID=nim_jobID.Get()) P.error('Reading nim_jobID') else: P.error('Failed reading nim_jobID') # Show : ''' if mc.objExists( 'defaultRenderGlobals.nim_showName' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_showName' ) P.debug( 'Show = %s' % value ) nim.set_name( elem='show', name=value ) ''' nim_showName = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_showName", nim_showName) if success: nim.set_name(elem='show', name=nim_showName.Get()) P.error('Reading nim_showName') else: P.error('Failed reading nim_showName') # Show ID : ''' if mc.objExists( 'defaultRenderGlobals.nim_showID' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_showID' ) P.debug( 'Show ID = %s' % value ) nim.set_ID( elem='show', ID=value ) ''' nim_showID = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_showID", nim_showID) if success: nim.set_ID(elem='show', ID=nim_showID.Get()) P.error('Reading nim_showID') else: P.error('Failed reading nim_showID') # Shot : ''' if mc.objExists( 'defaultRenderGlobals.nim_shot' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_shot' ) P.debug( 'Shot = %s' % value ) nim.set_name( elem='shot', name=value ) ''' nim_shot = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_shot", nim_shot) if success: nim.set_name(elem='shot', name=nim_shot.Get()) P.error('Reading nim_shot') else: P.error('Failed reading nim_shot') # Shot ID : ''' if mc.objExists( 'defaultRenderGlobals.nim_shotID' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_shotID' ) P.debug( 'Shot ID = %s' % value ) nim.set_ID( elem='shot', ID=value ) ''' nim_shotID = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_shotID", nim_shotID) if success: nim.set_ID(elem='shot', ID=nim_shotID.Get()) P.error('Reading nim_shotID') else: P.error('Failed reading nim_shotID') # Asset : ''' if mc.objExists( 'defaultRenderGlobals.nim_asset' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_asset' ) P.debug( 'Asset = %s' % value ) nim.set_name( elem='asset', name=value ) ''' nim_asset = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_asset", nim_asset) if success: nim.set_name(elem='asset', name=nim_asset.Get()) P.error('Reading nim_asset') else: P.error('Failed reading nim_asset') # Asset ID : ''' if mc.objExists( 'defaultRenderGlobals.nim_assetID' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_assetID' ) P.debug( 'Asset ID = %s' % value ) nim.set_ID( elem='asset', ID=value ) ''' nim_assetID = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_assetID", nim_assetID) if success: nim.set_ID(elem='asset', ID=nim_assetID.Get()) P.error('Reading nim_assetID') else: P.error('Failed reading nim_assetID') # File ID : ''' if mc.attributeQuery( 'defaultRenderGlobals.nim_fileID' ) : value=mc.attributeQuery( 'nim_fileID', node='defaultRenderGlobals' ) P.debug( 'Class = %s' % value ) nim.set_tab( tab=value ) ''' #TODO: Check if Maya code is error or intentional nim_fileID = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_fileID", nim_fileID) if success: #nim.set_ID( elem='file', ID=nim_fileID.Get() ) #nim.set_tab( tab=nim_fileID.Get() ) #P.error('Reading nim_fileID') pass else: P.error('Failed reading nim_fileID') # Shot/Asset Name : ''' if mc.objExists( 'defaultRenderGlobals.nim_name' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_name' ) # Determine what the tab is set to : if nim.tab()=='SHOT' : P.debug( 'Shot Name = %s' % value ) # No corresponding NIM attribute : #nim.set_tab( value ) elif nim.tab()=='ASSET' : P.debug( 'Asset Name = %s' % value ) # No corresponding NIM attribute : #nim.set_tab( value ) ''' nim_name = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_name", nim_name) if success: if nim.tab() == 'SHOT': P.debug('Shot Name = %s' % nim_name.Get()) #nim.set_tab( nim_name.Get() ) elif nim.tab() == 'ASSET': P.debug('Asset Name = %s' % nim_name.Get()) #nim.set_tab( nim_name.Get() ) else: P.error('Failed reading nim_name') # Basename : ''' if mc.objExists( 'defaultRenderGlobals.nim_basename' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_basename' ) P.debug( 'Basename = %s' % value ) nim.set_name( elem='base', name=value ) ''' nim_basename = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_basename", nim_basename) if success: nim.set_name(elem='base', name=nim_basename.Get()) P.error('Reading nim_basename') else: P.error('Failed reading nim_basename') # Task : ''' if mc.objExists( 'defaultRenderGlobals.nim_type' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_type' ) P.debug( 'Task = %s' % value ) nim.set_name( elem='task', name=value ) ''' nim_type = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_type", nim_type) if success: nim.set_name(elem='task', name=nim_type.Get()) P.error('Reading nim_type') else: P.error('Failed reading nim_type') # Task ID : ''' if mc.objExists( 'defaultRenderGlobals.nim_typeID' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_typeID' ) P.debug( 'Task ID = %s' % value ) nim.set_ID( elem='task', ID=value ) ''' nim_typeID = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_typeID", nim_typeID) if success: nim.set_ID(elem='task', ID=nim_typeID.Get()) P.error('Reading nim_typeID') else: P.error('Failed reading nim_typeID') # Task Folder : ''' if mc.objExists( 'defaultRenderGlobals.nim_typeFolder' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_typeFolder' ) P.debug( 'Task Folder = %s' % value ) nim.set_taskFolder( folder=value ) ''' nim_typeFolder = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_typeFolder", nim_typeFolder) if success: nim.set_taskFolder(folder=nim_typeFolder.Get()) P.error('Reading nim_typeFolder') else: P.error('Failed reading nim_typeFolder') # Tag : ''' if mc.objExists( 'defaultRenderGlobals.nim_tag' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_tag' ) P.debug( 'Tag = %s' % value ) nim.set_name( elem='tag', name=value ) ''' nim_tag = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_tag", nim_tag) if success: nim.set_name(elem='tag', name=nim_tag.Get()) P.error('Reading nim_tag') else: P.error('Failed reading nim_tag') # File Type : ''' if mc.objExists( 'defaultRenderGlobals.nim_fileType' ) : value=mc.getAttr( 'defaultRenderGlobals.nim_fileType' ) P.debug( 'File Type = %s' % value ) nim.set_name( elem='file', name=value ) ''' nim_fileType = MaxPlus.FPValue() success = MaxPlus.Core.EvalMAXScript("rootNodeDataCA.nim_fileType", nim_fileType) if success: nim.set_name(elem='file', name=nim_fileType.Get()) P.error('Reading nim_fileType') else: P.error('Failed reading nim_fileType') # Print dictionary : #P.info('\nNIM Dictionary from get vars...') #nim.Print() return
import MaxPlus # create a sphere node node_name = "my_sphere" obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Sphere) node = MaxPlus.Factory.CreateNode(obj, node_name) result = MaxPlus.FPValue() # get one FPValue pointer to the object by running some MAXScript evaluation_success = MaxPlus.Core.EvalMAXScript('$%s' % node_name, result) handle1 = result.Get() # get a second pointer to the same object evaluation_success = MaxPlus.Core.EvalMAXScript('$%s' % node_name, result) handle2 = result.Get() # this prints True: print 'Objects are equal: %s' % (handle1 == handle2) # this prints False: print 'Objects are not equal: %s' % (handle1 != handle2) # this prints False: print 'Objects are identical: %s' % (handle1 is handle2) # this prints True: print 'Objects are not identical: %s' % (handle1 is not handle2)
def getBlenderAppPath(): result = MaxPlus.FPValue() evaluation_success = MaxPlus.Core.EvalMAXScript('mcFile.readSettings Micra.UserSettings "Settings/BlenderAppPath"', result) dir = result.Get().rstrip('\\') #remove last slash return dir