When object deleted, delete children. Huh?


#2

Try with #nodePreDelete callbacks.


#3

it will not help… if you check events for delete process the first will be Unlink (unlink all children of a deleting node), and only after PreDelete


#4

So okay, working with linked hierarchies like that won’t work. But using custom parameters will.

ca = attributes ca
(
parameters ca rollout:ca
(
nodes type:#nodeTab tabSize:0 tabSizeVariable:on
)

rollout ca "ca"
(
)

) – end ca

delete objects
theSphere = sphere()
custAttributes.add theSphere ca #unique
theSphere.nodes = #()

for i = 1 to 5 do
(
b = box pos:[i*10,i*10,i*10]
append theSphere.nodes b
)

when theSphere deleted id:#del obj do
(
nodes = obj.nodes
for i = nodes.count to 1 by -1 where nodes[i] != undefined do delete nodes[i]
)

Now, to make things a little trickier. I’d like to make it so that if ANY of the associated nodes are deleted, all of them will be. So I tried the following, and it works. But if used several times in succession (I think about 6 or 7), it crashes Max. Any ideas about that?

delete objects
deleteAllChangeHandlers id:#del

ca = attributes ca
(
	parameters ca rollout:ca
	(
		nodes type:#nodeTab tabSize:0 tabSizeVariable:on

		on nodes tabChanged do
		(
			local owner = (refs.dependents (custAttributes.getOwner this))[1]

			d = false
			for i = this.nodes.count to 1 by -1 where this.nodes[i] == undefined do
				d = true

			if d == true do
			(
				for i = this.nodes.count to 1 by -1 where this.nodes[i] != undefined do
					delete this.nodes[i]

				if owner != undefined do
					delete owner
			)
		)
	) -- end parameters

	rollout ca "ca"
	(
	)
) -- end ca

delete objects
theSphere = sphere()
custAttributes.add theSphere ca #unique
theSphere.nodes = #()

for i = 1 to 5 do
(
	b = box pos:[i*10,i*10,i*10]
	append theSphere.nodes b
)

when theSphere deleted id:#del obj do
(
	nodes = obj.nodes
	for i = nodes.count to 1 by -1 where nodes[i] != undefined do	delete nodes[i]
)

#5

any other solution ? the truth is I got same problem …


#6

I had a friend try it out and he claims to have run it over 40 times in a row without incident. At least now I know it’s not just me. And I don’t even know how begin figuring out the cause :confused:


#7

 global ContainerAttrib = attributes ContainerAttrib 
 (
 	local handler
 	fn getNode = (refs.dependentnodes (custattributes.getowner this) firstonly:on)
 	fn constructNode node: = 
 	(
 		if node == unsupplied do node = getNode()
 		if isvalidnode node do
 		(
 			if handler != undefined do deleteChangeHandler handler
 			handler = when node deleted do 
 			(
 				delete (for n in this.nodes where isvalidnode n collect n)
 				this.nodes = #()
 			)
 		)
 	)
 	parameters params 
 	(
 		nodes type:#nodeTab tabsizevariable:on
 		on nodes set val do constructNode()
 	)
 	on update do constructNode()
 	on load do constructNode()
 )
 (
 	delete objects
 	b = dummy name:"master"
 	custattributes.add b ContainerAttrib
 	b.ContainerAttrib.constructNode()
 	b.nodes = for k = 1 to 5 collect (point pos:[k*20,0,0] wirecolor:orange) 
 )
 

most important it’s undoable/redoable, and you can also add and delete dependent nodes as well


Tigger actions on deletetion? (from within a plugin?)
#8

Definitely an improvement, and probably stable enough for my needs, but at least for me it still crashes after running it (for some reason always exactly) 22 consecutive times. (And I don’t just mean if I spam the script. Even if I wait a while before executing it each time it still happens.)

For my current project, I probably won’t ever run into a situation where I would need to run this repeatedly like that, but I’d still like to know WHY it’s happening :confused:


#9

your code might crash by any reason. but … do you say that my code crashes being run isolated?


#10

well… the code i’ve posted doesn’t crash. never…


#11

I’m saying that code you gave me, copied and pasted exactly as is, is crashing after being run repeatedly a whole bunch of times. At least on my machine, running Max 2012 64-bit. I can try it on my laptop later on I guess and see if I get the same results, but you’re saying it isn’t causing any problems on your side, so it may run fine. I guess I will find out.


#12

well… get a new max scene… means load the max. how do you crash the max using my code and only my code?


#13

you’ve posted some of your… contrivances about how to handle node transforms. forget about it now. let’s focus just on the ‘deleting all dependent nodes with deleting of their master’


#14

That’s exactly what I’m doing.

Copy code, open Max, new file, paste code.
Ctrl-E. It works.
Ctrl-E a second time. It works again.
Ctrl-E 19 more times, it works.
Run it a 22nd time, though, and “An error has occurred and the application will now close…”


#15

what is the error message?


#16

“An error has occurred and the application will now close. Do you want to attempt to save a copy of the current scene? (yes/no)”


#17

do you know that is sunday tomorrow? but… i will go tomorrow to the office to prove myself that i’m not an idiot yet.


#18

Eek. No copy of Max at home, eh? It can wait till monday, I’m going to a presentation thing tomorrow, so I won’t be around for part of the day anyway.


#19

one day i’ve dissuaded myself to do any ‘work’ at home. because … i’ve been working some days for 23 hours… :wink:


#20

it doesn’t crash for me… tell me all steps those make max crash.


#21

it doesn’t crash for me… tell me all steps those make max crash.

That’s exactly what I’m doing.

 Copy code, open Max, new file, paste code.
 Ctrl-E. It works.
 Ctrl-E a second time. It works again.
 Ctrl-E 19 more times, it works.
 Run it a 22nd time, though, and "An error has occurred and the application will now close..."
By the way, this happens on both my desktop and laptop (both running Max 2012 64-bit). 22 times exactly to crash the program.