Notifications
Clear all
[Closed] group to dummy
Mar 06, 2014 10:38 am
Hi,
I’d like to create a function to convert my groups to dummies on a selection. I wrote this code :
groupToDummy = undefined
fn groupsToDummies items =
(
items = items as array
global to_be_deleted = #()
fn groupToDummy g =
(
group_name = "dummy_" + g.name
g_dummy = dummy name:group_name pos:g.position
for n in g.children do n.parent = g_dummy
if g.parent != undefined then g_dummy.parent = g.parent
--do the same for children
for c in g_dummy.children where isValidNode c AND isGroupHead c do (
groupToDummy c
)
append to_be_deleted g
)
for c in items where isValidNode c AND isGroupHead c do (
groupToDummy c
)
for n in to_be_deleted where isValidNode n do delete n
)
items = selection
groupsToDummies items
Let’s say we are working with a simple structure as :
[ul]
[li]group1[/li][list]
[li]group2[/li][list]
[li]sphere[/li][/ul]
[li]group3[/li]
[ul]
[li]sphere[/li][/ul]
[/list]
[/list]
whee I select a single group it works great.
But when I select group2 and group3 it converts those groups to dummies AND delete group1 as if there we no more children inside (you can see it by commenting the delete line and delete its children one by one)
Has anyone encountered this kind of behaviour ?
Thanks