from pymxs import runtime as rt
import pymxs as mx
# 获取当前帧
rt.currentTime
# 获取时间范围
rt.animationRange
rt.animationRange.start
rt.animationRange.end
# 设置当前帧
rt.sliderTime = 01f
当前文件全路径:os.path.join(rt.maxFilePath, rt.maxFileName)
# 通过名字转换成节点,all为True返回列表,否则返回第一个元素
node = rt.getnodebyname('Bip001', all=True)
node.handle # 返回节点的唯一标识符
node_sel = rt.GetCurrentSelection() # 获取所选节点
node_selrt[0].namespace # 获取属性
# 通过handle 获得节点
rt.maxOps.getNodeByHandle(node.handle)
# 自定义属性
num = rt.custAttributes.count(node)
attr_list = [rt.custAttributes.get(node, i + 1) for i in range(1, num)]
# 添加属性
# 官方解释,无相应Python支持
# https://forums.autodesk.com/t5/3ds-max-programming/pymxs-custom-attributes/td-p/9582854
def create_attribute(node, attr_name, attr_type):
"""Create custom attribute with given name and type."""
create_attr_str = '''attributes Custom_Attributes
(
parameters main rollout:params
(
{0} type:#{1} ui:{0} default:""
)
rollout params "Custom Attributes"
(
edittext {0} "{0}" type:#{1}
)
)'''.format(attr_name, attr_type)
attr = rt.execute(create_attr_str)
rt.custAttributes.add(node, attr)
return attr
# 查询属性
b = box()
b.pos.x
b.setmxsprop(pos.x)
# 设置属性
from pymxs import runtime as rt
node_sel = rt.GetCurrentSelection() # 获取所选节点
for i in node_sel:
i.setmxsprop('pos', rt.point3(0,0,0))
print(i.pos)
# 选择子物体
macros.run "Scene Explorer" "SESelectChildren"
# 塌陷动画层
rt.actionMan.executeAction(2053995757, "8")
# 显示层的编辑
parent = rt.LayerManager.NewLayerFromName("C")
child = rt.LayerManager.NewLayerFromName("D")
child.setParent(parent)
rt.LayerManager.count
rt.LayerManager.current
layer.setName('new_name')
maxScript 与 python不互通
# 物体选择相关
clearSelection()
select $obj01
selectMore $obj02
select #($obj01, $obj02)
deselect #()
# 名字中有空格的需要用单引号括起来,eg:
# select $'Bip001 R Clavicle'
# 设置关键帧
# $.pos.controller.X_Position.controller.keys[2].time = 115f
# $.pos.controller.X_Position.controller.keys[2].value = 0.2
# 创建空心环
Tube radius1:10 radius2:20 height:20 pos:[0,0,0] isSelected:off
# 重名检查工具
from MaxPlus import Core
from pymxs import runtime as rt
import pymxs as mx
# 获取所有节点
def get_all_nodes(nodes=None):
"""Returns all descendants of a list of nodes.
If None is provided, it will return all nodes in the scene.
Args:
nodes (list[MaxPlus.INode]|None): Nodes from which to find descendants.
Returns:
list[MaxPlus.INode]: List of all nodes.
"""
all_nodes_list = []
if nodes is None:
nodes = Core.GetRootNode().Children
for node in nodes:
if node.GetNumChildren():
all_nodes_list.extend(get_all_nodes(node.Children))
all_nodes_list.append(node)
return all_nodes_list
def get_same_name_node_list():
same_name_list = []
same_name_node_list = []
all_node_name = set(i.NodeName for i in get_all_nodes())
for i in all_node_name:
node_list = rt.getnodebyname(i, all=True)
if len(node_list) > 1:
same_name_list.append(i)
same_name_node_list.extend([node.handle for node in node_list])
return same_name_list, same_name_node_list
def check_same_name()
same_name_list, same_name_node_list = get_same_name_node_list()
if same_name_list:
return False, '以下是具有重名列表:{}, handle分别是:{}'.format(', '.join(same_name_list), ', '.join(same_name_node_list)), False
# 获取max主窗口
def get_main_window():
# 3dsmax 2017 version: 19000
if rt.maxVersion()[0] > 20000:
import shiboken2
widget = QtWidgets.QWidget.find(rt.windows.getMAXHWND())
max_main_window = shiboken2.wrapInstance(
shiboken2.getCppPointer(widget)[0], QtWidgets.QMainWindow)
return max_main_window
# 3dsmax 2018 version: 20000
elif 20000 >= rt.maxVersion()[0] > 19000:
import MaxPlus
from PySide2 import shiboken2
maxWinHwd = MaxPlus.QtHelpers.GetQmaxMainWindow()
return shiboken2.wrapInstance(int(maxWinHwd), QtWidgets.QWidget)
else:
import MaxPlus
return MaxPlus.GetQMaxWindow()
# 根据类型获取节点列表
def get_node_by_type(type_name):
result = []
node_list = getChildren(rt.rootnode)
for node in node_list:
if str(rt.classOf(node)) == type_name:
result.append(node)
return result
# python调用maxscript
from pymxs import runtime as rt
max_script_path = os.environ['MAX_SCTIPT_PATH']
script_file = os.path.join(max_script_path, script_name+'.ms')
script_file = script_file.replace('\\', '/')
rt.execute("fileIn \"{}\"".format(script_file))
maxscript 获取环境变量
systemTools.getEnvVariable "3dsmax_setup_root"
初始化文件 | 3ds Max 2020 | Autodesk Knowledge Network
从命令行运行脚本 | 3ds Max 2021 | Autodesk Knowledge Network
插件读取配置:Plugin.UserSettings.ini
脚本路径配置:3dsmax.ini