Prompt a UI when a certain format is imported

60 views
Skip to first unread message

likage

unread,
Sep 5, 2014, 4:25:05 AM9/5/14
to python_in...@googlegroups.com
I am pretty new to Maya Api and I am in the midst of editing or changing a code for this custom plugin. I was wondering if it is possible for the following scenario:

  • User import in a particular file format - .chan (Using File >> Import), assumingly the plugin is working?
  • Upon importing, an UI will be prompted when Maya 'detects' that user imports in this .chan format
  • In this UI, it will be doing some other stuff..

So my question would be the first 2 points, how do i code it in such a way that if this .chan format was imported and it will prompt up another ui?

Marcus Ottosson

unread,
Sep 5, 2014, 4:50:17 AM9/5/14
to python_in...@googlegroups.com
Hi likage,

One way you might be able to achieve this is by replacing the Import menu item with your own, and do your checking from there. If it isn't a chan file, simply revert to Maya's defaults.

Another way might be to have users use another button, such as "Import Chan". This button would then be within your control, and you could pop up your UI from there.

Finally, you could try and get Maya to notify you whenever it imports a file and for you to intercept what it is about to do next. If it's a chan file, mute Maya and take over. Otherwise, let it pass. This is what I take it you are attempting to do with the API, however I'd be careful about it and instead try any of the two above approaches first. Simply because altering the internal behaviour of Maya isn't always a good idea as you might break things that Maya does on its own, such as when you paste curves via the Channel Box.

Best,
Marcus


--
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/da153073-a8e6-441d-868c-2bde8da819a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

likage

unread,
Sep 5, 2014, 5:06:19 AM9/5/14
to python_in...@googlegroups.com
Hi Marcus,

Thank you for getting back to me. Hmm, I think I will try out the button method as I hardly have any ideas to do the other methods you have suggested (mute the Maya etc.)

Right now I am in the midst of trying to figure how this code that I have managed to download from the web (could hardly figure it out what the developer was doing; most probably cause I do not have a solid understanding of the API stuff :x) and to rewrite it if possible and without the use of API since I am weak in it. But nonetheless, using this link as the example, should I be using API I was wondering if I could code it in the following manner:
  • Create a new class or function def xxx() for the chan importer and other functions, UI etc
  • Have the functions all dropped into the scripted command?

It will be something like this (Pardon for the very vague code):

class scriptedCommand(OpenMayaMPx.MPxCommand):
    def __init__(self):
        OpenMayaMPx.MPxCommand.__init__(self)
        actionA()
actionB() def actionA(): ...

def actionB():
    ...



On Friday, September 5, 2014 4:50:17 PM UTC+8, Marcus Ottosson wrote:
Hi likage,

One way you might be able to achieve this is by replacing the Import menu item with your own, and do your checking from there. If it isn't a chan file, simply revert to Maya's defaults.

Another way might be to have users use another button, such as "Import Chan". This button would then be within your control, and you could pop up your UI from there.

Finally, you could try and get Maya to notify you whenever it imports a file and for you to intercept what it is about to do next. If it's a chan file, mute Maya and take over. Otherwise, let it pass. This is what I take it you are attempting to do with the API, however I'd be careful about it and instead try any of the two above approaches first. Simply because altering the internal behaviour of Maya isn't always a good idea as you might break things that Maya does on its own, such as when you paste curves via the Channel Box.

Best,
Marcus
On 5 September 2014 10:25, likage <dissid...@gmail.com> wrote:
I am pretty new to Maya Api and I am in the midst of editing or changing a code for this custom plugin. I was wondering if it is possible for the following scenario:

  • User import in a particular file format - .chan (Using File >> Import), assumingly the plugin is working?
  • Upon importing, an UI will be prompted when Maya 'detects' that user imports in this .chan format
  • In this UI, it will be doing some other stuff..

So my question would be the first 2 points, how do i code it in such a way that if this .chan format was imported and it will prompt up another ui?

--
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_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

likage

unread,
Sep 5, 2014, 5:15:03 AM9/5/14
to python_in...@googlegroups.com
Sorry, another question to my previous reply.

Is it possible to write a code, in this case I am trying to ask Maya to import in a new file format that it was initially not compatible with, simply with python or mel coding without the use of API?



On Friday, September 5, 2014 4:50:17 PM UTC+8, Marcus Ottosson wrote:
Hi likage,

One way you might be able to achieve this is by replacing the Import menu item with your own, and do your checking from there. If it isn't a chan file, simply revert to Maya's defaults.

Another way might be to have users use another button, such as "Import Chan". This button would then be within your control, and you could pop up your UI from there.

