attach object/group to all group instances

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 06 June 2013   #16
oh my goodneeeeeeeeees

you're both awesome, Denis and Branko! Thank you so much for your support! I was dreaming so long for such a tool and finally with your help, it will be possible to finish it! Thank you both for the years of scripting - they now can guide us to the solution!
 
Old 06 June 2013   #17
Originally Posted by gazybara: Not undertand?
edit
I do understand you. Well I'm not sure allways in my fn's.

you are thinking usually in the right direction... but there is no such thing as 'quality assurance' for max script developers. you are yours QA. so try all the time play not just a specific case but also around it.
 
Old 06 June 2013   #18
First of all filter fn need to be changed
fn filtGroup o = isGroupMember o or isGroupHead o

I was thinking that it might be better and faster to:
-- collect all group instance transform.
-- attach selection to picked root group
-- delete another instances
-- copy root group to previous groups positions

But there is a small problem
what if group members of deleted instances have different materials then root group members?
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2013   #19
Originally Posted by gazybara: what if group members of deleted instances have different materials then root group members?

why do you have to care of it? your code makes an instance of selection, attaches it to destination group... that's it.
 
Old 06 June 2013   #20
Originally Posted by denisT: why do you have to care of it? your code makes an instance of selection, attaches it to destination group... that's it.

I haved trouble with rotation of selection before attach operation. That's why I use only position alignement. Can you provide some transform (matrix) solution. I'm bad in that area
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2013   #21
Originally Posted by gazybara: I haved trouble with rotation of selection before attach operation. That's why I use only position alignement. Can you provide some transform (matrix) solution. I'm bad in that area

that's actually easy... get cloning node's transform in the picked group coordinate system

tm = node.transform*(inverse <picked group>.transform)

but cloned node has to be returned in the destination group transform

clone.transform = tm*<destination group>.transform
 
Old 06 June 2013   #22
as i said the transform issue is a simple part of this task. most complicated one is to identify which node (and its hierarchy) can be attached to a group
 
Old 06 June 2013   #23
Originally Posted by denisT: that's actually easy... get cloning node's transform in the picked group coordinate system

 tm = node.transform*(inverse <picked group>.transform)
 

but cloned node has to be returned in the destination group transform

 clone.transform = tm*<destination group>.transform
 

This works very well
try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "• • •"
(
	fn filtGroup o = isGroupMember o or isGroupHead o
	fn getRootGroupHead node = if isgroupmember node do
	(
		while node != undefined and (not isgrouphead node or isgroupmember node) do (node = node.parent)
		node
	)
	pickbutton pick "PickGroup" pos:[5,5] width:100 height:20 filter:filtGroup
	on pick picked obj do if obj != undefined and selection.count !=0 do
	(
		local rootGroup = getRootGroupHead obj
		InstanceMgr.GetInstances rootGroup &groups
		selObjs = getCurrentSelection()
		if groups.count > 1 then 
		(
			with redraw off 
			(
				for i = 1 to groups.count where groups[i] != rootGroup do
				(
					-- next line not works
					--maxOps.cloneNodes selObjs expandHierarchy:on cloneType:#instance newNodes:&objs
					maxOps.cloneNodes selObjs cloneType:#instance newNodes:&objs
					for o in objs do
					(
						--next line is need to be removed vhen you try cloning with expandHierarchy:on
						if o.parent != undefined do o.parent = undefined
						tm = o.transform * (inverse rootGroup.transform)
						o.transform = tm*groups[i].transform
						attachNodesToGroup o groups[i]
					)
				)
				attachNodesToGroup selObjs rootGroup
			)
		)
	)

)
createDialog bgaRoll 110 30 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

Using "expandHierarchy:on" not works. I think that is not realy inportant in this case.
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2013   #24
Originally Posted by gazybara: This works very well

how can it not work? it's math. the exact science...
 
Old 06 June 2013   #25
Originally Posted by denisT: how can it not work? it's math. the exact science...

No doupt. This is very cool. That's why I must ask you. You are the math genius
Thanks again.
Hey Mike wake up and try2script this
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2013   #26
oh yeeeeeeeeeeeeeeeees

that's great! I woke up at 9:00 am today!

It's working when adding a single object, but it doesn't when adding a group of object to group instances!

>> MAXScript Rollout Handler Exception:
-- Runtime error: attachNodesToGroup() failed due to invalid input <<

line -- attachNodesToGroup o groups[i]

If I disable this line: attachNodesToGroup o groups[i]

