Get undefined value type from known channel?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Get undefined value type from known channel?

Post 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?
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Get undefined value type from known channel?

Post 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.
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Re: Get undefined value type from known channel?

Post 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?
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Get undefined value type from known channel?

Post by synthsin75 »

I would assume the sub-channels are by bone ID?
User avatar
rylleman
Posts: 750
Joined: Tue Feb 15, 2005 5:22 pm
Location: sweden
Contact:

Re: Get undefined value type from known channel?

Post 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...
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Get undefined value type from known channel?

Post 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?
User avatar
Fazek
Posts: 246
Joined: Thu Apr 13, 2006 1:37 pm
Location: Hungary
Contact:

Re: Get undefined value type from known channel?

Post 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.
- - - Fazek
Post Reply