def _script_version_all_up():
  import nuke
  import nukescripts
  for n in nuke.allNodes( 'Write' ):
    n['selected'].setValue ( True )
  nukescripts.version_up()
  nukescripts.script_version_up()
  for n in nuke.allNodes():
    n['selected'].setValue( False )
def publishScript(entityRef, context=None, versionUp=False, tagScript=True):

    item = items.NukeScriptItem()
    try:
        item.path = nuke.scriptName()
    except RuntimeError:
        item.path = None

    specification = item.toSpecification()

    session = FnAssetAPI.SessionManager.currentSession()
    manager = session.currentManager()

    # First we have to see what the management policy of the manager is
    policy = manager.managementPolicy(specification, context)
    if policy == FnAssetAPI.constants.kIgnored:
        raise RuntimeError(
            "The current asset management system doesn't handle Nuke Scripts (%s)"
            % policy)

    managesPath = policy & FnAssetAPI.constants.kWillManagePath

    # We only need to save a new version if we're not using a path-managing asset
    # system.
    if versionUp and not managesPath:
        nukescripts.script_version_up()
        item.path = nuke.scriptName()

    if not context:
        context = session.createContext()

    entity = None

    with context.scopedOverride():

        context.access = context.kWrite
        context.locale = FnAssetAPI.specifications.DocumentLocale()
        if versionUp:
            context.locale.action = FnAssetAPI.constants.kDocumentAction_SaveNewVersion
        else:
            context.locale.action = FnAssetAPI.constants.kDocumentAction_Save

        with session.scopedActionGroup(context):

            entity = session.getEntity(entityRef, context, mustExist=False)

            # Switch on if its a tracking asset manager, or one that determines paths,
            if managesPath:
                entity = _writeScriptAsset(item, entity, context)
            else:
                entity = _publishScript(item, entity, context)

    if entity and tagScript:
        # We use the temp store as not to mess with the document state
        utils.storeTemporaryRootNodeData('entityReference', entity.reference)

    return entity.reference if entity else ''
Example #3
0
def nextVersion():

    p = nextVersionPanel()
    if p.show():
        #script version up
        nukescripts.script_version_up()
        #writeNode version up and create folder
        for node in nuke.allNodes("Write"):
            name = node.name()
            if p.value(name) == 1:
                node.knob("create next version").execute()
Example #4
0
def nextVersion():
	
	p = nextVersionPanel()
	if p.show():
		#script version up
		nukescripts.script_version_up()
		#writeNode version up and create folder
		for node in nuke.allNodes("Write"):
			name = node.name()
			if p.value(name) == 1:
				node.knob("create next version").execute()
Example #5
0
    def next_subversion(self, path):
        """
        This function is use to Up subVersion
        :param path: path of current file
        :return: None
        """
        vernum = self.vernum_check.findall(path)
        if len(vernum[-1]) == 4:
            # when current file is a main version
            # find last subVersion in this main version

            sub_version = 'v' + str(int(vernum[-1][1:]) + 1).zfill(3) + '001'
            new_version_num = sub_version
            new_path = path.replace(vernum[-1], new_version_num)
            nuke.scriptSaveAs(new_path)

            # set write export to subVersion
            cur_filename = nuke.scriptName()
            publish_export_dir = os.path.dirname(cur_filename)
            if not os.path.exists(publish_export_dir):
                os.makedirs(publish_export_dir)
            file_name = os.path.basename(cur_filename).replace(
                '.nk', '.####.exr')
            for node in nuke.allNodes(filter='Write'):
                if node['name'].getValue() == 'Publish':
                    node['name'].setValue('Write_exr')
                    node['file'].setValue(publish_export_dir + '/render/' +
                                          new_version_num + '/' + file_name)
                    node['file_type'].setValue('exr')
                    return
                else:
                    nuke.message(
                        'Not find Write node named Write_exr,please set the Write node by yourself~'
                    )
        else:
            # when current file is a sub version
            nukescripts.script_version_up()
Example #6
0
def ScriptNameMenuUpBigHug():
    nukescripts.script_version_up()
    nuke.scriptSave()
    Name.NameBigHug()
def main():
    '''
    This script is meant to be run through the nuke commandline.
    It should receive theses sys.argv's:
    arg[0] :: path to this script
    arg[1] :: path to the nuke script to modify
    arg[2] :: Format [width height aspect name] to set for root
    arg[3] :: Create new version of script before saving? : True or False

    If it isn't run through the commandline, there are no special args passed.
    In this case a popup window opens, where the user is asked to make some choices.
    '''

    Log = nkstCC_init._DebugPrint('nkstCC_cmd.main',True)
    Log.msg("number of args: %s"%(len(sys.argv)))

    # Cancel if number of arguments is invalid
    if not len( sys.argv ) > 1:
        Log.msg( "ERROR: Not enough sys.argv's passed to script 'fix_specialcomp.py'. Args passed: %s"%(len ( sys.argv )))
        sys.exit(-1)

    Log.msg("arg0: %s" % sys.argv[0])
    Log.msg("arg1: %s" % sys.argv[1])
    Log.msg("arg2: %s" % sys.argv[2])
    Log.msg("arg3: %s" % sys.argv[3])
    Log.msg("arg4: %s" % sys.argv[4])
    Log.msg("arg5: %s" % sys.argv[5])
    Log.msg("arg6: %s" % sys.argv[6])
    
    pythonScript      = sys.argv[0]
    nukeScript        = sys.argv[1]
    setPrjFormatBool  = ast.literal_eval(sys.argv[2])
    inpFormat         = ast.literal_eval(sys.argv[3])
    delNodesBool      = ast.literal_eval(sys.argv[4])
    autoWriteNodeBool = ast.literal_eval(sys.argv[5])
    versionUpBool     = ast.literal_eval(sys.argv[6]) # True or False

    # Open the Nuke File
    if not os.path.exists(nukeScript):
        Log.msg("Nuke file doesn't exist: %s"%(nukeScript))
        return

    inScript = nukeScript
    Log.msg("Opening script...")
    nuke.scriptOpen( inScript )
    # RUN FUNCTIONS
    # Set Project Format
    if setPrjFormatBool == True:
        try:
            nkstCC_actions.setRootFormat(inpFormat)
        except:
            Log.msg("Failed to set root format.")
    # Delete nodes
    if delNodesBool == True:
        try:
            nkstCC_actions.deleteNodes()
        except:
            Log.msg("Failed to delete nodes...")
    # AutoWriteFolder
    if autoWriteNodeBool == True:
        try:
            nkstCC_actions.AutoWriteFolder()
        except:
            Log.msg("Failed to fix auto write folder.")
    # Save the script
    if versionUpBool == True:
        Log.msg("Saving Script as new version...")
        nukescripts.script_version_up()
    else:
        Log.msg("Saving Script...")
        nuke.scriptSave( inScript )
    Log.msg("Done.")