Finally, you could try and get Maya to notify you whenever it imports a file and for you to intercept what it is about to do next. If it's a chan file, mute Maya and take over. Otherwise, let it pass. This is what I take it you are attempting to do with the API, however I'd be careful about it and instead try any of the two above approaches first. Simply because altering the internal behaviour of Maya isn't always a good idea as you might break things that Maya does on its own, such as when you paste curves via the Channel Box.

Best,
Marcus
On 5 September 2014 10:25, likage <dissid...@gmail.com> wrote:
I am pretty new to Maya Api and I am in the midst of editing or changing a code for this custom plugin. I was wondering if it is possible for the following scenario:

  • User import in a particular file format - .chan (Using File >> Import), assumingly the plugin is working?
  • Upon importing, an UI will be prompted when Maya 'detects' that user imports in this .chan format
  • In this UI, it will be doing some other stuff..

So my question would be the first 2 points, how do i code it in such a way that if this .chan format was imported and it will prompt up another ui?

--
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_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Sep 5, 2014, 5:39:42 AM9/5/14
to python_in...@googlegroups.com

Is it possible to write a code, in this case I am trying to ask Maya to import in a new file format that it was initially not compatible with, simply with python or mel coding without the use of API?

Yes, you can pop up your own File Dialog, like this:

multipleFilters = "Maya (*.ma *.mb);;Custom (*.custom)"
cmds.fileDialog2(fileFilter=multipleFilters, dialogStyle=2)

From the documentation, found here:
http://help.autodesk.com/cloudhelp/2015/ENU/Maya-Tech-Docs/CommandsPython/fileDialog2.html

I’ll try and get back to you regarding your other questions as well, but overall I think all of what you’ve mentioned so far can be accomplished using maya.cmds



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/ddc0b57b-f83a-4c23-8640-161255e4af94%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

likage

unread,
Sep 5, 2014, 6:31:41 AM9/5/14
to python_in...@googlegroups.com
Cool, that will be great! Looking forward to your reply.

By the way, I tried out the fileDialog2 method that you have put up,

multipleFilters = "Maya (*.ma *.mb);;chan (*.chan)"
filename
= cmds.fileDialog2(fileMode=1, fileFilter=multipleFilters, dialogStyle=2)
cmds
.file( filename, i=True, renameAll = True, mergeNamespacesOnClash = False )

Though I am able to select and see the .chan files in the UI, as soon as I hit Enter, I was prompted with the following errors:

# Error: Unrecognized file.
# Traceback (most recent call last):
#   File "<maya console>", line 3, in <module>
# RuntimeError: Unrecognized file. #


So can I assume this cannot be done with just maya.cmds then?
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

--
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_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Sep 5, 2014, 7:40:49 AM9/5/14
to python_in...@googlegroups.com

Though I am able to select and see the .chan files in the UI, as soon as I hit Enter, I was prompted with the following errors:

May I ask what else you were expecting?



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/e30bd554-bd7a-400b-8a6b-7c2250d67e43%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Sep 5, 2014, 7:51:00 AM9/5/14
to python_in...@googlegroups.com

Might help to check the docs
http://download.autodesk.com/global/docs/maya2012/en_us/CommandsPython/fileDialog2.html

Return value: string array

Copy and paste is only going to get you so far. One operation/paste may lead into the next problem if you don't fully understand what the code does and returns.

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/e30bd554-bd7a-400b-8a6b-7c2250d67e43%40googlegroups.com.

likage

unread,
Sep 7, 2014, 12:34:01 AM9/7/14
to python_in...@googlegroups.com
I thought it is working if it can be done using maya.cmds, however it does not seems to be



--
Marcus Ottosson
konstr...@gmail.com

--
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_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

likage

unread,
Sep 7, 2014, 12:36:56 AM9/7/14
to python_in...@googlegroups.com
Hi Justin, in this case can I presume that this command works, only if the file format is within Maya format preset list?

Additionally, I am not a pro in such scenarios, but I was wondering if would you happen to know my issue is achievable from using maya.cmds?




--
Marcus Ottosson
konstr...@gmail.com

--
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_maya+unsub...@googlegroups.com.

Justin Israel

unread,
Sep 7, 2014, 5:17:09 AM9/7/14
to python_in...@googlegroups.com

What I was saying was that if you are going to use the fileDialog approach, as you did, and you see that it returns an error, you would have to make sure that you take a look at the API documentation to confirm that you are using it properly. In this case, the fileDialog returns an array of strings, and you are passing that array to the file() command, which only takes a string. So you end up with an error.

Because you are using a fileDialog command that allows the user to choose one existing file, you will need first check the filename variable to make sure it is set to something and that the user did not cancel the dialog. Because the people that designed the Maya cmds API love and value consistency, you will notice that if the dialog is canceled you get back a None instead of an empty list. Your check would be something like this:

