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   #46
here is a sample of sensibly organized scene:
we have furniture items: tables, chairs, cocktail tables, etc.
we have some on table things: plates, forks, knives, glasses, etc

furniture might be grouped in groups: two chair table, three... four, double table, table and cocktail table.., etc.
table things also can be specifically grouped...

and now is the same task: Get a node (or many nodes from table things) or whole table thing group and attach it to any furniture group or just a member of the group.

does it make scene?
but the tool provided does do it for root heads only... and we can't use only selected members to clone or attach to. Do we have to write new tool every time when we slightly modify the rules?
 
Old 06 June 2013   #47
Originally Posted by denisT: here is a sample of sensibly organized scene:
we have furniture items: tables, chairs, cocktail tables, etc.
we have some on table things: plates, forks, knives, glasses, etc

furniture might be grouped in groups: two chair table, three... four, double table, table and cocktail table.., etc.
table things also can be specifically grouped...

and now is the same task: Get a node (or many nodes from table things) or whole table thing group and attach it to any furniture group or just a member of the group.

does it make scene?
but the tool provided does do it for root heads only... and we can't use only selected members to clone or attach to. Do we have to write new tool every time when we slightly modify the rules?

I agree with you. But maybe is better to write now when we starts this topic a new tool "Group Manager" something like "Outliner" or "Named Selection Sets" dialog which is BTW broken in max2014. I was thinking of simple "tree list" dialog which will shows only current scene groups. Then it would be very easy to assign a selections to any group even if the group is nested. Also we can add all the options like: attach, detach, open, close group etc.
I'd love to participate in this challenge
This idea can be related to Denis previous thread "a discussion about a delicate matter... "
because we will talk about mxs and .net controls
__________________
Looking in the right side. [bgaTools]

Last edited by gazybara : 06 June 2013 at 07:09 PM.
 
Old 06 June 2013   #48
I'm very close to the FINISH

try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "• • •"
(

	fn filtGroup o = isGroupMember o or isGroupHead o
		
	fn getRootClosedGroupHead node = if node != undefined do
	(
		if isgroupmember node then
		(
			if isOpenGroupHead node.parent then 
			(	
				detachNodesFromGroup node
				node
			)	
			else	
				getRootClosedGroupHead node.parent
		)
		else node
	)
	--<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>
	fn getRootGroupHead node = if node != undefined do
	(
		if isgroupmember node then
		(
			getRootGroupHead node.parent
		)
		else node
	)
	pickbutton pick "PickGroup" pos:[5,5] width:100 height:20 filter:filtGroup
	on pick picked destObj do if destObj != undefined and selection.count !=0 do
	(
		attachingNodes = #()
		attachingNodesInstances = #()
		destinationGroups = #()
		local rootGroup = getRootGroupHead destObj

		InstanceMgr.GetInstances rootGroup &groups		
		for i = 1 to groups.count do
			appendIfUnique destinationGroups (getRootGroupHead groups[i])		
		
		for s in selection do
			if (q=(getRootClosedGroupHead s)) != rootGroup then 
				appendIfUnique attachingNodes q
		nodeCounts = 0
		if destinationGroups.count > 1 and attachingNodes.count>0 then 
		(
			with redraw off 
			(
				for i = 1 to destinationGroups.count where destinationGroups[i] != rootGroup do
				(
					maxOps.cloneNodes attachingNodes cloneType:#instance newNodes:&objs
					for o in objs do
					(	
						appendIfUnique attachingNodesInstances (getRootGroupHead o)
						if attachingNodesInstances.count>nodeCounts then
						(	
							nodeCounts+=1
							tm = o.transform * (inverse rootGroup.transform)
							o.transform = tm*destinationGroups[i].transform
							--attachNodesToGroup o destinationGroups[i]
						)	
					)	
				)
			)
		)
		else print "make another selection"
	)
)
createDialog bgaRoll 110 30 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)


The only thing is that I don't know how to attach attachingnodes to destinationgroups! If attachingnodes are groups, then I get error if I attach! If I don't use attach, the script is working fine! Thank you Denis and Branko for your great begining!
 
Old 06 June 2013   #49
Finished

