Notifications
Clear all

[Closed] How to pick a group object?

just simple as:


iskindof node geometryclass and canconvertto node editable_mesh

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Ok you talking about “pickObject” node. Now I get it.
Next is getRootGroupHead
I supose that I need to check if group is opened, right?

nope… try again

This freeze max, i not know why

	
fn getGrandParentGroup obj = 
	(
		groupsArr = #()
		while (obj.parent != undefined) do (if isGroupHead (grp=obj.parent) do append groupsArr grp)
		groupsArr[groupsArr.count]
	)

Branko, this is infinite while loop. The obj never changes, so its parent never changes and the max continue to execute the while loop.

The function below will return all parents of the selected object. So, for the test scene it will return $Box005. Then can be checked which object in the allObjParents are group head or group member.


(
   (
	local allObjParents = #()
	function FindRootParrent obj =
	(	   
		parent = obj.parent
		if parent != undefined then
		(
			append allObjParents obj
			FindRootParrent parent
		)
		else
		(
			append allObjParents obj
			obj
		)
		--
		objParents
	)
	FindRootParrent $Box001
	format "allObjParents: % 
" allObjParents
)
1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

I know how to find all parents but are you try to find root group in Denis example (“Group003”). He mentioned one line of code for that:)

Denis have one line solution, I have 100 lines solution – ugly, but I hope my solution to works properly no matter of how big the code is.


(
	 local allObjParents = #()
	 function FindRootParrent obj =
	 (	   
		 parent = obj.parent
		 if parent != undefined then
		 (
			 append allObjParents obj
			 FindRootParrent parent
		 )
		 else
		 (
			 append allObjParents obj
			 obj
		 )
		 --
		 objParents
	 )
	 FindRootParrent $Box001
	 
	notFound = false
	groupHead = undefined
	for i = allObjParents.count to 1 by -1 while notFound == false do
	(
		if (isGroupHead allObjParents[i] or isOpenGroupHead allObjParents[i]) and (not (isGroupMember allObjParents[i])) do
		(
			groupHead = allObjParents[i]
			notFound = true
		)
	)
	format "groupHead: % 
" groupHead	
)

Can you try this

fn FindRootGroup obj &master=
(	   
	if (p = obj.parent) != undefined do (if isGroupHead p do master = p ; FindRootGroup p &master)
)
FindRootGroup $Box001 &master
master

What do you think? Close enough?

this is not for picking node. it’s for loop where we have to collect only real geometries which can be converted to simple object plug-in

Return the correct result.
Denis have to say how close it is to his solution.
Mine is far far away.

and to find a root group head we really need only one line:


while <condition> do <iteration>

1 Reply
(@gazybara)
Joined: 11 months ago

Posts: 0

Always mystery with Denis.
whether the recursive function bad solution or one of many?

it doesn’t need recursion

Page 3 / 6