Selective preload of references via script (python)


#1

I have a custom asset management tool, in which I want to be able to use the “Selective preload” option found in the regular Open command in Maya (the one that allows you to set the loaded/unloaded state of any in-going references before opening the file).

If I just use regular cmds.open(filepath, open=True), the box with reference information does not pop up, probably because the query that populates that box takes place before the actual open command (?).

I have a feeling that it must be related to the referenceNode, referenceDepthInfo and/or loadSettings commands (plus more, obviously).

My preferred language is Python, but MEL or PyMel etc is fine too, in case someone has some pointers or other help to offer!

On a related note, I can’t seem to be able to query the references a given file has unless I open the file first, which is obviously not the way to go.
Selective preload option


#2

The following should launch Maya’s PreloadReferenceEditor for your scene file, filepath.

import maya.cmds as cmds
import maya.mel as mel

filepath = '/path/to/my/scene/file.ma'

# Build Maya's implicitLoadSettings
cmds.file(filepath, buildLoadSettings=True, open=True)

# Launch PreloadReferenceEditor GUI
cmds.optionVar(stringValue=('preloadRefEdTopLevelFile', filepath))
mel.eval('PreloadReferenceEditor;')


#3

I am doing the same but for Maya 2017 and these lines dont work in Maya 2017 (If I execute it takes a Fatal Error).

Do you know if is posible to do it in Maya 2017?