ScriptSpot

Forum topic · General Scripting

Convert groups to single objects script

By eyepiz · 2012-10-31

Description

Hello all,

I typically import AutoCAD Geometry in 3DS Max. The AutoCAD DWG's consist of multiple AutoCAD Block. When I import them I check the convert blocks to groups under general options of the dialog box so I don't get a million pieces and can move stuff around with ease.

I wanted to know if there is a scrips that can covert multiple max groups to single objects?

I would greatly appreciate any assistance.

Thanks

-Eric

Comments (5)

Allmost there!

eyepiz · 2016-01-25

So I almost have a working script! The only problem is when I have a group inside a group the script error out.

(
fn getGroupHead objArr = (
for grp in objArr where isGroupHead grp collect grp
)
fn getGroupMember objArr = (
for grp in objArr where isGroupMember grp collect grp
)

--Collect the Group Objects of the current selection
grpHeads = getGroupHead selection
--Find any nested Group Objects
grpHdMbr = getGroupMember grpHeads
--If there are nested groups then ungroup it
if grpHdMbr.count !=0 then (
unGrp = true
) else (
unGrp = false
)

fn detachGroups objArr unGrp = (
while unGrp do (
for cnt in 1 to objArr.count do (
grpHead = objArr[cnt].parent
if isGroupHead grpHead do (
deGrp = for val in (getGroupMember objArr[cnt].children) where not isGroupHead val collect val
append deGrp objArr[cnt]
setGroupOpen grpHead true
detachNodesFromGroup deGrp
objArr[cnt].parent = grpHead.parent
setGroupOpen grpHead false
)
)
objArr = getGroupMember grpHeads
if objArr.count !=0 then (
unGrp = true
) else (
unGrp = false
)
)
)

detachGroups grpHdMbr true
--Switch to Collapse Utility
UtilityPanel.OpenUtility collapse
--Get the HWND for the Collapse Utility and Buttons
HWNDCollapse = windows.getChildHWND #max "Collapse Selected"
HWNDbtn = windows.getChildrenHWND HWNDCollapse[2]

fn getBtnHWND hwnd btnStr = (
try ((for btn in hwnd where btn[5] == btnStr collect btn)[1][1]) catch ()
)

-- Get the HWND for the specific Collapse Buttons
BTN_CollapseSelected = getBtnHWND HWNDbtn "Collapse Selected"
BTN_Mesh = getBtnHWND HWNDbtn "Mesh"
BTN_SingleObject = getBtnHWND HWNDbtn "Single Object"
--Set the Collapse Utility to Mesh
UIAccessor.PressButton BTN_Mesh
--Set the Collapse Utility to Single Object
UIAccessor.PressButton BTN_SingleObject

for obj in grpHeads do (
select obj
--Collapse the Groups to Mesh, NOTE: Nested groups will be collapsed to a single mesh
UIAccessor.PressButton BTN_CollapseSelected
-- ungroup any remaining groups that hold the collapsed meshes
if isvalidNode obj do ungroup obj
)
)

try this one

Anubis · 2012-11-01

explodeGroup (for obj in helpers where isGroupHead obj and not isGroupMember obj collect obj)

eyepiz · 2016-01-25

It explodes the group but does not attached all the objects.

are you try with Utility >

barigazy · 2012-10-31

are you try with Command Panel > Utility > Collaps?

eyepiz · 2012-10-31

I tried it...Works if I select one group at a time...I would be nice if I select multiple groups and collapse to multiple singe objects.

Maybe a script could do it.

Thanks fir the help.

-Eric