try this:
try(destroydialog TakeApartRol) catch()
rollout TakeApartRol "Take Apart" width:191
(
fn getAllMeshElements node faces: detach:on pb: ni: gi: ti: mi: gc_count:0 =
(
prefix = node.name + "_"
local tmesh = snapshotasmesh node
--local amesh = copy tmesh
local num_groups = 0
local num_elements = 0
local elements = #()
local _detachfaces = meshop.detachfaces
local _deletefaces = meshop.deletefaces
local t0 = timestamp()
local numverts = tmesh.numverts
local numfaces = tmesh.numfaces
local allfaces = #{1..numfaces}
local verts = for v = 1 to numverts collect #()
for j in allfaces do
(
f = getface tmesh j
for k = 1 to 3 do append verts[f[k]] j
)
out = false
local element = #()
if faces == unsupplied do faces = allfaces
for i in faces while not keyboard.escPressed do
(
element = #(i)
for j in element where faces[j] do
(
faces[j] = false
f = getface tmesh j
for k = 1 to 3 where verts[f[k]] != undefined do
(
join element verts[f[k]]
verts[f[k]] = undefined
)
)
if detach then
(
join elements element
)
else
(
append elements (element as bitarray)
)
num_elements += 1
if pb != undefined do pb.value = mod (num_elements/10.0) 100
if ni != undefined do ni.text = num_elements as string
if gc_count and (mod num_elements gc_count == 0 or i == numfaces) do
(
--gc light:on
if detach do
(
m = _detachfaces tmesh elements delete:false asmesh:true
name = uniquename prefix
n = editable_mesh name:name parent:node
n.mesh = m
elements = #()
)
num_groups += 1
if gi != undefined do gi.text = num_groups as string
if ti != undefined do ti.text = ((timestamp() - t0) / 1000) as string
local val = int (100.0 * heapFree / heapSize + 0.5)
if mi != undefined do mi.text = val as string
windows.processPostedMessages()
)
out = true
)
num_elements
elements
)
label facetype_lb "Face Targets: " align:#right offset:[0,4] across:2
radiobuttons facetype_rb labels:#("All", "Selected") columns:1 align:#left offset:[0,3]
label bycount_lb "Group By Count: " align:#right offset:[0,4] across:2
radiobuttons bycount_rb labels:#("1", "10", "100", "1000", "10000") default:1 columns:1 align:#left offset:[0,3]
checkbox detach_ch "Detach" align:#left offset:[0,0] --across:2
button mxs_detach_bt "MXS Process" width:172 align:#left offset:[-4,2]
progressbar progress_pb color:orange width:172 height:10 align:#center offset:[0,0]
group "Statistics: "
(
label number_lb "All Elements" align:#left offset:[8,0] across:3
label info_01 "0" align:#right offset:[40,0]
label data_01 "" width:20 align:#right offset:[8,0]
label groups_lb "Groups By Count" align:#left offset:[8,0] across:3
label info_02 "0" align:#right offset:[40,0]
label data_02 "" width:20 align:#right offset:[8,0]
label time_lb "Time" align:#left offset:[8,0] across:3
label info_03 "0" align:#right offset:[40,0]
label data_03 "s" width:20 align:#right offset:[8,0]
label heap_lb "Memory" align:#left offset:[8,0] across:3
label info_04 "0" align:#right offset:[40,0]
label data_04 "%" width:20 align:#right offset:[8,0]
)
group "Settings and Debug: "
(
checkbox debugh_ch "Debug" align:#left offset:[0,4] across:2
checkbox gclight_ch " GC Light" align:#left offset:[20,4]
button gc_bt "Garbage Collection" width:172 align:#left offset:[-4,2]
)
fn memoryDisplay =
(
local val = 100.0*heapFree/heapSize + 0.5
info_04.text = (int val) as string
)
on gc_bt pressed do
(
gc light:gclight_ch.state
memoryDisplay()
completeRedraw()
)
local num
local t0, t1
local h0, h1
on mxs_detach_bt pressed do undo "Detach" off, with redraw off
(
node = selection[1]
if iskindof node GeometryClass do
(
gc light:on
memoryDisplay()
t0 = timestamp()
h0 = heapfree
mesh = gettempmesh node
faces = if facetype_rb.state == 1 then #{1..mesh.numfaces} else (mesh.selectedfaces as bitarray)
count = #(1,10,100,1000,10000)[bycount_rb.state]
global _ee = GetAllMeshElements node faces:faces detach:detach_ch.state \
pb:progress_pb ni:info_01 gi:info_02 ti:info_03 mi:info_04 gc_count:count
t1 = timestamp()
h1 = heapfree
format "count:% time:% heap:%\n" _ee.count (t1 - t0) (h0 - h1)
)
)
on TakeApartRol open do
(
gc light:on
memoryDisplay()
)
)
createdialog TakeApartRol