Notifications
Clear all

[Closed] Walk backwards up TV subAnims

 PEN

I don’t know why I’m having so much trouble with this. I thought it would be easy.

I have a track selected in TV, I want to get its subAnim, that is easy as there is

		numSub= (tv.getSelectedSubNum i)
		parent=(tv.getParent index)
		subAnimName=(getSubAnim parent numSub)

Now I want to get the parents subAnimName and it’s parents subAnimName and so on. I would rather not have to keep having it selecting each as it goes as it looks so far that is all I can do.

Any suggestions?

5 Replies
 PEN

I’m also trying with refs.dependents and trying to walk backwards. Again this I can do because it will return the whole tree but not as subAnimNames, only as the controllers and nodes.

 PEN

Also interesting that if there is no controller on the track that you have selected in trackview you can’t get that track

I was hoping to get somewhere with .getIndex , but eventually one of the objects returned is a ParamBlock2 for which it can’t get any index.

And indeed, most of those ‘trackviews’ interface methods appear to be UI based. Even if you do have a track ‘selected’, but collapsed up the hierarchy, maxscript will tell you there’s no selection.

refs.dependents it is, then. I think the only thing you should have to do to get the SubAnim, rather than the controller, is to loop over the subAnims of the refs.dependents results and check if that SubAnim -is- that controller.
I’ll bet that’s going to fall apart once you have instanced controllers within the same hierarchy, though :hmm:

 PEN

Well that also still doesn’t solve the issue that when you select a track without a controller it return undefined. You can’t get where you are at all. The next thing that I think I will have to do is what I have been asking for for years and that is a proper tool fro working with controllers. I have simple ones but I keep having hopes that I will not have to write it all my self:S

This is a tricky one! I feel a bit of a headache coming on now. Having to do so many workarounds!

Heres a function I put together that will return the subAnimIndex of a track without it having to be currently selected in the track view. Might be of help if anybody else is playing around with this. I might have been looking in the wrong spots, but I couldn’t find one in the help files anywhere.

  Pass the function a track and it's parent track and it will return the subAnimIndex if it is found.   I was using tv.getSelection and tv.getParentOfSelected to get these tracks. The function will return undefined if the track is not found or either obj or parentObj are not valid.

The track needs to have a controller assigned to it otherwise it won’t work, so that problem still exists. It does work with paramBlocks though.

fn getSubAnimIndex parentObj obj =
   (
   	if isValidObj obj and isValidObj parentObj then
   	(
   		parentSubNames = getSubAnimNames parentObj
   		
   		for i = 1 to parentSubNames.count do
   		(
   			subName = parentSubNames[i]
   			if getPropertyController parentObj subName == obj then
   			(
   				return i
   			)
   		)
   	)
   	return undefined
   )