-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
21 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,19 +218,18 @@ static string make_python_import_reload_wrapper(string python_filepath) | |
/// Jeff Hanna, [email protected], November 22, 2019 | ||
|
||
string mod_name = Path.GetFileNameWithoutExtension(python_filepath); | ||
string reload_cmd = String.Format("import contextlib\nimport importlib\nwith contextlib.suppress(NameError):\n\timportlib.reload({0})", | ||
mod_name); | ||
var reload_wrapper_filepath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "import_reload.py"); | ||
string reload_cmd = String.Format("import imp\ntry:\n\timp.reload({0})\nexcept:\n\tpass", mod_name); | ||
var reload_wrapper_filepath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "import_reload.py"); | ||
System.IO.File.WriteAllText(reload_wrapper_filepath, reload_cmd); | ||
|
||
return reload_wrapper_filepath; | ||
return reload_wrapper_filepath; | ||
} | ||
|
||
|
||
static string make_python_wrapper(string python_filepath) | ||
{ | ||
/// For the python file being executed in 3ds Max this script writes a Maxscript wrapper file | ||
/// that can be called to reimport that Python module so that the in-memory version is updated with | ||
/// that can be called to reimport that Python module so that the in-memory version is updated with | ||
/// any changes made between script executions. | ||
/// | ||
/// **Arguments:** | ||
|
@@ -252,7 +251,7 @@ static string make_python_wrapper(string python_filepath) | |
string reload_filepath = make_python_import_reload_wrapper( python_filepath ); | ||
string cmd = String.Format("python.ExecuteFile(\"{0}\");python.ExecuteFile(\"{1}\")", reload_filepath, python_filepath); | ||
var wrapper_filepath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "maxscript_python_wrapper.ms"); | ||
System.IO.File.WriteAllText(wrapper_filepath, cmd); | ||
System.IO.File.WriteAllText(wrapper_filepath, cmd); | ||
|
||
return wrapper_filepath; | ||
} | ||
|
@@ -291,7 +290,7 @@ static string mxs_try_catch_errors_cmd(string filepath) | |
/// For python files, use passed filepath for location msg, no pos or line available | ||
location = String.Format("\"Error; filename: {0}\"", filepath); | ||
|
||
/// Pass thru python.ExecuteFile() | ||
/// Pass thru python.ExecuteFile() | ||
string reload_filepath = make_python_import_reload_wrapper( filepath ); | ||
run_cmd = String.Format("python.ExecuteFile(\"{0}\");python.ExecuteFile(\"{1}\")", reload_filepath, filepath); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
from pymxs import runtime | ||
|
||
try: | ||
import MaxPlus | ||
except( ImportError ): | ||
import shiboken2 | ||
MaxPlus = None | ||
|
||
from PySide2.QtWidgets import QMainWindow, QMessageBox, QWidget | ||
import shiboken2 | ||
|
||
|
||
def main( ): | ||
main_window_widget = QWidget.find( runtime.windows.getMAXHWND( ) ) | ||
main_window = shiboken2.wrapInstance( shiboken2.getCppPointer( main_window_widget )[ 0 ], QMainWindow ) | ||
msg_box = QMessageBox( main_window ) | ||
if MaxPlus: | ||
main_window = MaxPlus.GetQMaxMainWindow( ) | ||
else: | ||
main_window_widget = QWidget.find( int( runtime.windows.getMAXHWND( ) ) ) | ||
main_window = shiboken2.wrapInstance( shiboken2.getCppPointer( main_window_widget )[ 0 ], QMainWindow ) | ||
|
||
msg_box = QMessageBox( main_window ) | ||
msg_box.setText( 'Hello World!' ) | ||
msg_box.show( ) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
main( ) | ||
|