Notifications
Clear all

[Closed] Problem with maxscript containers

“This is a bit technical, you may have to reread in order to understand what I’m trying to do”.

Need a bit of help sorting this out, I have a problem with getting the correct data in some of these loops however currently this script does output the correct amount of containers and the correct amount of things in them but does not input the correct actual thing in them.

First of all, here is what im working with~

In this pic there are 3 meshes named Object 1,2, and 3 which are in Containers 1 and 2.
“Object 1 is in Container 1, Object 2 and 3 is in Container 2”

START OF CODE~

CONTAINER_array=#()
CONTAINERCOUNT_array=#()
OBJECT_array=#(); counter=1; meshCounter = 0; pointerCounter = 0;

childrenArray = for hlp in helpers where classof hlp == Container collect hlp.children;

clearlistener()

for ca in childrenArray do ( for c in ca do(
if superclassof c == GeometryClass do (
OBJECT_array [counter] = meshCounter; meshCounter = meshCounter +1; counter = counter +1;
);
)
)

for hlp in helpers where classof hlp == Container do(
append CONTAINER_array hlp.children.count
)

for MDL = 1 to 1 do(
append CONTAINERCOUNT_array CONTAINER_array.count
for GR = 1 to CONTAINERCOUNT_array[MDL] do(
if CONTAINER_array[GR] < 2 then(
–OBJECTARRAY
)
else(
for IG = 1 to CONTAINER_array[GR] do(
–OBJECTARRAY
)
)
)
)

END OF CODE~

Print out object array you will notice in this specific file and it outputs “0,1,2”. That is the meshes themselves just FYI.

The reason why there is an IF and ELSE statement in this code is because the IF is supposed to only have one Object in it and the Else has multiple Objects in it. The IG loop controls the amount in the ELSE statement.

Basically this is what I need. Where you see –OBJECTARRAY in the code is where I need the OBJECT_array to go but if you try to do that, it will not give you the correct item inside of their loops. In this code I need Object 1 to be in the “If” statement and Object 2 and 3 to be in the Else statement in the “IG” section. The problem is that the IF and ELSE loop as it sits does not relay the correct Object only the correct amount.

7 Replies

what is the final idea? get an array of containers and corresponding to it an array of contained nodes?

if so there is a way how to do it:


struct ContainerContent (container, node, content)
fn collectContainers nestedContent:on = 
(
	for c in (getclassinstances container) collect 
	(
		d = ContainerContent container:c node:(refs.dependentnodes c firstonly:on)
		c.GetContentNodes nestedContent &d.content
		d
	)
)
collectContainers()

1 Reply
(@troopermanaic)
Joined: 11 months ago

Posts: 0

Problem with that is that I have other data that I didn’t include because it wasn’t necessary for this problem. I am trying to make a binary file and it does things differently. In these IF’s and ELSE’s I have writes for things that don’t belong to just this problem.

Although that lays out things nicely, I doubt it would work with that im trying to do because it doesn’t conform to how im trying to write data. You basically get what im trying to achieve though.

Unless someone is smart with binary file formats and I can whip up a sample explaining what every part of it does and you can see why im trying to do this. Basically it works with numbers and re-purposes them into shorts and longs in this way. This script sample is the only logical way to write the data correctly to the way the file is setup that I can see.

it’s very hard to read you unformatted code. i don’t want to format it myself. and i still don’t understand what you are doing.

1 Reply
(@troopermanaic)
Joined: 11 months ago

Posts: 0

Alright, here is the code in a sample file with a sample .max

What im trying to do is that im trying to get the OBJECT_array to print correctly in the IF and ELSE part of the GR loop. “The reason why the IG loop exists in the else statement is to show that there are more then 1 mesh in that container. The IF statement means only 1 mesh in the container”.

https://mega.co.nz/#!GVRWgTiB!WKFO6G7dADzYh9v1SKm5MyXccp_ZinOphRQaBaxHx_A

I organize and formated properly your code but still not understand what do you want to print?

(
   	CONTAINER_array=#()
   	CONTAINERCOUNT_array=#()
   	OBJECT_array=#()
   	counter=1
   	--meshCounter = 0
   	pointerCounter = 0
   
   	childrenArray = for hlp in helpers where isKindOf hlp Container collect 
   	(
   		append CONTAINER_array hlp.children.count
   		hlp.children
   	)
   
   	clearlistener()
   
   
   	for ca in childrenArray do 
   	( 
   		for c in ca where isKindOf c GeometryClass do
   		(
   			OBJECT_array[counter] = (counter-1)
   			counter += 1
   		)
   	)
 
   	append CONTAINERCOUNT_array CONTAINER_array.count
 
   	for GR = 1 to CONTAINERCOUNT_array[1] do
   	(
   		if CONTAINER_array[GR] < 2 then
   		(
   		--OBJECTARRAY
   		)
   		else
   		(
   			for IG = 1 to CONTAINER_array[GR] do
   			(
   			--OBJECTARRAY
   			)
   		)
   	)
   )

I don’t know how to explain it any better, I was completely through.

Imm’a have to visually simplify this

In the IF section, if there is 1 mesh inside of a container then the OBJECT_array should print out which object its trying to represent in 1

Same thing with ELSE except that in the ELSE section the IG loop represents how many meshes should be in the container.

This is how the script currently prints

0
1
1
2
3
3

6 items in total which is the correct amount but the reason why this is wrong is because these numbers are supposed to represent the mesh number not container number.

Loop should look like this instead

0
1
2
3
4
5

Lets break this down,

0
–CONTAINER 1

1
2
–CONTAINER 2

3
–CONTAINER 3

4
5
–CONTAINER 4

Visual representation of desired outcome

I simplified my script a bit also got rid of the IF and ELSE statement. I still have the same problem though but it is easier to understand now…

I linked the script and a test file with it, specifically my problem lies within the “IG” loop where it does not get the OBJECT_array correctly.

The “GR” loop is the amount of containers
The “IG” loop is the amount of objects in the container

So now you see that I cannot get all the meshes because there is nothing that puts them in order inside the loop, its just the amount that is correct.

If anyone can find a way around this while retaining the writes, I would be so grateful.
“Notice I wrote “OBJECT_array[???]” in the script, that is where the problem lies”.

[ https://mega.co.nz/#!2NBFwD6Z!ijQ2B6xc4wdpEXrFygrNWHUZVQxiywBfnAcXAkdBx2U
Include file key]( https://mega.co.nz/#!2NBFwD6Z!ijQ2B6xc4wdpEXrFygrNWHUZVQxiywBfnAcXAkdBx2U
Include file key)