2

i am still learning python so bear with me.

i need to import an fbx file into an existing scene.

i´ve tried multiply ways of importing, tho nothing worked so far.

what i`ve tried:

import maya.cmds as cmds

def setImport():
    setImportPath = 'X:\Path_To_File.fbx'
    cmds.file(setImportPath, i=True, mergeNamespacesOnClash=True, namespace=':');

setImport()

The error i get is:

# Error: RuntimeError: file <maya console> line 5: File not found. # 

Next thing i tried was:

import maya.cmds as cmds

cmds.file( 'X:\Path_To_File.fbx', o = True )    

The error i get is:

# Error: RuntimeError: file <maya console> line 4: File not found: "X:  ath_to_File.fbx" #

Notice the space between the "X:" and the first letter? As well as the missing "P" of "path" ? Why is that? What am i missing here?

The first methode is working perfectly on ma/mb files, tho not with fbx.

Does anyone have an idea on how to solve this?

SOLVED:

I copied the file path from the windows explorer, but windows displays the path with backslashes. I changed the backslashes to slashes and now the fbx import works. silly me!

dave
  • 93
  • 1
  • 12
  • Are you sure `X:\Path_To_File' is really where your file is? Usually it's either C or D – James Maa Sep 26 '17 at 21:10
  • Thanks for the reply: yes, i am sure the file path is correct. it doesnt matter tho, if i try an fbx in a different path, its the same error. – dave Sep 26 '17 at 21:14

2 Answers2

2

I think the somehow the script decode \P as a special character. (Which is really common for almost everything start with backslach \)

Some possible options you can try: X:\\Path_To_File.fbx , X:/Path_To_File.fbx

James Maa
  • 1,764
  • 10
  • 20
1

When using windows paths or paths containing backslashes you can use Python's raw string literal. It will interpret the string "as it is" (backslash will be interpreted just as a backslash character. No special meaning). e.g:

path = r'C:\path\to\file.txt'
matusf
  • 469
  • 1
  • 8
  • 20