ScriptSpot home

Forum topic · General Scripting

Group Attaching

By artrender · 2013-06-02

Description

Tell me please, I just want to make the same operation like simple attach group tool! I need to use this:

attachNodesToGroup

I know that I can use


on atachbtn click do 
( 
   attachNodesToGroup selection <targetNode> 
) 

but how to define targetnode that will be a group? It means that selection should be attached to the picked group=>finally it will be a group as well! How to pick a group by script? Thx in advance!


on atachbtn picked obj do 
( 
   if isValidNode obj AND isGroupHead obj do 
   print obj.name 
)

doesn't work for me

Comments (14)
artrender

Barigazy, thanks!

I have sent you an email! Read when you can please!

artrender

oh, finally, Barigazy!

You did a brilliant work! Thank you so much - even with visual line :)

HUUUGS!

Reply to Branko Živković
Branko Živković

To prevent flickering use this way

if isGroupHead (grpHead = getGrandParentName grpMember) do with redraw off attachNodesToGroup selection grpHead

artrender

thx Miauu

the problem is that first we have selection (it can be an object, group or even more then 1 object selected - t.e. torus001 from the picture of barigazy)! With this you pick the group(group001 from pic) that will attach your previous selection(torus001)!

my difficulty is to get the selection after you pressed on atachbtn and immediately to be able to pick the group that will take this selection inside!

Thank you again for your patience and for the wish to help!!!

miauu

I hope that this will help you.

This function will return the top most group head(work with hested groups also).


function FindTopMostGroupHead obj = 
	(
		res = undefined
		if ((isGroupHead obj) AND (not (isGroupMember obj))) then
			result = obj
		else
		(
			if (isGroupMember obj) then
				FindTopmostGroupHead (obj.parent) 
			else
				result = undefined
		)
		--	return
		res
	)

Using the atachbtn you can pick an object that is a part of a group, then the fn above will return the group head and you can attach the object that you want(is selected or stored in array) to the group head.



on atachbtn picked obj do 
( 
	grpHead = FindTopMostGroupHead obj
	if isValidNode obj  do 
	(
		grpHead = FindTopMostGroupHead obj
		if grpHead != undefined then
			print "Picked object is part of a group. Attach the objects that you want to grpHead"
		else
			print "Picked object is not a part of a group"
	)
)
Reply to miauu
Branko Živković

:)

Hey Kostadin
you are fester then me.

@artrender

See this image

You have Torus and one group which contains box sphere and teapot.
Schematic view shows you everithing that you need to know.
Group Head ei. helper is the grand parent of theses tree nodes.

Reply to artrender
Branko Živković

:)

Yup. I'm here and just finish my new tool and post it on "Scripts" page.
Whole day I try to find a bug and finaly "seed" function is the main reason for the lost time. Thanks to Kostadin (miauuu) and DenisT problem are solved.

Reply to Branko Živković
Branko Živković

Previous image code
Select Torus and then Group and try next line

sourceObj = selection[1]
targetObj = (for i in 2 to selection.count where selection[i].parent == undefined and isgroupHead selection[i] collect selection[i])[1]
attachNodesToGroup sourceObj targetObj

Reply to Branko Živković
artrender

the idea is good

but default attach tool doesn't work like it! It works when the object is selected and then when pressed on attachbtn you can pick the group that will attach the object

what if you have 2 toruses to attach at once? or even more?

Reply to artrender
Branko Živković

Then select first theses two toruses first then group and start for loop from number 3
for i = 3 to ...
Are you want pickObject method maybe (select objects that you need to attach and activae picking)?

Reply to Branko Živković
Branko Živković

This is funny work around

Try this
select some objects that you want to attach then run code below and pick any group member

fn getGrandParentName obj = (while obj.parent != undefined do obj = obj.parent)
fn groupFilt o = (isGroupMember o)
if selection.count != 0 do
(
grpMember = pickObject count:1 filter:groupFilt rubberBand:selection.center rubberBandColor:yellow
if isValidNode grpMember do
(
if isGroupHead (grpHead = getGrandParentName grpMember) do attachNodesToGroup selection grpHead
)
)