Notifications
Clear all

[Closed] select objects by order number

 em3

Hello! I have a thousand objects all appended with _0001 – 1000

I am trying to loop through them and modify thier properties in the order of thier names. I think I need to dump then into an array and then find them in the array based on thier order. This way I can have multiple arrays and execute each array in sequence. Problem is, I don’t know where to start. Can someone get me started? Thanks!

4 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

these functions will be helpful for you for sure:


fn getNodeID node = 
(
 n = trimright node.name "0123456789"
 id = substring node.name (n.count+1) -1
 if id.count > 0 then id as integer else -1 
)
fn makeSuffix id places:4 = if iskindof id integer do
(
 id = id as string
 while id.count < places do id = "0" + id
 id
)
fn findByID list id asnode:on = 
(
 local n = 0
 for k=1 to list.count while n == 0 where isvalidnode (node = list[k]) and matchpattern node.name pattern:("*" + id) do
 (
  if asnode then n = node else n = k
 )
 n
)
fn sortByID n1 n2 = 
(
 id1 = getNodeID n1
 id2 = getNodeID n2
 if id1 < id2 then -1 else if id1 > id2 then 1 else 0
)

 em3

Denis, your a badass. I will try these and let you know.

Right now I have the objects falling into place but they fall randomly in the order that they were put into the array. This will help me put them in a particular order. Thanks again.

 em3

OK, so now I am gathering the objects in my scene, assigning their name as “obj_z position” and then dumping their names into an array with the great help of Denis’s script.

by this logic when I animate them they will fall in the order from lowest to highest. Quite clever of me to figure out I must say! /pat

Now when I sort them they are sorting the 141’s before the 68’s. How do you overcome it in maxscript? (make sure they are integers!)

Objs = objects as array
myName = #()
for o in Objs do
(
	
	
	getNodeID o
)
	
	fn getNodeID node =
(
	
 n = trimright node.name "0123456789"
 id = substring node.name (n.count+1) -1
 if id.count > 0 then id as integer else -1
	append myName id
)
sort myName
print myName

result:

"144"
"144"
"162"
"170"
"175"
"181"
"3"
"64"
"68"
"98"

EDIT: this works

Objs = objects as array
myName = #()
for o in Objs do
(
	getNodeID o
		--actionMan.executeAction 0 "40022"

	fn getNodeID node =
(
 n = trimright node.name "0123456789"
 id = substring node.name (n.count+1) -1
 if id.count > 0 then id as integer else -1
	 myID = id as integer
	append myName myID
	
)
sort myName
print myName

and alas it is only now that I realize I was supposed to use ALL of those functions. :argh:

 em3

So, here I am with all of your above code in place.

What do I assign to i coming out of your functions. This is what is causing my mind to explode one small piece at a time.

Objs = objects as array
myName = #()
for o in Objs do
(
	getNodeID o
		--actionMan.executeAction 0 "40022"

	fn getNodeID node =
(
 n = trimright node.name "0123456789"
 id = substring node.name (n.count+1) -1
 if id.count > 0 then id as integer else -1
	 --myID = id as integer
-- 	append myName myID
	
)
fn makeSuffix id places:4 = if iskindof id integer do
(
 id = id as string
 while id.count < places do id = "0" + id
 id
)
fn findByID list id asnode:on = 
(
 local n = 0
 for k=1 to list.count while n == 0 where isvalidnode (node = list[k]) and matchpattern node.name pattern:("*" + id) do
 (
  if asnode then n = node else n = k
 )
 n
)
fn sortByID n1 n2 = 
(
 id1 = getNodeID n1
 id2 = getNodeID n2
 if id1 < id2 then -1 else if id1 > id2 then 1 else 0
)

So we have gotten the numbers from the name, now it’s time to make them the keys in the curve editor which is done with i. Except I have no idea what to assign to i to make it work.



		i = ???
		print myID
		--print o.name	
-- 		myNum = o.pos.z
-- 		my2ndNum = myNum+20
		myZ = o.pos.z
		print myNum
		o.visibility = bezier_float() -- Track View: Add Visibility Track
		addNewKey o.visibility.controller i #select
		i+=10
		addNewKey o.visibility.controller i #select
		o.visibility.controller.keys[1].value = 0
		o.visibility.controller.keys[2].value = 1
		addNewKey o.pos.controller.Z_Position.controller (i-10) #select
		addNewKey o.pos.controller.Z_Position.controller i #select
		o.pos.Z_Position.controller.keys[1].value = 100+myZ
		o.pos.Z_Position.controller.keys[2].value = myZ
		--actionMan.executeAction 0 "40022"
)