A couple questions about when construct usage


#2

of course if you know the node which you want to monitor it’s better to construct only this node.
if you want to listen all nodes transform changes it’s probably better to use the NodeEventCallback mechanism by checking #controllerOtherEvent


#3

That’s actually what I’ve been doing up to now, and may continue to do so. I’m just looking at all the possibilities.


#4

Okay, so… when I run the following:

delete objects
deleteAllChangeHandlers id:#test

for i = 1 to 5 do
	b = box pos:[i*10,i*10,i*10]

for o in objects where classOf o == box do
(
	when transform o changes id:#test handleAt:#redrawViews do
	(
		if not mouse.buttonStates[1] do format "$% transform changed
" o.name
	)
)

I get the error

-- Compile error: No outer local variable references permitted here:  o
--  In line: 		if not mouse.buttonStates[1] do format "$% transform changed
" o.

Now, when working with the delete form, you get “when o deleted id:#id obj do…” Instead of working with o as a local variable, is there ANY way to similarly force the construct to recognize the node it is operating on??


#5

you can do it as:


 for o in objects where classOf o == box do
 (
 	when transform o changes id:#test handleAt:#redrawViews o do
 	(
 		if not mouse.buttonStates[1] do format "$% transform changed
" o.name
 	)
 )
 

but better is:


objs = for obj in objects where classOf obj == box collect obj
 when transform objs change id:#test handleAt:#redrawViews obj do
 (
 	if not mouse.buttonStates[1] do format "$% transform changed
" obj.name
 )
 

#6

Trying to get this working with my ca script. In this case obj is returning a value of “ReferenceTarget:ParamBlock2”

I have absolutely no idea what I’m supposed to do with that and the documentation is pretty much useless on the subject.

Any way to get it to point to the referenced nodes?

(Also, this script still crashes Max after 6 or 7 times reloading it. Am I doing something wrong?)

delete objects
deleteAllChangeHandlers id:#tf

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

		on nodes tabChanged do
		(
			when transform this.nodes change id:#tf handleAt:#redrawViews obj do
			(
				format "obj: %
" obj
			) -- end construct (transform)
		)
	) -- end parameters

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

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]
)

#7

I haven’t been able to figure out what I’m supposed to do.

when parameters nodes change handleAt:#redrawViews obj do
format "obj: %
" obj

always returns

obj: ReferenceTarget:ParamBlock2

I don’t know how to get access to anything using that. ParamBlock2 has no name, id, properties methods, or anything that I can figure out how to access. All I can get from it is its class, “ParamBlock2ParamBlock2”.

Everything I’ve been able to find online relating to ParamBlock2 refers strictly to SDK usage. Since custom attributes work along the same lines as scripted plugins I can see where that might be the case, but there is absolutely nothing I can find showing how to get at it from Maxscript.


#8

In your CA… nodes is an array of nodes. So to see if a node’s transform has changed don’t you need to index into nodes? Just my uneducated guess.


#9

So how do I do that? I’d considered the possibility that obj was somehow referring to the nodes array, or the custom attribute, or the owner of said attribute, but it has no attributes, no parameters, no index or anything that I am able to get at.

How do I paramblock2?


#10

Try a for loop to iterate thru your nodes array… and use the index operator: nodes[i]


#11

Where do I do that, how do I call it, and how will that give me what I need?

I’ve been trying to get this figured out for a week and my brain is fried. I’m sure what you’re saying has some basis in something but right now I’m at the point where nothing makes any sense at all.


#12

For now I guess I’m stuck with using

when transform nodes change handleAt:#redrawViews do
(
if mouse.buttonStates[1] == false do
format "% transform changed
" selection[1]
)

Unfortunately, this will only pick up user driven changes in transformations, not anything caused by a script :confused:


#13

Look in the Maxscript help for info on parameter block event handlers.


#14

Look in the Maxscript help for info on parameter block event handlers. Try using the “parameters” attribute in your when construction rather than “transform” as “parameters” will catch any changes to the object.


#15

I’ve tried it with both transform and parameters, that part doesn’t make much of a difference as far as that goes.

I can’t find anything useful in the maxscript documentation on parameter block event handlers.

Also, I tried putting this in my parameters definition:


		on nodes tabChanged change do
		(
			if change == #refDeleted and ownerDeleteHandler != undefined do
			(
				owner = (refs.dependentNodes (custAttributes.getOwner this))[1]
				delete owner
			)

			for n in nodes where n != undefined do
			(
				when parameters n change handleAt:#redrawViews obj do
				(
					if mouse.buttonStates[1] == false do
						format "% parameters changed
" obj
				)
			)
		)
	) -- end parameters

Works fine initially, but if I delete and undelete a node, it stops working.


Question about the When Construct
#16

what do you mean by “driven by a script”? in time? animated by a controller? in this case you have to use controller. when construct is not for that.


#17

Yeah, you’re right. You know, I… don’t even know any more. I’m too burned out too think clearly. Using the selection is fine for what I need. Just forget I mentioned it -___-


#18

Parameter event handlers are handlers like:
on … set … do
on … get … do

Sorry I wasn’t much help.


#19

look at this snippet… i might help

delete objects
b = dummy name:#master 
in b (global p = point name:#p pos:[20,0,0] wirecolor:orange)
c = b.pos.controller = Position_List()
s = c.available.controller = Position_Script()
s.addobject "pos_monitor" p.pos.controller
s.setexpression "print pos_monitor.value; [1,1,1]"

#20

I’ll look into it a bit more tomorrow. I tried it earlier and it crashed Max when I tried to delete something, and I was thinking “no, not going through this again…” However I tried it again just now and haven’t been able to replicate the problem from earlier, so it was likely some other thing that was responsible.


#21

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.