Page MenuHome

Pack/unpack Python functions for more data types
AbandonedPublic

Authored by Campbell Barton (campbellbarton) on Mar 8 2014, 1:40 PM.

Diff Detail

Event Timeline

Brecht Van Lommel (brecht) requested changes to this revision.Mar 8 2014, 2:23 PM

This won't work, as it's missing the actual function implementations to pack fonts and sounds.

The second argument to RNA_def_function should be the name of the C function that packs/unpacks the sound/font, but these do not exist currently and need to be implemented. You can look at rna_Image_pack and rna_Image_unpack to see how to make this work.

Further I'll leave this to @Campbell Barton (campbellbarton) who created this Quick Hacks tasks I think.

I was lost because of I couldn't find something similar to rna_Image_pack and rna_Image_unpack for sound/font. Now you erased my doubts. Thanks,

Kévin Dietrich (kevindietrich) updated this revision to Unknown Object (????).Mar 8 2014, 3:33 PM
Campbell Barton (campbellbarton) requested changes to this revision.May 5 2014, 5:25 AM

@Kévin Dietrich (kevindietrich). this patch cant have been tested.

  • RNA_api_vfont, RNA_api_sound arent called.
  • use_mono option is ignored.

Please make sure patches compile and are tested before submitting.

I apologize for the inconvenience, I did screw up big time on this... I might have gone a little too fast.

No worries, just double check your patch works, you can even attach small python script to this page? (double checking the code is doing whats expected is often half the work here) :)

Kévin Dietrich (kevindietrich) updated this revision to Unknown Object (????).May 8 2014, 8:42 PM
  • Call RNA_Sound_api, RNA_VFont_api
  • move some includes in the RNA_RUNTIME block
  • actually do something with "use_mono"

I did a little more work on this task. There are some issues/things that I can't comprehend at the moment:

  • I don't really know how to handle "use_mono";
  • the attached script doesn't really work for me: bpy.ops.sound.pack() fails with "invalid context" (maybe is it because I ran it in the text editor?)
  • bpy.ops.font.pack() is missing and that puzzles me (maybe a typo?)

Here is my test script (by no means perfect):

I don't know why, but this is giving me problems. Closing it for now, will reopen when/if I feel like finishing this.

Not sure why you are calling bpy.ops.font.pack() the whole point of this patch is to avoid having to use operators.

Looks like this patch is nearly finished. If you dont have time someone else can probably finish it off.

Taking this one... (so its not marked as abandoned) but feel free to commandeer back and update.

Campbell Barton (campbellbarton) planned changes to this revision.

Not sure why you are calling bpy.ops.font.pack() the whole point of this patch is to avoid having to use operators.

Looks like this patch is nearly finished. If you dont have time someone else can probably finish it off.

Then I don't get how to use it :P

It's not really a time issue, but maybe a lack of understanding of the python API. I actually kinda forgot about this one until a couple of days ago where I made some quick changes, will update with them and we'll see what you think.

Kévin Dietrich (kevindietrich) edited edge metadata.
  • Apply patch
  • Merge branch 'master' into pack_unpack

You would access these functions like this...

bpy.data.sounds["MySound"].pack()

or...

font = bpy.data.fonts.load(filepath)
font.pack()

The reason for having these api calls is they dont depend on the context, you could for example - loop over all sounds/fonts and unpack them.

Thanks for the quick explanation :).

I tried and the patch seems to work as expected, though apparently I do not have all the necessary libs to have audio support in Blender and calling Sound.pack(use_mono=True) causes a crash here, I'd need to install those libs to check if this is the cause of the crash. I will update the patch then.

Kévin Dietrich (kevindietrich) edited edge metadata.
  • Fix bug in Sound.pack()
  • Remove use_mono option as this is to be handled while loading/opening the file
  • Fix rna_Sound_pack() signature and use reports in rna_VectorFont_pack()

Well, I think the patch is pretty much done now (you tell me :) ). I ended up removing the use_mono option for Sound.pack() as it is supposed to be done when opening the file, also I don't remember why I added it in the first place (the initial patch being almost one year old).

I also used this quick script for my testing:

.

Campbell Barton (campbellbarton) requested changes to this revision.Feb 6 2015, 5:08 PM
Campbell Barton (campbellbarton) edited edge metadata.

You can avoid using global (G which we're trying to get rid of... slowly) by using FUNC_USE_MAIN, see rna_RenderLayer_remove

Otherwise, think this patch is looking quite close to being done.

Note, in future, if you dont know how to test your patch, please say so early on.
Its OK if your not sure of something - but just say so to avoid a lot more confusion.

This revision now requires changes to proceed.Feb 6 2015, 5:08 PM
Kévin Dietrich (kevindietrich) edited edge metadata.
  • Avoid using Global
  • Quick cleanup