Page 1 of 1

Get undefined value type from known channel?

Posted: Fri Sep 16, 2016 10:30 am
by rylleman
I want to get a value from a key at a given channel at a specific frame. The value (and channel) can be of any type. Can I get that value found without having to specify which type of value I'm looking for?

Re: Get undefined value type from known channel?

Posted: Fri Sep 16, 2016 8:11 pm
by synthsin75
Lua variables don't have declared types, so you can give them anything. But if you need to populate an LM value (the kind you need to declare as new_local), you will need to know which type of LM value the channels is looking to populate. I assume using ChannelType() would tell you.

Re: Get undefined value type from known channel?

Posted: Fri Sep 16, 2016 10:02 pm
by rylleman
Thank you.

To get a value with GetValue() I need to know which AnimVal I'm after (value1 = bone.fAnimPos:GetValue(frame). I also need to know (in this case) which bone I'm trying to get a value from.

I'm going through all channels and subchannels for a layer, trying to get values. (Using the lm_listchannels script for that part). Subchannels contains one value for one bone per frame; a Skeleton with 4 bones has 4 subchannels for bone rotation.
I can't figure out how to tell which bone a given subchannel belongs to. ChannelType() returns an integer; 1 for bone angle, 2 for bone Translation, 6 for Layer Translation etc.
- Do I need to have a lot of ifs here? (if ChannelType = 1 then property = fAngle etc.) and how do i tell which bone or other sublayer thing the given subchannel belongs to?

Re: Get undefined value type from known channel?

Posted: Fri Sep 16, 2016 10:23 pm
by synthsin75
I would assume the sub-channels are by bone ID?

Re: Get undefined value type from known channel?

Posted: Fri Sep 16, 2016 11:18 pm
by rylleman
Probably, but I can't figure how to get that information from the channel.

Also I really would like to get the values disregarding what type they are, I just need to compare two values, not going to populate anything from them. (Apart from a generic valueX variable, which doesn't need to know what kind of value it is).
I'm going to work on all the channel types, which there is 72 of... It will be a lot of code just to select the right kind of value for any of them...

Re: Get undefined value type from known channel?

Posted: Sat Sep 17, 2016 12:04 am
by synthsin75
I'm afraid I'd have to see some code snippets to fully appreciate the problem. Do you have an example of where you're at?

Re: Get undefined value type from known channel?

Posted: Sat Sep 17, 2016 6:19 pm
by Fazek
Lua tables are very flexible. Instead of

Code: Select all

channel= bone.fAnimPos
You can write

Code: Select all

ch_name= "fAnimPos"
...
channel=bone[ch_name]
So you don't really need to repeat the same code again and again for the different channels, you can use the channel name as a parameter in your loops. There are animated channels in the document, in the layers, and in some contents of the layers too (points, curves, bones...). Maybe you need to parse all of these to find the channels you need.

You may take a look into my csv export code (viewtopic.php?f=12&t=29429 fa_export_csv.lua: the FA_export_csv:IsAnimated() function). It's also an ugly code though, repeating the same "if"s several times.