try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "• • •"
(

	fn filtGroup o = isGroupMember o or isGroupHead o
		
	fn getRootClosedGroupHead node = if node != undefined do
	(
		if isgroupmember node then
		(
			if isOpenGroupHead node.parent then 
			(	
				detachNodesFromGroup node
				node
			)	
			else	
				getRootClosedGroupHead node.parent
		)
		else node
	)
	--<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>
	fn getRootGroupHead node = if node != undefined do
	(
		if isgroupmember node then
		(
			getRootGroupHead node.parent
		)
		else node
	)
	pickbutton pick "PickGroup" pos:[5,5] width:100 height:20 filter:filtGroup
	on pick picked destObj do if destObj != undefined and selection.count !=0 do
	(
		attachingNodes = #()
		attachingNodesInstances = #()
		destinationGroups = #()
		local rootGroup = getRootGroupHead destObj

		InstanceMgr.GetInstances rootGroup &groups		
		for i = 1 to groups.count do
			appendIfUnique destinationGroups (getRootGroupHead groups[i])		
		
		for s in selection do
			if (q=(getRootClosedGroupHead s)) != rootGroup then 
				appendIfUnique attachingNodes q
		nodeCounts = 0
		if destinationGroups.count > 1 and attachingNodes.count>0 then 
		(
			with redraw off 
			(
				for i = 1 to destinationGroups.count where destinationGroups[i] != rootGroup do
				(
					maxOps.cloneNodes attachingNodes cloneType:#instance newNodes:&objs
					for o in objs do
					(	
						appendIfUnique attachingNodesInstances (getRootGroupHead o)
						if attachingNodesInstances.count>nodeCounts then
						(	
							nodeCounts+=1
							tm = o.transform * (inverse rootGroup.transform)
							o.transform = tm*destinationGroups[i].transform
						)
					)
					attachNodesToGroup objs destinationGroups[i] 	
				)
				attachNodesToGroup attachingNodes rootGroup 
				
			)
		)
		else print "make another selection"
	)
)
createDialog bgaRoll 110 30 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)
 
Old 06 June 2013   #50
Originally Posted by denisT: and undo "Attach" on to pick object at least


Denis, please help to make my tool undoable! I don't understand how

Here is the final code

try(destroyDialog ::bgaRoll)catch()
rollout bgaRoll "• • •"
(

	fn filtGroup o = isGroupMember o or isGroupHead o
		
	fn getRootClosedGroupHead node = if node != undefined do
	(
		if isgroupmember node then
		(
			if isOpenGroupHead node.parent then 
			(	
				detachNodesFromGroup node
				node
			)	
			else	
				getRootClosedGroupHead node.parent
		)
		else node
	)
	--<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>
	fn getRootGroupHead node = if node != undefined do
	(
		if isgroupmember node then
		(
			getRootGroupHead node.parent
		)
		else node
	)
	pickbutton pick "PickGroup" pos:[5,5] width:100 height:20 filter:filtGroup
	on pick picked destObj do if destObj != undefined do
	(
		attachingNodes = #()
		attachingNodesInstances = #()
		destinationGroups = #()
		if selection.count	== 0 then
			print "select attaching nodes first :)"
		else
		(		
			local rootGroup = getRootGroupHead destObj

			InstanceMgr.GetInstances rootGroup &groups		
			for i = 1 to groups.count do
				appendIfUnique destinationGroups (getRootGroupHead groups[i])		
	
			for s in selection do
				if (q=(getRootClosedGroupHead s)) != rootGroup then 
					appendIfUnique attachingNodes q
			nodeCounts = 0
			if destinationGroups.count > 1 and attachingNodes.count>0 then 
			(
				with redraw off 
				(
					for i = 1 to destinationGroups.count where destinationGroups[i] != rootGroup do
					(
						maxOps.cloneNodes attachingNodes cloneType:#instance newNodes:&objs
						for o in objs do
						(	
							appendIfUnique attachingNodesInstances (getRootGroupHead o)
							if attachingNodesInstances.count>nodeCounts then
							(	
								nodeCounts+=1
								tm = o.transform * (inverse rootGroup.transform)
								o.transform = tm*destinationGroups[i].transform
							)
						)
						attachNodesToGroup objs destinationGroups[i] 	
					)
					attachNodesToGroup attachingNodes rootGroup 
				
				)
				print "Successful :)" 
			)
			else print "make another selection :("
		)
	)
)
createDialog bgaRoll 110 30 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)
 
Old 06 June 2013   #51
Try with this
with undo "attach_to_groups" on
(
	with redraw off
	(
		 -- rest of code
	)
)
__________________
Looking in the right side. [bgaTools]
 
Old 06 June 2013   #52
Thx, Branko, it's working now! I will add the tool soon!
 
Old 06 June 2013   #53
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
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 11:25 PM.


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