Specifying a File path correctly in MEL/Python

Whenever you write a MEL script or a Python script that contains a file path, you should pay attention to whether it is a relative file path or an absolute file path. In case of POSIX, it is very clear that the path separator is always forward slash (/). In case of Windows, you have to be bit careful on file path separator.

If you specify a path on Windows, you have either to use forward slash (/) or double backward slash (\). Don’t use single back-slash (), because Windows will interpret it as an escape sequence. For example, if you specify a path like “C:\vijay”, Windows will consider it as “C:ijay”, because \v is the escape sequence.

A Maya user faced the same issue when he tried to import the FBX file using the FBXImport command and received an error. The error is caused by the malformed file path, and resulting Windows escape sequence errors. In the end, it has nothing to do with FBXImport command or Maya, but in that context it may be easily overlooked as a formatting error.

Below are the scenarios that will explain the issue more clearly.

— Error Scenario —
string $strDir="C:\vijay\output.fbx";
FBXImport -f $strDir;
// Error: Use syntax: FBXImport -f "filename" [-t take_index_zero_based] [-e extract_folder] //

Fbximport-path-error

 

Working Scenarios

string $strDir="C:\vijay\output.fbx";
FBXImport -f $strDir;
// Logfile: "C:\Users\prakasv\Documents\maya\FBX\Logs\2016.1\maya2016imp.log" //
// Result: Success //

string $strDir="C:/vijay/output.fbx";
FBXImport -f $strDir;
// Logfile: "C:\Users\prakasv\Documents\maya\FBX\Logs\2016.1\maya2016imp.log" //
// Result: Success //


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading