Notifications
Clear all

[Closed] attach object/group to all group instances

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

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!

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)

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)

Try with this

with undo "attach_to_groups" on
(
	with redraw off
	(
		 -- rest of code
	)
)

Thx, Branko, it’s working now! I will add the tool soon!

Page 4 / 4