Maya Python-将zip文件嵌入到maya文件中吗? [英] Maya Python - Embed zip file into maya file?

查看:176
本文介绍了Maya Python-将zip文件嵌入到maya文件中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是另一个堆栈线程的建议,我终于回头了.这是关于如何将工具嵌入到maya文件中的讨论的一部分.

This was a suggestion from another stack thread that I'm finally getting back to. It was part of a discussion about how to embed tools into a maya file.

您可以将整个内容编写为python包,将其压缩,然后将zip文件的二进制内容填充到fileInfo中.当您需要编码时,请在用户的$ MAYA_APP_DIR中查找;如果没有zip,则将fileInfo的内容作为zip写入磁盘,然后将zip插入sys.path

You can write the whole thing as a python package, zip it, then stuff the binary contents of the zip file into a fileInfo. When you need to code, look for it in the user's $MAYA_APP_DIR; if there's no zip, write the contents of the fileInfo to disk as a zip and then insert the zip into sys.path

源讨论是: 将脚本复制到脚本中 Maya Python创建并使用压缩包?

到目前为止,编程尚可,但我想我遇到了麻烦.当我尝试这样做时:

So far the programming is going okay, but I think I hit a snag. When I attempt this:

with open("..directory/myZip.zip","rb") as file:
    cmds.fileInfo("myZip", file.read())

..然后是I ..

..and then I..

print cmds.fileInfo("myZip",q=1)

我知道

[u'PK \ 003 \ 004 \ 024']

[u'PK\003\004\024']

当将zip文件作为文本文档读取时,这是乱码第一行的错误翻译.

which is a bad translation of the first line of gibberish when reading the zip file as a text document.

如何将zip文件作为二进制文件嵌入到maya文件中?

How can I embed my zip file into my maya file as binary?

===================

====================

更新: Maya不喜欢直接读取utf-8编码的zip文件来写入文件.我发现了将其制成可以写入的可接受字符串的各种方法,但是解码回文件似乎无效.我现在看到Theodox的建议是将其写入二进制文件并将其放入fileInfo节点.

Update: Maya doesn't like writing to the file as a direct read of the utf-8 encoded zip file. I found various methods of making it into an acceptable string that could be written, but the decoding back to the file didn't appear to work. I see now that Theodox's suggestion was to write it to binary and put that in the fileInfo node.

一个人如何编码,存储然后解码以稍后写入文件?

How can one encode, store and then decode to write to file later?

如果要使用以下示例将其转换为二进制文件:

If I were to convert to binary using for instance:

' '.join(format(ord(x), 'b') for x in line)

我需要什么代码将其转换回原始的utf-8 zip信息?

What code would I need to turn that back into the original utf-8 zip information?

推荐答案

您可以在此处找到相关代码:

you can find related code here:

http://tech- artist.org/forum/showthread.php?4161-Maya-API-Singleton-Nodes&highlight=mayapersist

相关位是

  import base64
  encoded = base64.b64encode(value)
  decoded = base64.b64decode(encoded)

基本上是相同的想法,除了使用base64模块而不是binascii.只要使用可逆方法,任何将任意字符流转换为ASCII安全表示形式的方法都可以正常工作:您需要注意的潜在问题是数据块中的字符看起来像是玛雅字符. quote-一个开放的引号int fileInfo将在MA文件中杂乱无章.

basically it's the same idea, except using the base64 module instead of binascii. Any method of converting an arbitary character stream to an ascii-safe representation will work fine, as long as you use a reversable method: the potential problem you need to watch out for is a character in the data block that looks to maya like a close quote - an open quote int he fileInfo will be messy in an MA file.

此示例使用YAML进行任意键/值对,但该部分与存储二进制内容无关.我已经将此技术用于相当大的数据(如果我记得的话,最大可达640k),但我不知道它在Maya中可以存储的内容是否有上限

This example uses YAML to do arbitrary key-value pairs but that part is irrelevant to storing the binary stuff. I've used this technique for fairly large data (up to 640k if i recall) but I don't know if it has an upper limit in terms of what you can stash in Maya

这篇关于Maya Python-将zip文件嵌入到maya文件中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