Skip to content

Commit 583298e

Browse files
committed
Re-work the Maya dcc integration to use the PREDITOR_SITE env var
1 parent 8c6c820 commit 583298e

File tree

5 files changed

+119
-70
lines changed

5 files changed

+119
-70
lines changed

README.md

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ a better `parent_callback`.
9797
## Installing Qt
9898

9999
PrEditor is built on Qt, but uses [Qt.py](https://github.com/mottosso/Qt.py) so
100-
you can choose to use PySide2 or PyQt5. We have elected to not directly depend
101-
on either of these packages as if you want to use PrEditor inside of a an existing
102-
application like Maya or Houdini, they already come with PySide2 installed. If
103-
you are using it externally, add them to your pip install command.
100+
you can choose to use PySide6, PySide2, PyQt6 or PyQt5. We have elected to not
101+
directly depend on either of these packages so that you can use PrEditor inside
102+
of existing applications like Maya or Houdini that already come with PySide
103+
installed. If you are using it externally add them to your pip install command.
104104

105-
- PySide2: `pip install preditor PySide2`
106-
- PyQt5: `pip install preditor PyQt5`
105+
- PySide6: `pip install preditor PySide6`
106+
- PyQt6: `pip install preditor PyQt6`
107107

108108
## Cli
109109

@@ -125,35 +125,68 @@ this is only useful for windows.
125125
## QScintilla workbox
126126

127127
The more mature QScintilla workbox requires a few extra dependencies that must
128-
be passed manually. It hasn't been added to `extras_require` because we plan to
129-
split it into its own pip module due to it requiring PyQt5 which is a little hard
130-
to get working inside of DCC's that ship with PySide2 by default. Here is the
131-
python 3 pip install command.
128+
be passed manually. We have added it as pip `optional-dependencies`. QScintilla
129+
only works with PyQt5/6 and it is a little hard to get PyQt working inside of
130+
DCC's that ship with PySide2/6 by default. Here is the python 3 pip install command.
132131

133-
- `pip install preditor PyQt5, QScintilla>=2.11.4 aspell-python-py3`
132+
- PyQt6: `pip install preditor[qsci6] PyQt6, aspell-python-py3`
133+
- PyQt5: `pip install preditor[qsci5] PyQt5, aspell-python-py3`
134134

135135
The aspell-python-py3 requirement is optional to enable spell check.
136136

137+
You may need to set the `QT_PREFERRED_BINDING` or `QT_PREFERRED_BINDING_JSON`
138+
[environment variable](https://github.com/mottosso/Qt.py?tab=readme-ov-file#override-preferred-choice) to ensure that PrEditor can use PyQt5/PyQt6.
137139

138140
# DCC Integration
139141

140-
## Maya
141-
142-
PrEditor is pre-setup to use as a Maya module. To use it, create a virtualenv
143-
with the same python as maya, or install it using mayapy.
144-
145-
```
146-
virtualenv venv_preditor
147-
venv_preditor\Scripts\activate
148-
pip install PrEditor
149-
set MAYA_MODULE_PATH=c:\path\to\venv_preditor\Lib\site-packages\preditor\dccs
150-
```
151-
Note: Due to how maya .mod files works if you are using development installs you
152-
can't use pip editable installs. This is due to the relative path used
153-
`PYTHONPATH +:= ../..` in `PrEditor_maya.mod`. You can modify that to use a hard
154-
coded file path for testing, or add a second .mod file to add the virtualenv's
155-
`site-packages` file path as a hard coded file path.
156-
142+
Here are several example integrations for DCC's included in PrEditor. These
143+
require some setup to manage installing all pip requirements. These will require
144+
you to follow the [Setup](#setup) instructions below.
145+
146+
- [Maya](/preditor/dccs/maya/README.md)
147+
- [3ds Max](/preditor/dccs/studiomax/README.md)
148+
149+
If you are using hab, you can simply add the path to the [preditor](/preditor) folder to your site's `distro_paths`. [See .hab.json](/preditor/dccs/.hab.json)
150+
151+
## Setup
152+
153+
PrEditor has many python pip requirements. The easiest way to get access to all
154+
of them inside an DCC is to create a virtualenv and pip install the requirements.
155+
You can possibly use the python included with DCC(mayapy), but this guide covers
156+
using a system install of python.
157+
158+
1. Identify the minor version of python that the dcc is using. Running `sys.version_info[:2]` in the DCC returns the major and minor version of python.
159+
2. Download and install the required version of python. Note, you likely only need to match the major and minor version of python(3.11 not 3.11.12). It's recommended that you don't use the windows store to install python as it has had issues when used to create virtualenvs.
160+
3. Create a virtualenv using that version of python. On windows you can use `py.exe -3.11` or call the correct python.exe file. Change `-3.11` to match the major and minor version returned by step 1. Note that you should create separate venvs for a given python minor version and potentially for minor versions of Qt if you are using PyQt.
161+
```batch
162+
cd c:\path\to\venv\parent
163+
py -3.11 -m virtualenv preditor_311
164+
```
165+
4. Use the newly created pip exe to install PrEditor and its dependencies.
166+
* This example shows using PySide and the simple TextEdit workbox in a minimal configuration.
167+
```batch
168+
c:\path\to\venv\parent\preditor_311\Scripts\pip install PrEditor
169+
```
170+
* This example shows using QScintilla in PyQt6 for a better editing experience. Note that you need to match the PyQt version used by the DCC, This may require matching the exact version of PyQt.
171+
```batch
172+
c:\path\to\venv\parent\preditor_311\Scripts\pip install PrEditor[qsci6] PyQt6==6.5.3
173+
```
174+
175+
### Editable install
176+
177+
You should skip this section unless you want to develop PrEditor's code from an git repo using python's editable pip install.
178+
179+
Due to how editable installs work you will need to set an environment variable
180+
specifying the site-packages directory of the virtualenv you created in the
181+
previous step. On windows this should be the `lib\site-packages` folder inside
182+
of the venv you just created. Store this in the `PREDITOR_SITE`, this can be done
183+
permanently or temporarily(via `set "PREDITOR_SITE=c:\path\to\venv\parent\preditor_311\lib\site-packages"`).
184+
185+
This is required because you are going to use the path to your git repo's preditor
186+
folder in the module/plugin loading methods for the the DCC you are using, but
187+
there is no way to automatically find the virtualenv that your random git repo
188+
is installed in. In fact, you may have have your git repo installed into multiple
189+
virtualenvs at once.
157190
158191
# Plugins
159192
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
+ PrEditor DEVELOPMENT .
2-
PYTHONPATH +:= ../..

preditor/dccs/maya/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Maya Integration
2+
3+
This is an example of using an Maya module to add PrEditor into Maya. This adds
4+
a PrEditor menu with a PrEditor action in Maya's menu bar letting you open PrEditor. It
5+
adds the excepthook so if a python exception is raised it will prompt the user
6+
to show PrEditor. PrEditor will show all python stdout/stderr output generated
7+
after the plugin is loaded.
8+
9+
# Setup
10+
11+
Make sure to follow these [setup instructions](/preditor/README.md#Setup) first to create the virtualenv.
12+
13+
Alternatively you can use [myapy's](https://help.autodesk.com/view/MAYAUL/2026/ENU/?guid=GUID-72A245EC-CDB4-46AB-BEE0-4BBBF9791627) pip to install the requirements, but a
14+
separate virtualenv is recommended. This method should not require setting the
15+
`PREDITOR_SITE` environment variable even if you use an editable install.
16+
17+
# Use
18+
19+
The [preditor/dccs/maya](/preditor/dccs/maya) directory is setup as a Maya Module. To load it in
20+
maya add the full path to that directory to the `MAYA_MODULE_PATH` environment
21+
variable. You can use `;` on windows and `:` on linux to join multiple paths together.
22+
You will need to enable auto load for the `PrEditor_maya.py` plugin.

preditor/dccs/maya/plug-ins/PrEditor_maya.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from __future__ import absolute_import
22

3+
import os
4+
import site
5+
from pathlib import Path
6+
37
import maya.mel
48
from maya import OpenMayaUI, cmds
59

@@ -35,12 +39,39 @@ def launch(ignored):
3539
return widget
3640

3741

42+
def update_site():
43+
"""Adds a site dir to python. This makes its contents importable to python.
44+
45+
This includes making any editable installs located in that site-packages folder
46+
accessible to this python instance. This does not activate the virtualenv.
47+
48+
If the env var `PREDITOR_SITE` is set, this path is used. Otherwise the
49+
parent directory of preditor is used.
50+
51+
- `PREDITOR_SITE` is useful if you want to use an editable install of preditor
52+
for development. This should point to a virtualenv's site-packages folder.
53+
- Otherwise if the virtualenv has a regular pip install of preditor you can
54+
skip setting the env var.
55+
"""
56+
venv_path = os.getenv("PREDITOR_SITE")
57+
# If the env var is not defined then use the parent dir of this preditor package.
58+
if venv_path is None:
59+
venv_path = cmds.moduleInfo(moduleName="PrEditor", path=True)
60+
venv_path = Path(venv_path).parent.parent.parent
61+
venv_path = str(venv_path)
62+
63+
print(f"Preditor is adding python site: {venv_path}")
64+
site.addsitedir(venv_path)
65+
66+
3867
def initializePlugin(mobject): # noqa: N802
3968
"""Initialize the script plug-in"""
4069
global preditor_menu
4170

4271
# If running headless, there is no need to build a gui and create the python logger
4372
if not headless():
73+
update_site()
74+
4475
from Qt.QtWidgets import QApplication
4576

4677
import preditor
@@ -67,7 +98,7 @@ def initializePlugin(mobject): # noqa: N802
6798
gmainwindow = maya.mel.eval("$temp1=$gMainWindow")
6899
preditor_menu = cmds.menu(label="PrEditor", parent=gmainwindow, tearOff=True)
69100
cmds.menuItem(
70-
label="Show",
101+
label="PrEditor",
71102
command=launch,
72103
sourceType="python",
73104
image=preditor.resourcePath('img/preditor.png'),

preditor/dccs/studiomax/README.md

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,10 @@ output generated after the plugin is loaded.
88

99
# Setup
1010

11-
PrEditor has many python pip requirements. The easiest way to get access to all
12-
of them is to create a virtualenv and pip install the requirements. You can possibly use the python included with 3ds Max, but this guide covers using a system install of python.
13-
14-
1. Identify the minor version of python that 3ds Max is using. 3ds Max 2025 and 2026 are both using python 3.11. The version of python is printed when you first activate python mode in the Scripting Listener.
15-
2. Download and install the required version of python. Note, you likely only need to match the major and minor version of python(3.11 not 3.11.12). It's recommended that you don't use the windows store to do this as it has had issues when used to create virtualenvs.
16-
3. Create a virtualenv using that version of python. On windows you can use `py.exe -3.11` or call the correct python.exe file.
17-
```batch
18-
cd c:\path\to\venv\parent
19-
py -3.11 -m virtualenv preditor_venv
20-
```
21-
4. Use the newly created pip exe to install PrEditor and its dependencies.
22-
* This example shows using PySide and the simple TextEdit workbox in a minimal configuration.
23-
```batch
24-
c:\path\to\venv\parent\preditor_venv\Scripts\pip install PrEditor
25-
```
26-
* This example shows using QScintilla in PyQt6 for a better editing experience. Note that you need to match the Qt version used by 3ds Max. Both 2025 and 2026 use 6.5.3.
27-
```batch
28-
c:\path\to\venv\parent\preditor_venv\Scripts\pip install PrEditor[qsci6] PyQt6==6.5.3
29-
```
11+
Make sure to follow these [setup instructions](/preditor/README.md#Setup) first to create the virtualenv.
3012

3113
# Use
3214

33-
There are a few environment variables that need to be set. They can be set permanently, but this
34-
example shows setting them temporarily for the current command prompt window.
35-
Note that these paths are referencing the site-packages folder of the virtualenv.
36-
37-
1. Open a command prompt.
38-
2. Set the `ADSK_APPLICATION_PLUGINS` variable. This env var is used by 3ds Max to load the package defined by the PackageContents.xml file. If you are using an editable install of PrEditor, this should point to it's `preditor\dccs\studiomax` folder not inside the virtualenv's site-packages.
39-
```batch
40-
set "ADSK_APPLICATION_PLUGINS=c:\path\to\venv\parent\preditor_venv\Lib\site-packages\preditor\dccs\studiomax"
41-
```
42-
3. Set the `PREDITOR_SITE` variable. This env var is used to make the packages in the virtualenv's site-packages accessible in 3ds Max's python. The virtualenv is only used to handle the pip installations, 3ds Max doesn't activate the virtualenv, it just makes its site-packages folder importable.
43-
```batch
44-
set "PREDITOR_SITE=c:\path\to\venv\parent\preditor_venv\Lib\site-packages"
45-
```
46-
4. Optional: If using QScintilla, you will also need to force Qt.py to load it instead of PySide by setting `QT_PREFERRED_BINDING` or `QT_PREFERRED_BINDING_JSON`.
47-
```batch
48-
set "QT_PREFERRED_BINDING=PyQt6"
49-
```
50-
5. Launch 3ds Max.
51-
```batch
52-
"C:\Program Files\Autodesk\3ds Max 2026\3dsmax.exe"
53-
```
15+
The [preditor/dccs/studiomax](/preditor/dccs/studiomax) directory is setup as a 3ds Max Application Plugin.
16+
To load it in 3ds Max add the full path to that directory to the `ADSK_APPLICATION_PLUGINS` environment
17+
variable. You can use `;` on windows and `:` on linux to join multiple paths together.

0 commit comments

Comments
 (0)