script for automatically loading reference files from different destinations in Maya

zingy

Hi a beginner in writing python scripts for Maya. I am trying to write a script that automates the process of opening a Maya file along with its references. Usually when the parent file and reference files are in different destinations Maya cannot open a file being referenced and you have to browse the filename to open it. I am trying to automate this. When a user tries to open a file it should open with all its references. So far I have got this but the main part is what I am confused about.

import pymel.api as api

def callFunc():
    print "hello world" # just a print cmd to check

print "registering a file reference call back"
cb = api.MSceneMessage_addCallback(api.MSceneMessage.kAfterOpen, callFunc())

def callbackOff():
    api.MSceneMessage.removeCallback(cb)

So when the function callFunc() is called, this is where all the action happens. Now I don't know how to proceed.

fredrik

Unless there's a specific reason to use pymel, I'd go with regular Maya commands:

import maya.cmds as cmds
import os

def openFileAndRemapRefs():
    multipleFilters = "Maya Files (*.ma *.mb);;Maya ASCII (*.ma);;Maya Binary (*.mb);;All Files (*.*)"

    # Choose file to open
    filename = cmds.fileDialog2(fileFilter=multipleFilters, dialogStyle=2, fileMode=1)

    # Open file with no reference loaded
    cmds.file( filename[0], open=True, force=True );

    # Dir containing the references
    refDir = 'C:/References'

    # A list of any references found in the scene
    references = cmds.ls(type='reference')

    # For each reference found in scene, load it with the path leading up to it replaced
    for ref in references:
        refFilepath = cmds.referenceQuery(ref, f=True)
        refFilename = os.path.basename( refFilepath )       
        print 'Reference ' + ref + ' found at: ' + cmds.referenceQuery(ref, f=True)   
        cmds.file( os.path.join(refDir, refFilename), loadReference=ref, options='v=0;')

openFileAndRemapRefs()

For more options on fileDialog2 and file, check out the Maya Python docs at http://download.autodesk.com/global/docs/maya2014/en_us/CommandsPython/index.html

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Renaming named destinations in PDF files

From Dev

how to output multiple files from a set of different input files for a python script in bash

From Dev

How to set different destinations in nodejs using multer?

From Dev

loading data from json files

From Dev

Apps Script - Automatically Delete Files from Google Drive Older than 3 Days - Get List of Files

From Dev

Loading different Javascript files in Rails based on environment

From Dev

Writing same Spark Streaming Output to different destinations

From Dev

Run a script with different input files

From Dev

Loading classes from a set of files

From Dev

Multer : Setting different destinations in the destination Property

From Dev

Array sorting algorithm for different destinations

From Dev

Loading Custom Configuration Section from DLL Reference

From Dev

Posting form data to 2 different destinations

From Dev

Loading different objects from file

From Dev

script to remove redundant lines from two different files

From Dev

Loading different versions of Jquery files

From Dev

Loading images from different folders

From Dev

Run a script with different input files

From Dev

Receive multiple files from pipe and write to different destinations

From Dev

Loading panels from different files

From Dev

open ssh server files automatically with apple script

From Dev

Loading Custom Configuration Section from DLL Reference

From Dev

JSDOM not loading script files in Node

From Dev

How variable different from the reference?

From Dev

How to make a script that copies files from different subject folders?

From Dev

Set maya project from an external script

From Dev

Loading different module for Webpack than Server Script

From Dev

ARKit - Error loading DAE file exported from Maya

From Dev

Script to Delete various files from different subfolder?

Related Related

  1. 1

    Renaming named destinations in PDF files

  2. 2

    how to output multiple files from a set of different input files for a python script in bash

  3. 3

    How to set different destinations in nodejs using multer?

  4. 4

    loading data from json files

  5. 5

    Apps Script - Automatically Delete Files from Google Drive Older than 3 Days - Get List of Files

  6. 6

    Loading different Javascript files in Rails based on environment

  7. 7

    Writing same Spark Streaming Output to different destinations

  8. 8

    Run a script with different input files

  9. 9

    Loading classes from a set of files

  10. 10

    Multer : Setting different destinations in the destination Property

  11. 11

    Array sorting algorithm for different destinations

  12. 12

    Loading Custom Configuration Section from DLL Reference

  13. 13

    Posting form data to 2 different destinations

  14. 14

    Loading different objects from file

  15. 15

    script to remove redundant lines from two different files

  16. 16

    Loading different versions of Jquery files

  17. 17

    Loading images from different folders

  18. 18

    Run a script with different input files

  19. 19

    Receive multiple files from pipe and write to different destinations

  20. 20

    Loading panels from different files

  21. 21

    open ssh server files automatically with apple script

  22. 22

    Loading Custom Configuration Section from DLL Reference

  23. 23

    JSDOM not loading script files in Node

  24. 24

    How variable different from the reference?

  25. 25

    How to make a script that copies files from different subject folders?

  26. 26

    Set maya project from an external script

  27. 27

    Loading different module for Webpack than Server Script

  28. 28

    ARKit - Error loading DAE file exported from Maya

  29. 29

    Script to Delete various files from different subfolder?

HotTag

Archive