1

I'm actually working on a script to convert a very basic Maya .ma scene to Nuke .nk project using Maya batch mode (mayapy.exe)

I have found how to select, search infos from camera but I don't know how to export them in a text file, as a text file with .nk extention works in Nuke. For the moment I use this to export the camera as FBX :

outputFilename = os.path.splitext(current)[0]+'.fbx'
    print "Output file: ", outputFilename

cmds.file(outputFilename, exportSelected=True, typ="FBX export", force=True, options="v=0;", es=1)

But that cant work for text file or .nk file as Maya doesn't have this option in export settings. Any idea how I can specify to write in a text file with the .nk extention ?

Thank you.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
William Eguienta
  • 135
  • 1
  • 13
  • As much as I knwo there is no nuke .nk exporter for maya. So the only solution is to find a script which already does what you want or write your own. That means you need to open a text file and fill it with the appropriate data from maya. – haggi krey Apr 02 '18 at 13:02
  • yes that's exactly my question, how to create a text file ? i know how to create the content but not the file itself there is no .nk file but as a nuke .nk file is just a text file with .nk extention – William Eguienta Apr 03 '18 at 17:25

1 Answers1

2

For batch conversion use a syntax like this to accomplish fbx export:

import maya.mel as mel

mel.eval('FBXExport -f "/Users/swift/Desktop/fileName";')

You'll get fileName.fbx file on your Desktop.

...or simply write what you want into .nk file...

fileName = "/Users/swift/Desktop/fileName.nk"

# pass in 'r' for reading a file
# pass in 'r+' for reading and writing a file
# pass in 'w' for overwriting the file
# pass in 'a' for appending to the file

fileWrite = open(fileName,'w')

# write here a content of .nk file
fileWrite.write('Hello, NUKE! ...blah, blah, blah...') 
fileWrite.close()

You'll get fileName.nk file on your Desktop.


For non-batch conversion use the code like this:

from pymel.core import *

fileName = fileDialog2()
print fileName[0]
fileWrite = open(fileName[0],'w')

# write here a content of .nk file
fileWrite.write('Hello, NUKE') 
fileWrite.close()
print open(fileName[0],'r').read()

In opened dialog box just type fileName with .nk extension. And you'll get .nk ASCII file.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • the base work well but as i use other command to determine finename, i cant use your line `fileName = "/Users/swift/Desktop/fileName.nk"` i use : `fileWrite = open(filename+'.nk', 'w')` and it result `aname.ma.nk` any idea to remove the .ma from it ? (even a minus 3 caractere can do the job) – William Eguienta Apr 24 '18 at 10:02
  • 1
    You need a replace command. Here are some examples: https://stackoverflow.com/questions/4128144/replace-string-within-file-contents – Andy Jazz Apr 24 '18 at 10:20