Kredka Strikes Back "Controllers"

I'm back:)
Before I start writing 500 lines of code I have question about controllers to ask.
I search for this in help/net, no idea how to do it.

I have to do 2 operations
1) check for particular controller in objects selection like:
for obj in selection do
check if obj has given controller if yeas add object to list

2) take these objects with particular controllers and remove from them controllers.

It will be few controllers but let say now I'm looking for one particular notetrack.

I can do it like this:
notetracksobjmdq=#()
for s in selection do
(
tr1=classof s.controller == prs
if clasacontroler=true then ntrack=hasNoteTracks s.pos.controller
if ntrack=true then append notetracksobjmdq s
...... etc
)

but it will take hundreds of lines to define and check all controllers in this way. Is way to check for particular controller in selection and remove this controllers simpler than this one above? I need it for selection. Like always grateful for any help.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kredka's picture

One last question

One last question regarding this function I hope.
Due to I must use it to find and replace specific kind of controllers on selected objects - notetracks and retimers most likely, I noticed that function replaceController work for all kind of controllers except this two. Irony. I already asked about it but without replacing this two, whole effort It's no use. Is it way to make this function work also on retimers and notetracks. I already played with your code but now idea why this two don't work on retimers and notetracks.

kredka's picture

Great thanks to You milion

Great thanks to You milion times.

kredka's picture

Work :) :)

It work, You right, I test it again and it work great. Thank You very much.
For the very first time I called function in wrong way. My bad.

Is is possible to use your function to select two or more controllers at once like:
controllerObj trackClass:linear_float,float_limit,...etc mode:#selection
If it's complex then let's skip this one.

This is free question.
I use this code to find and replace also retimers and notertacks but it seams there is no results for only this particular controllers, for rest work fine. Are notertrack and retimers need to be treat in some special way to fount it and remove.

barigazy's picture

...

Now U can assigne multiple controller classes as array in "trackClasses" argument

fn controllerObj trackClasses: mode: = if trackClasses.count != 0 do
(
	local arr = #()
	case mode of
	(
		#selection:
		(
			if selection.count != 0 do
			(	
				for s in selection do
				(
					for c in trackClasses where  (getClassInstances c target:s).count != 0 do (append arr s ; exit)
				)
			)
		)
		#objects:
		(
			local ctrlsArr = #()
			for c in trackClasses where (ctrls = getClassInstances c).count != 0 do join ctrlsArr ctrls
			if ctrlsArr.count != 0 do
			(
				local temp = #()
				for c in ctrlsArr do
				(
					for n in (refs.dependentNodes c) do appendIfUnique temp n.name
				)
				if temp.count != 0 do for s in temp do append arr (getNodeByName s)
				free temp ; free ctrlsArr
			)
		)
	) ; arr
)

Example:

(controllerObj trackClasses:#(linear_float, float_list, scale_list) mode:#selection)

bga

kredka's picture

after selecting all objects

after selecting all objects script should select only box001,box002,box003 which posses linear_float controllers also this controllers should be replaced

scene is in max2010

AttachmentSize
test.max 200 KB
barigazy's picture

...

Code works as expected. Run line by line. You don't have to select anything
only if you use "mode" argument as #selection

arr = controllerObj trackClass:linear_float mode:#objects
-- print to see result
print arr
-- now replace linear_float with bezier_float
replaceController arr whichCtrl:linear_float withCtrl:bezier_float

In the motion panel you can see that $Box003 and the other nodes fro arr not have any more linear float controller

bga

kredka's picture

sorry one more time

Great thanks for this but my understanding of function is so poor.

I hope I did in right way, please correct me if not, just for test, I created box with some linear_float controller on position and rotation, select objects with those controllers launch function and arry was empty:

fn controllerObj trackClass: mode: =
(
local arr = #()
case mode of
(
#selection:
(
if selection.count != 0 do
(
for s in selection where (getClassInstances trackClass target:s).count != 0 do append arr s
)
)
#objects:
(
if (ctrls = getClassInstances trackClass).count != 0 do
(
local temp = #()
for c in ctrls do
(
for n in (refs.dependentNodes c) do appendIfUnique temp n.name
)
if temp.count != 0 do for s in temp do append arr (getNodeByName s)
)
)
) ; arr
)
 
controllerObj trackClass:linear_float mode:#selection
 
linearfloatobjects=arr as string
messagebox linearfloatobjects

also tried replacecontroller function, but I'm sure i'm calling it in incorrect way because selected objects controllers linear_float was still not replaced:

fn replaceController nodes whichCtrl: withCtrl: = if nodes.count != 0 do
(
for o in nodes where (ctrls = getClassInstances whichCtrl target :o).count != 0 do
(
for c in ctrls do
(
execute ((exprForMAXObject c)+" = createInstance "+ withCtrl as string)
)
)
)
 
replaceController whichCtrl:linear_float

Can You tell me what I'm doing wrong here?

barigazy's picture

...

can you post a test scene

bga

kredka's picture

Great thanks for this but my

Great thanks for this but my understanding of function is so poor.

I hope I did in right way, please correct me if not, just for test, I created box with some linear_float controller on position and rotation, select objects with those controllers launch function and arry was empty:

< ss >
fn controllerObj trackClass: mode: =
(
local arr = #()
case mode of
(
#selection:
(
if selection.count != 0 do
(
for s in selection where (getClassInstances trackClass target:s).count != 0 do append arr s
)
)
#objects:
(
if (ctrls = getClassInstances trackClass).count != 0 do
(
local temp = #()
for c in ctrls do
(
for n in (refs.dependentNodes c) do appendIfUnique temp n.name
)
if temp.count != 0 do for s in temp do append arr (getNodeByName s)
)
)
) ; arr
)
 
controllerObj trackClass:linear_float mode:#selection
 
linearfloatobjects=arr as string
messagebox linearfloatobjects
 
<code>
 
 
also tried replacecontroller function, but I'm sure i'm calling it in incorrect way because selected objects controllers linear_float was still not replaced:
 
<code>
fn replaceController nodes whichCtrl: withCtrl: = if nodes.count != 0 do
(
for o in nodes where (ctrls = getClassInstances whichCtrl target :o).count != 0 do
(
for c in ctrls do
(
execute ((exprForMAXObject c)+" = createInstance "+ withCtrl as string)
)
)
)
 
replaceController whichCtrl:linear_float
 
<code>
 
Can You tell me what I'm doing wrong here?
kredka's picture

Great thanks for this but my

Great thanks for this but my understanding of function is so poor.

I hope I did in right way, please correct me if not, just for test, I created box with some linear_float controller on position and rotation, select objects with those controllers launch function and arry was empty:

fn controllerObj trackClass: mode: =
(
local arr = #()
case mode of
(
#selection:
(
if selection.count != 0 do
(
for s in selection where (getClassInstances trackClass target:s).count != 0 do append arr s
)
)
#objects:
(
if (ctrls = getClassInstances trackClass).count != 0 do
(
local temp = #()
for c in ctrls do
(
for n in (refs.dependentNodes c) do appendIfUnique temp n.name
)
if temp.count != 0 do for s in temp do append arr (getNodeByName s)
)
)
) ; arr
)

controllerObj trackClass:linear_float mode:#selection

linearfloatobjects=arr as string
messagebox linearfloatobjects

also tried replacecontroller function, but I'm sure i'm calling it in incorrect way because selected objects controllers linear_float was still not replaced:

fn replaceController nodes whichCtrl: withCtrl: = if nodes.count != 0 do
(
for o in nodes where (ctrls = getClassInstances whichCtrl target :o).count != 0 do
(
for c in ctrls do
(
execute ((exprForMAXObject c)+" = createInstance "+ withCtrl as string)
)
)
)

replaceController whichCtrl:linear_float

Can You tell me what I'm doing wrong here?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.