then I get elements of added groups spread throughout all the scene but not on the tables!
Still confusing!

   					maxOps.cloneNodes selObjs cloneType:#instance newNodes:&objs
   					for o in objs do
   					(
   						if o.parent != undefined do o.parent = undefined
   						tm = o.transform * (inverse rootGroup.transform)
   						o.transform = tm*groups[i].transform
   						--attachNodesToGroup o groups[i]
   					)
   
   


obs here are the groups that where cloned! But I don't know how to apply next to every object inside every group! Just try to apply this script to the max scene I've uploaded on previous page!

Last edited by try2script : 06 June 2013 at 12:14 AM.
 
Old 06 June 2013   #27
I've just found

					print objs
					for o in objs do
					(
						--next line is need to be removed vhen you try cloning with expandHierarchy:on
					--	if o.parent != undefined do o.parent = undefined
						if not isGroupHead o then
						(	
							tm = o.transform * (inverse rootGroup.transform)
							o.transform = tm*groups[i].transform
						)	
						--attachNodesToGroup o groups[i]
					)


But now I have just to --attachNodesToGroup o groups[i]
 
Old 06 June 2013   #28
Working Solution

I prepare new test scene and of course working script.
Select all items on the table and use script by selecting table below.
For the items I used 3 groups and 3 linked objects to make this example mor interesting.

try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "• • •"
(
	fn filtGroup o = (isGroupMember o or isGroupHead o)
	fn getRootGroupHead node = if filtGroup node do
	(
		while node != undefined and (not isgrouphead node or isgroupmember node) do (node = node.parent)
		node
	)	
	fn RemoveFrom theArray Itmes = if theArray.count > 0 and  Itmes.count > 0 do
	(
		local idxs = sort (for i in Itmes where (idx = findItem theArray i) > 0 collect idx)
		if idxs.count > 0 do for x = idxs.count to 1 by -1 do (deleteItem theArray idxs[x])
		theArray
	)
	fn collectRootGroups arr =
	(
		local rootGArr = #()
		while arr.count != 0 do
		(
			append rootGArr (getRootGroupHead arr[1])
			RemoveFrom arr (join #() rootGArr[rootGArr.count])
		) ; rootGArr
	)
	fn unparentAndClose arr = if arr.count != 0 do
	(
		for i in arr do
		(
			if isGroupHead i and isOpenGroupHead i do setGroupOpen i off
			i.parent = null
		) ; arr
	)
	fn redefineSelection arr =
	(
		local groupArr = for o in arr where filtGroup o collect o
		arr = RemoveFrom arr groupArr
		groupArr = collectRootGroups groupArr
		arr = unparentAndClose (join arr groupArr)
	)
	pickbutton pick "PickGroup" pos:[5,5] width:100 height:20 filter:filtGroup
	on pick picked obj do if obj != undefined and selection.count !=0 do
	(
		
		local selObjs = redefineSelection (getCurrentSelection())
		local rootGroup = getRootGroupHead obj
		InstanceMgr.GetInstances rootGroup &groups
		if groups.count > 1 then 
		(
			with redraw off 
			(
				for i = 1 to groups.count where groups[i] != rootGroup do
				(
					maxOps.cloneNodes selObjs cloneType:#instance newNodes:&objs
					for o in (redefineSelection objs) do
					(
						tm = o.transform * (inverse rootGroup.transform)
						o.transform = tm*groups[i].transform
						attachNodesToGroup o groups[i]
					)
				)
				attachNodesToGroup selObjs rootGroup
			)
		)
	)

)
createDialog bgaRoll 110 30 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2013   #29
Wake up Mike!
And please define you profile, at least add your name
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2013   #30
Originally Posted by gazybara: I prepare new test scene and of course working script.
Select all items on the table and use script by selecting table below.
For the items I used 3 groups and 3 linked objects to make this example mor interesting.
...

try the sample scene from try2script.
you script doesn't work right for it. you are doing a lot of unnecessary things (most are about opened groups)... the only function that you need for cloned selection is the function that returns only highest by hierarchy nodes. after that you have to clone only them with their children if the 'root' node is not a group member.
so you need three simple functions:

 fn getRoot node nodes: = ...
 fn getRootNodes nodes: = ...
 mapped fn attachNodeToAllGroupInstances node group includeChildren:#all = ...
 

and this will be a line to call:

 attachNodeToAllGroupInstances (getRootNodes nodes:(selection as array)) <group> includeChildren:#all
 
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:44 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.