Max导入Ehome便捷插件
1.使用上传得.ms资源,直接拖入max,
2.或者新建一个文本,复制下面代码,另存为.ms文件,也是直接拖入max使用即可
------------------------------------------------------------------------------------------------------------------------------
try(destroyDialog TKT)catch()
rollout TKT "批量导出" width:248 height:544
(
global StartTime
global EndTime
local theClasses = exporterPlugin.classes
local The_INI_Path = ((GetDir #userScripts) + "/N00BY_Scripts/Export_Settings_1_8_3.ini")
local TheChildren = #()
local CollisionMeshes = #()
local MeshesToSelect = #()
local LinkedToDummy = False
global TheSelection = #()
checkbox 'MoveToCenter' "移动到[0,0,0]" pos:[16,62] width:96 height:15 checked:true toolTip:"导出前将对象移动到原点,但保留其当前位置." align:#left
checkbox 'ResetX' "重置变换" pos:[16,86] width:85 height:15 checked:true toolTip:"导出前重置对象几何体。原始对象保持不变。" align:#left
checkbox 'ConvertToEditableMesh' "转换为可编辑网格" pos:[16,110] width:141 height:15 checked:true toolTip:"将对象导出为可编辑网格。这样可以避免一些奇怪的错误,有时原始对象保持不变." align:#left
checkbox 'MergeAllNodes' "合并所有节点" pos:[16,136] width:101 height:15 checked:true align:#left tooltip:"如果作为点辅助对象或虚拟对象的父对象:\请在导出之前合并对象."
checkbox 'NameChange' "更改名称" pos:[16,192] width:91 height:15 toolTip:"将以下字符串添加到导出的对象名称中。场景中对象的名称保持不变." align:#left
edittext 'prefix' "" pos:[10,213] width:70 height:17 align:#left
edittext 'suffix' "" pos:[157,213] width:70 height:17 align:#left
label 'lbl1' "+ 物体名称 +" pos:[86,213] width:68 height:25 align:#left
checkbox 'AddCollision' "添加碰撞" pos:[16,280] width:96 height:15 toolTip:"将具有相同名称和以下前缀的所有网格合并导出每个对象." align:#left
edittext 'UCXMeshName' "前缀" pos:[120,280] width:104 height:17 align:#left text:"UCX_"
dropdownList 'ExportFormat' "格式" pos:[14,385] width:70 height:40 items:#("FBX", "OBJ", "3DS", "DWG", "DXF", "ABC", "SAT", "DAE", "IGS", "W3D", "FLT", "ASE", "DWF", "VRSCENE", "MAX") align:#left
dropdownList 'ExportPaths' "路径" pos:[14,426] width:192 height:40 toolTip:"Right click to open selected folder ;)" align:#left
button 'Browse' "..." pos:[210,444] width:25 height:21 toolTip:"浏览导出文件夹。右击可清除列表" align:#left
button 'Export_Button' "导出所选内容" pos:[8,482] width:232 height:54 toolTip:"导出所选内容." align:#left
GroupBox 'GeometryGroupBox' "几何体" pos:[8,38] width:232 height:122 align:#left
GroupBox 'NameGroupBox' "名称" pos:[8,168] width:232 height:80 align:#left
GroupBox 'CollisionGroupBox' "碰撞" pos:[8,256] width:232 height:56 align:#left
GroupBox 'GeneralGroupBox' "常规" pos:[8,315] width:232 height:159 align:#left
checkbox 'ShowPrompt' "导出前显示提示" pos:[16,338] width:150 height:15 checked:true toolTip:"导出前显示对话框(取决于格式)" align:#left
checkbox 'Show_Dialog' "导出后显示对话框" pos:[16,362] width:140 height:15 checked:false align:#left
label 'version' "v2.2" pos:[12,14] width:60 height:16 align:#left
-- ***********************************************************************************************************************************
-- ************************************************** FUNCTIONS ********************************************************************
-- ***********************************************************************************************************************************
fn GetINISettings = -- Get / save settings from .ini file
(
if (getfiles The_INI_Path).count != 0 then
(
Global DialogPositionExportTool = execute (getINISetting The_INI_Path "Dialog_Position" "DialogPositionExportTool")
ExportPaths.items = execute (getINISetting The_INI_Path "Paths" "Export_Paths")
if ExportPaths.items.count == 0 do
(
temp01 = GetDir #export
insertItem temp01 ExportPaths.items 1
ExportPaths.items = makeUniqueArray ExportPaths.items
-- ExportPathsPersistent = ExportPaths.items
setINISetting (The_INI_Path) "Paths" "Export_Paths" (ExportPaths.items as string)
)
ExportFormat.selection = execute (getINISetting The_INI_Path "Format" "Selected_Format")
prefix.text = getINISetting The_INI_Path "Texts" "Name_Prefix"
suffix.text = getINISetting The_INI_Path "Texts" "Name_Suffix"
UCXMeshName.text = getINISetting The_INI_Path "Texts" "Collision_Prefix"
MoveToCenter.checked = execute (getINISetting The_INI_Path "Checkboxes" "MoveToCenter")
ResetX.checked = execute (getINISetting The_INI_Path "Checkboxes" "ResetX")
ConvertToEditableMesh.checked = execute (getINISetting The_INI_Path "Checkboxes" "ConvertToEditableMesh")
NameChange.Checked = execute (getINISetting The_INI_Path "Checkboxes" "NameChange")
AddCollision.checked = execute (getINISetting The_INI_Path "Checkboxes" "AddCollision")
MergeAllNodes.checked = execute (getINISetting The_INI_Path "Checkboxes" "MergeAllNodes")
ShowPrompt.checked = execute (getINISetting The_INI_Path "Checkboxes" "Show_Prompt")
Show_Dialog.checked = execute (getINISetting The_INI_Path "Checkboxes" "Show_Dialog")
)
else
(
DialogPositionExportTool = GetDialogPos TKT
setINISetting (The_INI_Path) "Dialog_Position" "DialogPositionExportTool" (GetDialogPos TKT as string)
temp01 = GetDir #export
insertItem temp01 ExportPaths.items 1
ExportPaths.items = makeUniqueArray ExportPaths.items
setINISetting (The_INI_Path) "Paths" "Export_Paths" (ExportPaths.items as string)
setINISetting (The_INI_Path) "Format" "Selected_Format" (ExportFormat.selection as string)
setINISetting (The_INI_Path) "Texts" "Name_Prefix" (prefix.text as string)
setINISetting (The_INI_Path) "Texts" "Name_Suffix" (suffix.text as string)
setINISetting (The_INI_Path) "Texts" "Collision_Prefix" (UCXMeshName.text as string)
setINISetting (The_INI_Path) "Checkboxes" "MoveToCenter" (MoveToCenter.checked as string)
setINISetting (The_INI_Path) "Checkboxes" "ResetX" (ResetX.checked as string)
setINISetting (The_INI_Path) "Checkboxes" "ConvertToEditableMesh" (ConvertToEditableMesh.checked as string)
setINISetting (The_INI_Path) "Checkboxes" "NameChange" (NameChange.checked as string)
setINISetting (The_INI_Path) "Checkboxes" "AddCollision" (AddCollision.checked as string)
setINISetting (The_INI_Path) "Checkboxes" "MergeAllNodes" (MergeAllNodes.checked as string)
setINISetting (The_INI_Path) "Checkboxes" "Show_Prompt" (ShowPrompt.checked as string)
setINISetting (The_INI_Path) "Checkboxes" "Show_Dialog" (Show_Dialog.checked as string)
)
)
fn FindExporterClass TheClass =
(
Counter = 1
for i in theClasses do
(
if i as string == TheClass then
(
return Counter
)
Counter += 1
)
if Counter == theClasses.count then return 0
)
fn GetExporterClass = -- Get exporter class corresponding to the selected format
(
case ExportFormat.selection of
(
1 : ExporterClass = FindExporterClass "FBXEXP" --FBX
2 : ExporterClass = FindExporterClass "ObjExp" --OBJ
3 : ExporterClass = FindExporterClass "3D_StudioExporterPlugin" --3DS
4 : ExporterClass = FindExporterClass "DWG_ExportExporterPlugin" --DWG
5 : ExporterClass = FindExporterClass "DWG_Export" --DXF
6 : ExporterClass = FindExporterClass "Alembic_Export" --ABC
7 : ExporterClass = FindExporterClass "ACIS_SAT" --SAT
8 : ExporterClass = FindExporterClass "DAEEXP" --DAE
9 : ExporterClass = FindExporterClass "IGES_Export" --IGS
10 : ExporterClass = FindExporterClass "SW3D_Exp" --W3D
11 : ExporterClass = FindExporterClass "OpenFltExport" --FLT
12 : ExporterClass = FindExporterClass "AsciiExp" --ASE
13 : ExporterClass = FindExporterClass "DWF_Exporter" --DWF
14 : ExporterClass = (-1) --VRSCENE
15 : ExporterClass = (-2) --MAX
)
return ExporterClass
)
fn GetRoot obj = -- Get the root of obj
(
while obj.parent != undefined do obj = obj.parent
return obj
)
fn SelectObjAndCollisionMeshes obj UcxMeshes InitialUCXPos =
(
if LinkedToDummy == True then
(
for i in CollisionMeshes do i.pos = obj.pos
if MergeAllNodes.checked == False then select (CollisionMeshes + MeshesToSelect)
else select (CollisionMeshes + obj)
)
else
(
ClearSelection()
execute("select $" + UCXMeshName.text + obj.name + "*")
for i in selection do
(
append InitialUCXPos i.pos
i.pos = obj.pos
append UcxMeshes i
)
select (UcxMeshes + obj)
)
)
fn GetAllChildren obj TheChildren = -- Get all the children of obj and append them to TheChildren
(
if obj.children != undefined then
for i in obj.children do
(
appendifunique TheChildren i
GetAllChildren i TheChildren
)
)
fn MergeChildren TheRoot CollisionMeshes = -- Merge all the children of TheRoot and return them as a collapsed mesh, and store collision meshes in CollisionMeshes (snap collision pivot point on root)
(
free TheChildren
free CollisionMeshes
free MeshesToSelect
MeshesToMerge = #()
GetAllChildren TheRoot TheChildren
for i in TheChildren do
(
if UCXMeshName.text != "" and matchPattern i.name pattern:(UCXMeshName.text + "*") then
(
if AddCollision.checked then
(
NewObj = copy i
NewObj.name = i.name
NewObj.parent = TheRoot
NewObj.pivot = TheRoot.pos
appendifunique CollisionMeshes NewObj
)
)
else
(
if MergeAllNodes.checked == true then
(
if superClassOf i != GeometryClass then
(
-- nothing ^^
)
else
(
NewObj = copy i
NewObj.parent = none
collapseStack NewObj
resetxform NewObj
if classOf NewObj != Editable_Poly then convertTo NewObj Editable_Poly
append MeshesToMerge NewObj
)
)
else
(
append MeshesToSelect i
)
)
)
if MergeAllNodes.checked == true then
(
FirstObj = MeshesToMerge[1]
for i = 2 to MeshesToMerge.count do
(
FirstObj.attach MeshesToMerge[i] FirstObj
)
FirstObj.parent = none
FirstObj.pivot = TheRoot.pos
FirstObj.transform = TheRoot.transform
FirstObj.name = TheRoot.name
return FirstObj
)
else
(
return TheRoot
)
)
fn SortSelection SelectionList = -- If any of the selected objects is linked to a dummy or a point helper, then keep this helper only in the selection
( -- if no parent or no helper then keep a copy of the selected objects in the selection
local NewSelectionList = #()
for i in SelectionList do
(
TheRoot = GetRoot i
if classOf (TheRoot) == Dummy or classOf (TheRoot) == Point then appendifunique NewSelectionList TheRoot
else
(
NewObj = copy i
NewObj.name = i.name
append NewSelectionList NewObj
)
)
return NewSelectionList
)
fn AddFormatToName TheName = -- Adds the format at the end of the name to avoid bug when exporting object that contains a '.' in its name
(
case ExportFormat.selection of
(
1 : TheName = (TheName + ".FBX")
2 : TheName = (TheName + ".OBJ")
3 : TheName = (TheName + ".3DS")
4 : TheName = (TheName + ".DMG")
5 : TheName = (TheName + ".DXF")
6 : TheName = (TheName + ".ABC")
7 : TheName = (TheName + ".SAT")
8 : TheName = (TheName + ".DAE")
9 : TheName = (TheName + ".IGS")
10 : TheName = (TheName + ".W3D")
11 : TheName = (TheName + ".FLT")
12 : TheName = (TheName + ".ASE")
13 : TheName = (TheName + ".DWF")
14 : TheName = (TheName + ".VRSCENE")
15 : TheName = (TheName + ".MAX")
)
return TheName
)
fn Export_Stuff obj ExporterClass = -- Make the actual export with the right name, format and collisions
(
if AddCollision.checked then
(
UcxMeshes = #()
InitialUCXPos = #()
SelectObjAndCollisionMeshes obj UcxMeshes InitialUCXPos
)
else
(
if MergeAllNodes.checked == False and LinkedToDummy == True then
/*if ExporterClass == -2 then
(
free TheChildren
GetAllChildren obj TheChildren
appendifunique TheChildren obj
select TheChildren
)
else*/ select MeshesToSelect
else select obj
)
if ExportCounter == 0 and Show_Dialog.checked then StartTime = timeGetTime()
if ExporterClass == -2 and ExportFormat.selection != 2 then
(
if NameChange.checked then TheObjName = (ExportPaths.selected + "\\" + Prefix.text + obj.name + Suffix.text)
else TheObjName = (ExportPaths.selected + "\\" + obj.name)
TheObjName = AddFormatToName TheObjName
saveNodes $ TheObjName
)
else
(
print("ExNUm")
print(ExportCounter)
if ShowPrompt.checked then --ExportCounter == 0 and ShowPrompt.checked then
(
if NameChange.checked then TheObjName = (ExportPaths.selected + "\\" + Prefix.text + obj.name + Suffix.text)
else TheObjName = (ExportPaths.selected + "\\" + obj.name)
TheObjName = AddFormatToName TheObjName
--FBXExporterSetParam "ASCII" False
--FBXExporterSetParam "Cameras" False
--FBXExporterSetParam "FileVersion" "FBX201500"
--FBXExporterSetParam "Lights" False
--FBXExporterSetParam "UpAxis" "Y"
--FBXExporterSetParam "ConvertUnit" "Centimeters"
--FBXExporterSetParam "ScaleFactor" 1.0
--FBXExporterSetParam "BakeAnimation" False
-- FBXExporterSetParam "LoadPreset" "C:\\Users\\Administrator\\Documents\\3dsmax\\FBX\\3dsMax2024_X64\\Presets\\export\\用户定义.fbxexportpreset"
exportFile TheObjName selectedOnly:true using:FBXEXP
)
else
(
if NameChange.checked then TheObjName = (ExportPaths.selected + "\\" + Prefix.text + obj.name + Suffix.text)
else TheObjName = (ExportPaths.selected + "\\" + obj.name)
TheObjName = AddFormatToName TheObjName
FBXExporterSetParam "ASCII" False
FBXExporterSetParam "Cameras" False
FBXExporterSetParam "FileVersion" "FBX201600"
FBXExporterSetParam "Lights" False
FBXExporterSetParam "UpAxis" "Y"
FBXExporterSetParam "ConvertUnit" "cm"
FBXExporterSetParam "BakeAnimation" False
exportFile TheObjName #noPrompt selectedOnly:true using:FBXEXP
)
)
if AddCollision.checked then
(
if LinkedToDummy then
(
for i = CollisionMeshes.count to 1 by -1 do delete CollisionMeshes[i]
)
else
(
for j = 1 to UcxMeshes.count do UcxMeshes[j].pos = InitialUCXPos[j]
)
)
if MergeAllNodes.checked == True or LinkedToDummy == False then delete obj
)
-- ***********************************************************************************************************************************
-- ************************************************** EVENTS ***********************************************************************
-- ***********************************************************************************************************************************
on TKT open do
(
windows.sendmessage ExportPaths.hwnd[1] 352 450 0
GetINISettings()
if DialogPositionExportTool != undefined do SetDialogPos TKT DialogPositionExportTool
if ExportFormat.selection == 14 then
(
AddCollision.enabled = false
UCXMeshName.enabled = false
)
else
(
AddCollision.enabled = true
UCXMeshName.enabled = true
)
if MergeAllNodes.checked == False then
(
ResetX.enabled = False
ConvertToEditableMesh.enabled = False
)
else if MergeAllNodes.checked == True then
(
ResetX.enabled = True
ConvertToEditableMesh.enabled = True
)
)
on TKT close do
(
setINISetting (The_INI_Path) "Dialog_Position" "DialogPositionExportTool" (GetDialogPos TKT as string)
)
on MoveToCenter changed MoveToCenterState do
setINISetting (The_INI_Path) "Checkboxes" "MoveToCenter" (MoveToCenterState as string)
on ResetX changed ResetXState do
setINISetting (The_INI_Path) "Checkboxes" "ResetX" (ResetXState as string)
on ConvertToEditableMesh changed ConvertToEditableMeshState do
setINISetting (The_INI_Path) "Checkboxes" "ConvertToEditableMesh" (ConvertToEditableMeshState as string)
on MergeAllNodes changed MergeAllNodesState do
(
setINISetting (The_INI_Path) "Checkboxes" "MergeAllNodes" (MergeAllNodesState as string)
if MergeAllNodesState == False then
(
ResetX.enabled = False
ConvertToEditableMesh.enabled = False
)
else if MergeAllNodesState == True then
(
ResetX.enabled = True
ConvertToEditableMesh.enabled = True
)
)
on NameChange changed NameChangeState do
setINISetting (The_INI_Path) "Checkboxes" "NameChange" (NameChangeState as string)
on prefix changed prefixText do
setINISetting (The_INI_Path) "Texts" "Name_Prefix" (prefixText as string)
on suffix changed suffixText do
setINISetting (The_INI_Path) "Texts" "Name_Suffix" (suffixText as string)
on AddCollision changed AddCollisionState do
setINISetting (The_INI_Path) "Checkboxes" "AddCollision" (AddCollisionState as string)
on UCXMeshName changed UCXMeshNameText do
setINISetting (The_INI_Path) "Texts" "Collision_Prefix" (UCXMeshNameText as string)
on ExportFormat selected ExportFormatSelection do
(
setINISetting (The_INI_Path) "Format" "Selected_Format" (ExportFormatSelection as string)
if ExportFormat.selection == 14 then
(
AddCollision.enabled = false
UCXMeshName.enabled = false
)
else
(
AddCollision.enabled = true
UCXMeshName.enabled = true
)
)
on ExportPaths selected ExportPathsSelection do
(
insertItem ExportPaths.selected ExportPaths.items 1
ExportPaths.items = makeUniqueArray ExportPaths.items
ExportPaths.selection = 1
setINISetting (The_INI_Path) "Paths" "Export_Paths" (ExportPaths.items as string)
)
on ExportPaths rightClick do -- Open the selected path in windows explorer
(
if ExportPaths.selected != undefined do shellLaunch "explorer.exe" ExportPaths.selected
)
on Browse pressed do
(
if ExportPaths.selected != undefined then Global ExportPath = getSavepath initialDir:ExportPaths.selected
else Global ExportPath = getSavepath initialDir:(GetDir #export)
if ExportPath != undefined do
(
insertItem ExportPath ExportPaths.items 1
ExportPaths.items = makeUniqueArray ExportPaths.items
setINISetting (The_INI_Path) "Paths" "Export_Paths" (ExportPaths.items as string)
)
)
on Browse rightClick do
(
if QueryBox "Are you sure you want to remove the selected path from the list ?" then
(
ExportPaths.items = deleteItem ExportPaths.items 1
setINISetting (The_INI_Path) "Paths" "Export_Paths" (ExportPaths.items as string)
)
)
on Export_Button pressed do
(
undo off
(
max create mode
if selection.count == 0 then
(
if TheSelection == undefined or TheSelection.count == 0 then
(
MessageBox "Selection is empty !"
return 0
)
else
(
TheSelection = for node in TheSelection where isvalidnode node collect node -- Remove any deleted scene objects from TheSelection
local SelectedObj = #()
if TheSelection.count > 0 then SelectedObj = SortSelection TheSelection
else
(
MessageBox "Selection is empty !"
return 0
)
)
)
else
(
TheSelection = selection as array
local SelectedObj = SortSelection (selection as array)
)
if ExportPaths.selected == undefined then
(
MessageBox "Please select an export path ;)"
return 0
)
global ExportCounter = 0
global ExporterClass
ExporterClass = GetExporterClass()
if ExporterClass == undefined or ExporterClass == 0 then
(
MessageBox "Export plugin not found !"
return 0
)
if ExporterClass == (-1) then -- VRSCENE
(
local UnHiddenObj = #()
for o in objects do -- Make any visible object hidden and append them in UnHiddenObj
(
if o.isHidden == false then
(
append UnHiddenObj o
o.isHidden = true
)
)
StartTime = timeGetTime()
ParentedToDummy = False
for i in SelectedObj do -- VRSCENE export loop
(
if classOf i == Dummy or classOf i == Point then
(
ParentedToDummy = True
free TheChildren
GetAllChildren i TheChildren
TheNewRoot = copy i
TheNewRoot.name = i.name
i = TheNewRoot
for j in TheChildren do
(
NewObj = copy j
NewObj.parent = i
)
free TheChildren
GetAllChildren i TheChildren -- Fill TheChildren with the copies
)
i.isHidden = false -- Unhide i
if MoveToCenter.Checked then i.pos = [0,0,0]
if ResetX.checked then
(
if ParentedToDummy then
(
for j in TheChildren do
(
resetxform j
collapseStack j
)
)
else
(
resetxform i
collapseStack i
)
)
if ConvertToEditableMesh.Checked then
(
if ParentedToDummy then
(
for j in TheChildren do convertToMesh j
)
else convertToMesh i
)
if ParentedToDummy then
(
for j in TheChildren do j.isHidden = False
)
if NameChange.checked then TheObjName = (ExportPaths.selected + "\\" + Prefix.text + i.name + Suffix.text)
else TheObjName = (ExportPaths.selected + "\\" + i.name)
TheObjName = AddFormatToName TheObjName
vrayExportRTScene
if ParentedToDummy then
(
for j in TheChildren do delete j
delete i
)
else delete i
ExportCounter += 1
)
for o in UnHiddenObj do -- Makes everything Unhidden
(
if isValidNode o then o.isHidden = false
)
if Show_Dialog.checked then
(
EndTime = timeGetTime()
ExportTime = (EndTime as float - StartTime as float) / 1000
if QueryBox (ExportCounter as string + " object(s) exported successfully ;)\nExport took " + ExportTime as string + " seconds.\n\nOpen export folder ?") then
(
shellLaunch "explorer.exe" ExportPaths.selected
)
)
max modify mode
ClearSelection()
select TheSelection
return 0
)-- End VRSCENE
ParentedToDummy = False
for obj in SelectedObj do -- Main export loop
(
if classOf obj == Dummy or classOf obj == Point then
(
obj = MergeChildren obj CollisionMeshes
LinkedToDummy = True
)
else LinkedToDummy = False
if MoveToCenter.Checked then
(
if MergeAllNodes.checked then obj.pos = [0,0,0]
else
(
local InitialPos = obj.pos
obj.pos = [0,0,0]
)
)
if ResetX.checked and (MergeAllNodes.checked or LinkedToDummy == False) then
(
resetxform obj
collapseStack obj
)
if ConvertToEditableMesh.Checked and (MergeAllNodes.checked or LinkedToDummy == False) then convertToMesh obj
Export_Stuff obj ExporterClass
ExportCounter += 1
if MoveToCenter.Checked and MergeAllNodes.checked == False and LinkedToDummy then obj.pos = InitialPos
)
ClearSelection()
select TheSelection
if Show_Dialog.checked then
(
EndTime = timeGetTime()
ExportTime = (EndTime as float - StartTime as float) / 1000
if QueryBox (ExportCounter as string + " object(s) exported successfully ;)\nExport took " + ExportTime as string + " seconds.\n\nOpen export folder ?") then
(
shellLaunch "explorer.exe" ExportPaths.selected
)
)
max modify mode
)
)
on ShowPrompt changed ShowPromptState do
setINISetting (The_INI_Path) "Checkboxes" "Show_Prompt" (ShowPromptState as string)
on Show_Dialog changed Show_DialogState do
setINISetting (The_INI_Path) "Checkboxes" "Show_Dialog" (Show_DialogState as string)
)
CreateDialog TKT style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)