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
On Sun, Sep 7, 2014 at 4:36 PM, likage <[email protected]> wrote:
> 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?
>
>
>
> On Friday, September 5, 2014 7:51:00 PM UTC+8, Justin Israel wrote:
>>
>> 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.
>> On 5/09/2014 10:31 PM, "likage" <[email protected]> wrote:
>>
>>> 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?
>>>
>>>
>>> On Friday, September 5, 2014 5:39:42 PM UTC+8, Marcus Ottosson wrote:
>>>>
>>>> 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
>>>>
>>>>
>>>>
>>>> On 5 September 2014 11:15, likage <[email protected]> wrote:
>>>>
>>>>> 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 <[email protected]> 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 [email protected].
>>>>>>> To view this discussion on the web visit
>>>>>>> https://groups.google.com/d/msgid/python_inside_maya/da15307
>>>>>>> 3-a8e6-441d-868c-2bde8da819a6%40googlegroups.com
>>>>>>> <https://groups.google.com/d/msgid/python_inside_maya/da153073-a8e6-441d-868c-2bde8da819a6%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>> .
>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> *Marcus Ottosson*
>>>>>> [email protected]
>>>>>>
>>>>> --
>>>>> 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 [email protected].
>>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>>> msgid/python_inside_maya/ddc0b57b-f83a-4c23-8640-161255e4af94%
>>>>> 40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/python_inside_maya/ddc0b57b-f83a-4c23-8640-161255e4af94%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> *Marcus Ottosson*
>>>> [email protected]
>>>>
>>> --
>>> 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 [email protected].
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/python_inside_maya/e30bd554-bd7a-400b-8a6b-
>>> 7c2250d67e43%40googlegroups.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/e30bd554-bd7a-400b-8a6b-7c2250d67e43%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/2bc75aba-5f12-46ca-a3e8-421395d39cbf%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/2bc75aba-5f12-46ca-a3e8-421395d39cbf%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1aFkD-BW3V%3DgrznnuBEqDnb8%3D1K%2B36fp9xtfwPc-e-pA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.