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.
barigazy's picture
kredka's picture

yes, but I need two

yes, but I need two actions:
one) check which objects in selection contain those controllers
two) remove those controllers from selected objects

I would be very thankful for help.

barigazy's picture

...

Now U need to know that U can't delete some controlles of nodes but just resete or replace.
This is the fn for that

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

example:
Let's say we have a box object and "linear float" controlle assigned in "RotationY" track. By default this track is "bezier_float"

obj = Box isSelected:on
rotY_controller = obj[3][2][2].track
rotY_controller = linear_float()
-- now I want to reset this to deafult
-- It's important to add controller class in arguments "whichCtrl" and "withCtrl"
replaceController selection whichCtrl:linear_float withCtrl:bezier_float

Also be careful which controller replace with.

bga

barigazy's picture

...

If you want to collect all abject by specified controller class then use this fn

-- "trackClass" argument is the class of controller that you searching for
-- "mode" argument can be #objects or #selection
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
)

exampe:
Let's say that you want to collect all object that have assigned "Linear Float" controller. For this it's not important to select any node

controllerObj trackClass:linear_float mode:#objects

But if you want to work ei. look through objects in selections then chose other mode like this

controllerObj trackClass:linear_float mode:#selection

bga

barigazy's picture

...

Do U want remove all controlles by specified class from the selection?

bga

Comment viewing options

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