FXTD-ODYSSEY / vscode-mayapy

Visual Studio Code Extension for Autdoesk Maya Python Developer
MIT License
38 stars 10 forks source link

Problem when using __file__ #1

Closed michaden18 closed 4 years ago

michaden18 commented 4 years ago

Hello, i found a bug when i try to find a path for my file using os.path.abspath(os. file ). it work perfectly when i using terminal, but i notice this package will run the script from Local/Temp folder...so, might be become a problem?

Error: line 1: NameError: file C:/Users/*****/AppData/Local/Temp/MayaCode.py line 6: name 'file' is not defined

Capture

FXTD-ODYSSEY commented 4 years ago

Thanks for your Bug Reporting. I try to run your code to hit the same error. however, I run the code in Maya2019 | Maya2018 | Maya2017. They both work fine without any problems.

test

Maybe you should open the temp folder MayaCode.py to check the python code there.

You also can try to delete the MayaCode.py file. The extension will automatically generate a same file.

here is the correct MayaCode.py code run in my machine

# -*- coding: utf-8 -*-

current_directory = r"d:\Users\82047\Desktop"
if current_directory not in sys.path:
    sys.path.insert(0,current_directory)

print("\nMayaPy Python Debugger : debug test module\n")
if 'test' not in globals():
    import test
else:
    reload(test)
michaden18 commented 4 years ago

thank you for your response. my MayaCode.py in temp folder is exactly the same like what i write in test.py . so maybe that's the reason why it losing the connection using file .

this is MayaCode.py

# -*- coding: utf-8 -*-
import os
path = os.path.abspath(__file__)
print(path)

for example if i change my test.py into :

from maya import cmds
cmds.polyCube()

the MayaCode.py will generate the newest code i execute. (the cmds.polyCube()'s version)

FXTD-ODYSSEY commented 4 years ago

That's weird. MayaCode.py should not just copy the code into the py file. Because that would not trigger the ptvsd python debug module.(only import would make it work) I guess you are using the MayaCode extension send to maya feature not the MayaPy extension debug feature.

image

michaden18 commented 4 years ago

i see! yeah i think it happen because i'm using "Send Python Code to Maya". thank you!