fileList = cmds.fileDialog2(fileMode=1, fileFilter=multipleFilters, dialogStyle=2)
if not fileList:
    # return or print something or bail out early

filename = fileList[0]
cmds.file(filename, i=True)

If you are allowing multiple files:

fileList = cmds.fileDialog2(fileMode=4, fileFilter=multipleFilters, dialogStyle=2)
if not fileList:
    # return or print something or bail out early

for filename in fileList:
    cmds.file(filename, i=True)

At this point, you have control over knowing which file is being imported and having the opportunity of doing pre/post



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/2bc75aba-5f12-46ca-a3e8-421395d39cbf%40googlegroups.com.

likage

unread,
Sep 7, 2014, 9:08:34 AM9/7/14
to python_in...@googlegroups.com
Pardon my noob-ness in this.

Earlier I tried importing, specifically citing for a file format which is .chan
Then as I implemented the bailed-out scenario and your code that you have written, I got the same set of errors that I have posted previously and I am not getting any statement etc.

Still getting the unrecognized file error.

Marcus Ottosson

unread,
Sep 7, 2014, 11:27:01 AM9/7/14
to python_in...@googlegroups.com
likage, perhaps if you told us a little bit about what it is that you want to have happen when you run your code. Tell us about the expected results and what you expect to have happen. Are you looking to import a `.chan` file and have it applied onto a channel of a transform node? Are you looking to make it into a NURBS curve?

At first, I thought your question was about intercepting the import command from the File menu, but that doesn't seem to be the case any more. Until I understand what you are looking for, it's quite difficult to point you in the right direction.

--
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.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

likage

unread,
Sep 7, 2014, 10:10:24 PM9/7/14
to python_in...@googlegroups.com
Hi Marcus, you are right on the first point.

Now what I am trying to achieve is to import in .chan (I'm trying to rewrite the whole script) just by using maya.cmds and without the use of maya api. I apologized if I have been going in rounds without making myself clear, as I have been lost myself too.

Thus right now I am trying to ditch this API coding since I am not familiar with, and trying to do it using the maya.cmds method. So far, just for the importing of this .chan file, I have met with errors which are depicted in my previous posts - Unrecognized format etc.

This is the coding that I have done so far:
multipleFilters = "chan (*.chan)"

fileList
= cmds.fileDialog2(fileMode=1, fileFilter=multipleFilters, dialogStyle=2)

with open (fileList[0], 'rt') as filehandle:
     
for line in filehandle:
         
print line

Results of the .chan information
1    -1.95229    0.105858    4.26187    166.513    22.9641    -42.0018    26.9915

2    -1.02854    0.509221    4.16079    -177.631    14.0901    -30.9537    26.9915

But as you can see, I am only printing or getting the camera information, since it is only reading the file info and not creating any node of the said file in the scene.
Thus, are there any ways that I can make it to create a camera node (as .chan is a camera file) and ensure that it is reading the information correctly?
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
Sep 7, 2014, 11:49:32 PM9/7/14
to python_in...@googlegroups.com
You are saying that your problem is not using the dialog and operating on the collected chan files, but rather the ability to translate the chan files into cameras?

If you are specifically asking for a way to import chan files into Maya, I could reference a tool I had written for cmiVFX to do chan file conversions: https://github.com/justinfx/AtomSplitter
You are welcome to cannibalize that. I wrote it over 4 years ago and its not my best work ever :-) But it does convert chan files to FBX which can be imported into Maya. 

I haven't been keeping up on whether there are better ways to do this currently. For all I know there is current support for .chan files or some hot new approach and I am just out of touch. 






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/c48e3724-528b-4027-922b-713dfbcae97d%40googlegroups.com.

likage

unread,
Sep 8, 2014, 11:20:56 PM9/8/14
to python_in...@googlegroups.com
Hmm.. I am not exactly looking for ways to convert the .chan again but ways to import .chan into Maya. Initially I had thought this can be done using the fileDialog2 command and importing in the animation while creating a camera in maya itself.

I will try and see if I can implement the code you have provided.

Thank you!
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

--
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_maya+unsub...@googlegroups.com.

Justin Israel

unread,
Sep 9, 2014, 2:14:35 AM9/9/14
to python_in...@googlegroups.com

If Maya natively supports importing Chan files as cameras, then I didn't know that and you can ignore my suggestion ☺

That tool was written at a time when the desire was to be able to import Chan files produced by Nuke into multiple target applications like Maya, Flame/Inferno, and a couple other ones.

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/01c38f49-b0f8-416a-a71f-00d544d84c75%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages