Move group node into another group

I want to move group node into another group.
But addchild function cannot apply because it is only for leaf node.
Is there any solution to move group into another subtree?

Ungroup the original group and regroup it together with the items to be moved, resulting in a move.
However, the properties of the original group will be lost, so its use is limited.

ใ‚‚ใจใฎใ‚ฐใƒซใƒผใƒ—ใ‚’่งฃ้™คใ—ใฆ๏ผŒ็งปๅ‹•ใ—ใŸใ„ใ‚ขใ‚คใƒ†ใƒ ใจไธ€็ท’ใซๅ†ใ‚ฐใƒซใƒผใƒ—ๅŒ–ใ™ใ‚‹ใจ๏ผŒ็ตๆžœ็š„ใซ็งปๅ‹•ใงใใพใ™ใ€‚
ใŸใ ใ—๏ผŒใ‚‚ใจใฎใ‚ฐใƒซใƒผใƒ—ใŒๆŒใฃใฆใ„ใŸใƒ—ใƒญใƒ‘ใƒ†ใ‚ฃใฏๆถˆใˆใ‚‹ใฎใง็”จ้€”ใฏ้™ๅฎš็š„ใงใ™ใ€‚

const { selection } = require('scenegraph') ;
const commands = require('commands') ;

const group0 = selection.items[0] ;
const group1 = selection.items[1] ;

selection.items = [group0] ;
commands.ungroup() ;
const items0 = selection.items ;

selection.items = [...items0, group1] ; ;

Thank you for your answer. I found the way.
But as you mentioned, loosing the properties is sometimes critical.
I strongly hope it will be able to do removechild /addchild easily!

1 Like