Query maya scene info with references

72 views
Skip to first unread message

Utkarsh Agnihotri

unread,
Nov 14, 2023, 11:49:58 AM11/14/23
to Python Programming for Autodesk Maya
Hi, 

I am trying to query Maya scene name and path using

main_scene_file = cmds.file(q=True, sceneName=True)

But it doesn't work when there are references in the scene. Does anyone how can I fix that?

Thanks :)

Marcus Ottosson

unread,
Nov 14, 2023, 5:11:55 PM11/14/23
to python_in...@googlegroups.com

That definitely should work, independent of references. How can I reproduce what you see?

Here’s what I see:

from maya import cmds

# Make an original scene to reference
cmds.polyCube()
cmds.file(rename="referenceMe.ma")
cmds.file(save=True, type="mayaAscii")

# Make a new scene, and reference the original scene
cmds.file(new=True, force=True)
cmds.file("referenceMe.ma", reference=True)
cmds.file(rename="newScene.ma")

fname = cmds.file(query=True, sceneName=True)
assert fname.endswith("newScene.ma")

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f11a3271-498a-4857-8a8b-a12e171086e4n%40googlegroups.com.

Utkarsh Agnihotri

unread,
Nov 14, 2023, 6:09:16 PM11/14/23
to python_in...@googlegroups.com
I have a scene with referenced rig e.g. walk.ma. I am trying query the scene name so that I can export a fbx with same name. How ever, scenes with references are not returning anything.

You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/_avaEPrznr4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODh9pD7iuHHbUG3EfX8VV3ukO-k-R97LqkNSqYNDCFOfA%40mail.gmail.com.

Juan Moraga

unread,
Nov 14, 2023, 10:07:39 PM11/14/23
to python_in...@googlegroups.com
what about: cmds.file(q=True, l=True)[0]?

Marcus Ottosson

unread,
Nov 15, 2023, 3:20:54 AM11/15/23
to python_in...@googlegroups.com

Aha, you are trying to find the path to the referenced file? In that case, Maya maintains each reference in a node of type “reference”. You can then query various properties of this node, including the full path to the file it references.

for reference in cmds.ls(type="reference"):
    fname = cmds.referenceQuery(reference, filename=True)
    print(fname)

Utkarsh Agnihotri

unread,
Nov 15, 2023, 3:48:18 AM11/15/23
to python_in...@googlegroups.com
Hi, no, not for this one. Only file name and path.

Marcus Ottosson

unread,
Nov 15, 2023, 4:32:08 AM11/15/23
to python_in...@googlegroups.com
Hm, then you've got all information.

1. You can find the path to the currently saved file
2. You can find the path to any referenced file in your scene

Is there anything else you are looking for? Can you provide a way to reproduce what you are seeing?

Utkarsh Agnihotri

unread,
Nov 15, 2023, 5:18:56 AM11/15/23
to python_in...@googlegroups.com
Thank you. This one worked :)



--
Kind regards,
Utkarsh Agnihotri

Utkarsh Agnihotri

unread,
Nov 15, 2023, 5:20:47 AM11/15/23
to python_in...@googlegroups.com
Yes, but I was having issue with the command. But Juan' suggestion also worked. 
Thank you for the help.☺️

Juan Moraga

unread,
Nov 15, 2023, 6:36:57 AM11/15/23
to python_in...@googlegroups.com
I'm glad it worked :)



--
Juan Moraga
Supervising Pipeline & Technical Direction @ MondoTV

Portfolio: https://juanmoraga.dev
LInkedin: https://www.linkedin.com/in/juanmoragamartin/
Reply all
Reply to author
Forward
0 new messages