Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 2.15 KB

File metadata and controls

71 lines (52 loc) · 2.15 KB

HowTo: transformlock

Original MaxScript Tutorial Source Code

Goals:

  • learn how to call a function in pymxs
  • learn how to hook a Python function to a 3ds Max ui element

Explanations

The shows how to create a minimal Python tool for 3ds Max. This tools adds a menu item to the Scripting menu to lock all transformations on the selection.

Using the tool

From the 3ds Max listener window we can do:

import transformlock

transformlock.startup()

If we install this sample as a pip package it will be automatically started during the startup of 3ds Max (because it defines a startup entry point for 3ds Max).

Understanding the code

We first import menuhook. This package provides an easy way to create a menu item for running a Python function.

import menuhook

We also import pymxs. Pymxs lets Python access the whole MAXScript scripting library.

from pymxs import runtime as rt

The core business logic of the program comes from the lock_selection function. This uses the setTransformLockFlags of (node common methods) to lock all (rt.Name("all") transforms on the whole selection (rt.selection)):

def lock_selection():
    '''Lock all transforms on the selection'''
    rt.setTransformLockFlags(rt.selection, rt.Name("all"))

We then define the startup function. This function will be called by the 3ds Max entry point (if this project is installed as a pip package). We can also call it manually (in the listener window) if we prefer.

def startup():
    """
    Hook the transform lock function to a menu item.
    """
    menuhook.register(
        "transformlock",
        "howtos",
        lock_selection,
        menu=["&Scripting", "Python3 Development", "How To"],
        text="Lock transformations for the selection",
        tooltip="Lock transformations for the selection")