Notifications
Clear all

[Closed] Maxscript container help please

Ok I have a bit of a problem with 3DS Max right now, basically I need to make arrays for different items inside containers, here is what I got so far


clearlistener()

for obj in geometry where classof obj == Editable_Mesh do(
	m = snapshotAsMesh obj
)

for hlp in helpers where classof hlp == container do(
	print hlp.children
)

As you can see from the image below basically I have a few meshes, points, and containers in the scene.

When you run the code above you get,

$Editable_Mesh:Box001 @ [1.668987,-1.495510,0.000000]
$Editable_Mesh:Cone001 @ [-46.257660,47.650322,0.000000]
$Editable_Mesh:Teapot001 @ [55.768753,-52.102142,0.000000]
$Point_Helper:Point003 @ [69.874283,38.212112,0.000000]
$Point_Helper:Point001 @ [-1.901779,-78.986145,0.000000]
$Point_Helper:Point002 @ [-16.389603,10.233978,0.000000]
$Editable_Mesh:Sphere001 @ [-30.795021,-31.702766,0.000000]
$Editable_Mesh:Box002 @ [27.118874,33.827194,0.000000]

As you can see there are 8 enteries, In the listener, I need to make 2 arrays: one for Point_Helpers and another for Editable_Mesh. It needs to look like this
Editable_Mesh array = 1,1,2,5,5
Point_Helper array = 3,4,4

Problem is that I don’t know how to isolate the data and give them a number in order in the hlp loop. Can anyone help me with this?

9 Replies

Because my question changed I am bumping this.

Do you mean like this here?

-- create Array
allMesh = for m in geometry where superclassof m == GeometryClass collect m
allHelper = for h in helpers where classof h == point collect h

-- print Value
for i in allMesh do print i
for j in allHelper do print j
1 Reply
(@troopermanaic)
Joined: 10 months ago

Posts: 0

That doesn’t solve my problem. I am writing an exporter for a hex-binary file type and I need the array in numbers only. “has to be in the hlp loop only because of the sorting”.

Basically if a mesh or point is in the first container then the array needs to have 1 in it to begin.

Say for example say I got 2 meshes in container 1 and 4 meshes in container 3, I need to make an array like this~ 1,1,3,3,3,3

Also for example say I got 3 points in container 1, 1 point in container 2 and 3 points in container 5, I need to make an array like this 1,1,1,2,5,5,5

This sequential array needs to be created to work correctly in a loop I have in my script that compares what objects are where.

Oh I misunderstud you. You mean something like this.

-- function with parameter
fn createArray type=(
	myArray = #()
	counter = 1;
	for index = 1 to ((containerArray = for c in Helpers where classof c == Container collect c).count)do(
		for o in containerArray[index] where classof o == type OR superclassof o == type do(
			myArray[counter] = index
			counter =counter+1;
		)
	)
	return myArray
)

--function Call
createArray Point
createArray Box
createArray GeometryClass
2 Replies
(@troopermanaic)
Joined: 10 months ago

Posts: 0

WHOA dude I would have never gotten that. You are a wizard. THANKS SO MUCH!

(@gazybara)
Joined: 11 months ago

Posts: 0

Try this aproch. Both methods work only on opened containers

fn intArr objclass =
(
	local result = #(), nodes = #()
	if (cArr = getClassInstances Container).count != 0 do
	(
		for i = 1 to cArr.count do
		(
			cArr[i].GetContentNodes off &nodes
			if nodes.count != 0 do
			(
				for n in nodes where isKindOf n objclass do append result i
			)
		)
	) ; result
)
intArr box

It’s my pleasure

Oh this is a good tip
what means the “&” for “nodes”

This is from mxs help doc

<void>.GetContentNodes nestedContainerNodes <&node array>contentNodes
  contentNodes is Out parameter
  Returns an array of the content nodes of the container into the second by-reference parameter. 
  If the first argument is passed as true, nested containers will also be processed. 
  If the first argument is passed as false, only the content of the current container will be returned.
 

Now to better understand this here two different examples with same result.
Let say we have an array filled with integers and floats and we need to get two arrays for each number type.
#1 method

nums = #(5,58, 11, 885, 0.56, 23.65, 300, 501.6)
  fn collectNumbers1 arr &intArr =
  (
  	intArr = #() ; floatArr = #()
  	for n in arr do
  	(
  		if isKindOf n integer then append intArr n else append floatArr n
  	)
  	floatArr
  )
  collectNumbers1 nums &intArr
  --#(0.56, 23.65, 501.6)
  intArr
  --#(5, 58, 11, 885, 300)

#2 method

fn collectNumbers2 arr &a =
  (
  	for n in arr collect (if isKindOf n float then n else (append a n ; dontcollect))
  )
intArr = #()
  floatArr = collectNumbers2 nums &intArr
  --#(0.56, 23.65, 501.6)
  intArr
  --#(5, 58, 11, 885, 300)

For more info read this topic
Edit: I corrected second method