Hi
is there a way to export a group of objects (a group not a selection) with maxscript using:
CProxy.ProxyFp.fromScene (CProxy()) “groupnode” @“D:\myproxy1111111.cgeo”
much appreciated
Hi
is there a way to export a group of objects (a group not a selection) with maxscript using:
CProxy.ProxyFp.fromScene (CProxy()) “groupnode” @“D:\myproxy1111111.cgeo”
much appreciated
this will work for you.
/*
================================================================================
CORONA TEAM PROXY EXPORTER
================================================================================
DESCRIPTION:
Converts selected geometry or groups into Corona Proxy (.cgeo) files.
Works with single objects, multiple objects, and grouped objects.
Automatically handles closed groups by opening them temporarily.
HOW TO USE:
1. SAVE YOUR FILE FIRST! This script modifies your scene.
2. Select the object(s) or group you want to convert to proxy
3. Run this script (drag into viewport or run from MAXScript menu)
4. Click "..." to choose where to save the .cgeo file
5. Set options:
- Delete original: Removes source geometry after export
- Collapse to single proxy: Combines all selected into one proxy
- Keep in group: Places new proxy inside the original group
6. Click "Export to Proxy"
OPTIONS:
- Delete original: Check to remove the original objects after proxy creation
- Collapse to single proxy: Merges all geometry into one proxy file
- Keep in group: If source was in a group, proxy stays in that group
FEATURES:
- Auto-refreshes when selection changes
- Works with nested groups
- Preserves object positions
- Names proxy as "originalname_proxy"
REQUIREMENTS:
- Corona installed
- 3ds Max 2020 or newer recommended
================================================================================
*/
(
global CoronaTeamProxyRollout
try(destroyDialog CoronaTeamProxyRollout) catch()
rollout CoronaTeamProxyRollout "Corona Team Proxy Exporter" width:480 height:260
(
dotNetControl lbl_warning "System.Windows.Forms.Label" pos:[10,8] width:460 height:22
label lbl_info "Select object(s) or group, then choose export path:" pos:[10,35] width:460
edittext edt_path "Path:" text:"" pos:[10,55] width:380 height:20
button btn_browse "..." pos:[400,55] width:40 height:20
checkbox chk_deleteOriginal "Delete original" pos:[10,85] checked:false width:150
checkbox chk_collapseGroup "Collapse to single proxy" pos:[10,105] checked:true width:180
checkbox chk_keepInGroup "Keep in group" pos:[240,85] checked:true width:150
label lbl_selected "Selected: (none)" pos:[10,140] width:300
label lbl_geoCount "Geometry: 0" pos:[10,160] width:300
button btn_refresh "Refresh" pos:[380,150] width:70 height:22
button btn_export "Export to Proxy" pos:[10,195] width:180 height:40
button btn_cancel "Cancel" pos:[200,195] width:100 height:40
local selectedNodes = #()
local collectedGeo = #()
local parentGroup = undefined
local openedGroups = #()
fn openParentGroups obj =
(
local p = obj.parent
while p != undefined do
(
if isGroupHead p and not (isOpenGroupHead p) do
(
appendIfUnique openedGroups p
setGroupOpen p true
)
p = p.parent
)
)
fn restoreGroups =
(
for grp in openedGroups do
try ( setGroupOpen grp false ) catch ()
openedGroups = #()
)
fn getGroupChildren groupNode =
(
local children = #()
local wasOpen = isOpenGroupHead groupNode
if not wasOpen do
(
setGroupOpen groupNode true
appendIfUnique openedGroups groupNode
)
for obj in groupNode.children do
(
if isGroupHead obj then
join children (getGroupChildren obj)
else if superClassOf obj == GeometryClass then
append children obj
)
children
)
fn collectGeometry sourceNodes =
(
local geoNodes = #()
local processedObjects = #{}
parentGroup = undefined
for obj in sourceNodes do
(
if isGroupHead obj then
(
if parentGroup == undefined do parentGroup = obj
local children = getGroupChildren obj
for child in children do
(
local idx = child.inode.handle
if not processedObjects[idx] do
(
append geoNodes child
processedObjects[idx] = true
)
)
)
else if superClassOf obj == GeometryClass then
(
local idx = obj.inode.handle
if not processedObjects[idx] do
(
append geoNodes obj
processedObjects[idx] = true
if parentGroup == undefined and isGroupMember obj do
(
local p = obj.parent
while p != undefined do
(
if isGroupHead p do (parentGroup = p; exit)
p = p.parent
)
)
)
)
)
geoNodes
)
fn updateSelectionLabel =
(
selectedNodes = selection as array
collectedGeo = collectGeometry selectedNodes
if selectedNodes.count == 0 then
lbl_selected.text = "Selected: (none)"
else if selectedNodes.count == 1 then
lbl_selected.text = "Selected: " + selectedNodes[1].name
else
lbl_selected.text = "Selected: " + (selectedNodes.count as string) + " objects"
lbl_geoCount.text = "Geometry: " + (collectedGeo.count as string)
if parentGroup != undefined do
lbl_geoCount.text += " (group: " + parentGroup.name + ")"
)
fn validatePath filePath =
(
if filePath == "" do return false
local dirPath = getFilenamePath filePath
if dirPath != "" and not doesFileExist dirPath do
try (makeDir dirPath all:true) catch (return false)
if dirPath == "" do dirPath = "C:\\"
return doesFileExist dirPath
)
fn createCombinedMesh geoNodes =
(
local combinedMesh = mesh vertices:#() faces:#()
combinedMesh.name = "temp_proxy_mesh"
for obj in geoNodes do openParentGroups obj
for obj in geoNodes do
(
local tempCopy = snapshot obj
if classOf tempCopy != Editable_Mesh do convertToMesh tempCopy
if (getNumVerts combinedMesh) == 0 then
(
delete combinedMesh
combinedMesh = tempCopy
combinedMesh.name = "temp_proxy_mesh"
)
else
attach combinedMesh tempCopy
)
ResetXForm combinedMesh
convertToMesh combinedMesh
combinedMesh
)
fn exportToProxy filePath deleteOrig collapseToOne keepInGroup =
(
if collectedGeo.count == 0 do
(
messageBox "No geometry found!" title:"Error"
return false
)
if not validatePath filePath do
(
messageBox ("Invalid path:\n" + filePath) title:"Path Error"
return false
)
openedGroups = #()
local createdProxies = #()
local origName = ""
if collectedGeo.count == 1 then
origName = collectedGeo[1].name
else if parentGroup != undefined then
origName = parentGroup.name
else
origName = collectedGeo[1].name
if collapseToOne or collectedGeo.count == 1 then
(
local tempMesh = createCombinedMesh collectedGeo
local newProxy = CProxy()
local result = CProxy.ProxyFp.fromScene newProxy tempMesh filePath
newProxy.name = origName + "_proxy"
delete tempMesh
if result == 0 then
append createdProxies newProxy
else
(
delete newProxy
messageBox ("Export failed! Code: " + (result as string)) title:"Error"
return false
)
)
else
(
local basePath = getFilenamePath filePath
local baseName = getFilenameFile filePath
for i = 1 to collectedGeo.count do
(
local obj = collectedGeo[i]
local objPath = basePath + baseName + "_" + obj.name + ".cgeo"
local tempMesh = snapshot obj
convertToMesh tempMesh
ResetXForm tempMesh
convertToMesh tempMesh
local newProxy = CProxy()
local result = CProxy.ProxyFp.fromScene newProxy tempMesh objPath
newProxy.name = obj.name + "_proxy"
delete tempMesh
if result == 0 then
append createdProxies newProxy
else
delete newProxy
)
)
if keepInGroup and parentGroup != undefined and createdProxies.count > 0 do
(
setGroupOpen parentGroup true
for prx in createdProxies do attachNodesToGroup prx parentGroup
setGroupOpen parentGroup false
)
if deleteOrig and createdProxies.count > 0 do
(
if parentGroup != undefined do setGroupOpen parentGroup true
for obj in collectedGeo do delete obj
)
restoreGroups()
messageBox ("Created " + (createdProxies.count as string) + " proxy(s)!\nPath: " + filePath) title:"Success"
return true
)
on CoronaTeamProxyRollout open do
(
lbl_warning.text = "WARNING: Save file before running! Use at own risk."
lbl_warning.font = dotNetObject "System.Drawing.Font" "Microsoft Sans Serif" 10 ((dotNetClass "System.Drawing.FontStyle").Bold)
lbl_warning.foreColor = (dotNetClass "System.Drawing.Color").fromARGB 255 100 100
local defaultPath = maxFilePath
if defaultPath == "" do defaultPath = (getDir #temp) + "\\"
edt_path.text = defaultPath + "proxy.cgeo"
updateSelectionLabel()
callbacks.addScript #selectionSetChanged "try(CoronaTeamProxyRollout.updateSelectionLabel())catch()" id:#CoronaTeamProxyCallback
)
on CoronaTeamProxyRollout close do
(
callbacks.removeScripts id:#CoronaTeamProxyCallback
)
on btn_browse pressed do
(
local initDir = getFilenamePath edt_path.text
if initDir == "" or not doesFileExist initDir do initDir = maxFilePath
if initDir == "" do initDir = getDir #temp
local savePath = getSaveFileName caption:"Save Corona Proxy" filename:(initDir + "proxy.cgeo") types:"Corona Proxy (*.cgeo)|*.cgeo"
if savePath != undefined do edt_path.text = savePath
)
on btn_refresh pressed do updateSelectionLabel()
on btn_export pressed do
(
updateSelectionLabel()
if collectedGeo.count > 0 then
(
local filePath = edt_path.text
if filePath != "" then
exportToProxy filePath chk_deleteOriginal.checked chk_collapseGroup.checked chk_keepInGroup.checked
else
messageBox "Please specify a file path!" title:"Error"
)
else
messageBox "Please select geometry first!" title:"Error"
)
on btn_cancel pressed do destroyDialog CoronaTeamProxyRollout
)
createDialog CoronaTeamProxyRollout
)