使用python或者maxScript批量化操作
2017版本python api使用说明:https://help.autodesk.com/view/3DSMAX/2017/ENU/?guid=__py_ref_classes_html
3dmax相关操作方法主要存储在MaxPlus包,因此使用前需先import MaxPlus
导入包
批量导入模型脚本(python语法):
import MaxPlus
import os
dir_path = r"F:Downloads2023040420230404obj0331databuilding"
for root, dirs, files in os.walk(dir_path):
for file in files:
if '.obj' in file:
#print('building num :', file[:-4])
#print('11',str(os.path.join(root, file)))
MaxPlus.FileManager.Import(os.path.join(root, file),False)
for i in range(MaxPlus.SelectionManager.GetCount()):
MaxPlus.SelectionManager.GetNode(i).Name =file[:-4] + '_'+ MaxPlus.SelectionManager.GetNode(i).Name
批量修改模型名称脚本(maxscript语法)
modelFileDir = "F:Downloads2023040420230404定版地块obj0331data7-2424.obj"
prefix = "24_"
importfile modelFileDir #noPrompt
for i=1 to $selection.count do(
$selection[i].name = prefix+ $selection[i].name
)
然后按下快捷键Ctrl+E执行。
3dmax2023版本后开始pymxs代替了原有的MaxPlus
2023版本python api使用说明:https://help.autodesk.com/view/MAXDEV/2023/ENU/?guid=MAXDEV_Python_using_pymxs_html
批量导入模型脚本(python语法)
import os
import pymxs
from pymxs import runtime as rt
dir_path = r"F:Downloads2023040420230404obj0331databuilding" for root, dirs, files in os.walk(dir_path): for file in files: if '.obj' in file: rt.importFile(os.path.join(root, file),rt.Name('noPrompt')) for i in range(len(rt.selection)): rt.selection[i].name =file[:-4] + '_'+ rt.selection[i].name
3dmax2023版本使用python输出所有对象信息
import os
import pymxs
from pymxs import runtime as rt
file_name = r"F:Document3dsMaxexportbatchExportoutput_pos.txt"
for i in range(len(rt.selection)):
data_list = [str(i), rt.selection[i].name.replace(' ','_'),str(rt.selection[i].center.x),str(rt.selection[i].center.y),str(rt.selection[i].center.z),str(rt.selection[i].max.x - rt.selection[i].min.x ),str(rt.selection[i].max.y - rt.selection[i].min.y), str(rt.selection[i].max.z - rt.selection[i].min.z)]
content = ' '.join(data_list)
print(content)
with open(file_name,'a+',encoding='utf-8')as file:
file.write(content+ 'n')
使用maxscript直接获取选择对象的相关属性:
select $*路灯* 选择对象
$.center (模型中心点) $.position (模型位置,也就是pivot锚点的位置,与pos相同) $.pos (与position相同)
$.scale 获取缩放比例 $.transform 获取结果前三个数组为旋转矩阵,最后一个数组为位置
$.rotation 获取二元数
$.rotation.x_rotation 获取角度 $.rotation.y_rotation $.rotation.z_rotation
使用python操作获取模型相关属性
https://help.autodesk.com/view/MAXDEV/2023/ENU/?guid=MAXDEV_Python_using_pymxs_pymxs_objects_html
模型操作
模型绕任意一点旋转
选中模型,点击仅仅影响轴,使用移动功能,将轴移动到控制点位置,然后,取消仅影响轴,然后使用旋转功能,旋转模型
将多个模型合并为一个:
选择一个待合并的模型,然后点击attach,再旋转需要合并的模型