Hey does anyone know if there's an easy way to convert this string -
<hou.Keyframe t=0.4 expr='bezier()' lang=exprLanguage.Hscript v=0 s=0 auto_slopes=True in a=0.133333 out a=0.333333 use_accel_ratio=True>
back into a keyframe?
Thanks!
Pete
Parsing a keyframe from a string in Python
2410 7 1-
- peteski
- Member
- 518 posts
- Joined: Dec. 2013
- Offline
-
- alexwheezy
- Member
- 209 posts
- Joined: Jan. 2013
- Offline
-
- peteski
- Member
- 518 posts
- Joined: Dec. 2013
- Offline
-
- alexwheezy
- Member
- 209 posts
- Joined: Jan. 2013
- Offline
-
- jsmack
- Member
- 7850 posts
- Joined: Sept. 2011
- Offline
Why do you need to parse this string in the first place? If you have this string, then at some point you would have had the python object that generated it. The python object makes interfacing each item directly possible. Are you trying to recover data that was somehow archived this way as a last resort?
In the future I recommend using the hscript opscript command. It is far more foolproof than the keyframe object methods, and you don't have to worry about whether you need to set a string keyframe or a standard keyframe. It has the other benefit that it can be executed directly instead of parsing.
In the future I recommend using the hscript opscript command. It is far more foolproof than the keyframe object methods, and you don't have to worry about whether you need to set a string keyframe or a standard keyframe. It has the other benefit that it can be executed directly instead of parsing.
-
- peteski
- Member
- 518 posts
- Joined: Dec. 2013
- Offline
Hey jsmack,
Yes I'm generating the string, I'm just messing around with saving off a bunch of animation to load back in at another time. So I'm writing data out to a txt file. I could seperate each element of the key manually I guess but since it wrote it out in that specific way I thought there might be a simple way to read that back in.
Yes I'm generating the string, I'm just messing around with saving off a bunch of animation to load back in at another time. So I'm writing data out to a txt file. I could seperate each element of the key manually I guess but since it wrote it out in that specific way I thought there might be a simple way to read that back in.
-
- mchaput
- Staff
- 484 posts
- Joined: July 2005
- Offline
Parsing a string like this isn't as easy as you might think. Especially given that:
* It doesn't have a very regular structure (mostly attributes in the form x=y, but also free-floating keywords like “in” and “out” where it isn't clear how they should be interpreted).
* It has quoted strings that would need to be parsed specially if they allow quoting inside.
It's definitely not a quick answer… you'd need to write a parser or else learn how to use a Python parsing library.
IMHO the best bet would be for you to generate the string as JSON instead of as a custom one-off format. That would make writing the info out and reading it back in trivial.
* It doesn't have a very regular structure (mostly attributes in the form x=y, but also free-floating keywords like “in” and “out” where it isn't clear how they should be interpreted).
* It has quoted strings that would need to be parsed specially if they allow quoting inside.
It's definitely not a quick answer… you'd need to write a parser or else learn how to use a Python parsing library.
IMHO the best bet would be for you to generate the string as JSON instead of as a custom one-off format. That would make writing the info out and reading it back in trivial.
Edited by mchaput - June 1, 2017 11:54:01
-
- peteski
- Member
- 518 posts
- Joined: Dec. 2013
- Offline
-
- Quick Links