转换/映射linux参考路径而不改变文件?

发布于 2024-10-15 19:41:44 字数 866 浏览 2 评论 0原文

目前在我的客户需要参考文件路径的项目中 保留 linux 格式。例如,

A.ma , referencing objects from --> //linux/project/scene/B.ma
B.ma , referencing objects from --> //linux/project/scene/C.ma

我们这里的大多数 Maya 许可证都适用于 Windows。我可以运行一个 Python脚本,将所有路径转换为windows路径并保存 文件。例如

Z:\project\scene\B.ma

,但是我正在尝试找出一种方法来执行此操作而不转换 或更改原始文件......我会尝试解释我想要做什么。

  • 运行脚本以打开文件。
  • 该脚本检查 linux 格式的引用路径,以及所有 层次结构中的子路径。
  • 将所有路径映射到相应的 Windows 格式路径。
  • 使动画师能够正常“保存”文件,而无需运行单独的保存脚本。

用Python脚本可以实现这个目的吗?或者我需要一个 完全编译的插件可以让它工作吗?

任何建议都将不胜感激。


编辑:感谢您的意见。

再澄清一点。这些项目是由一家远程公司为我们设置的,部分要求是我们必须保持路径不变。它们是绝对的道路,我们在这件事上别无选择。

我们在 Fedora 工作站上匹配挂载 //linux/ 。该驱动器被映射到我们 Windows 工作站上的 Z:\。我们只有 2 个 Linux 版 Maya 许可证,这就是我尝试这样做的原因。

Currently on a project that my client needs the reference file path to
remain in linux format. For example

A.ma , referencing objects from --> //linux/project/scene/B.ma
B.ma , referencing objects from --> //linux/project/scene/C.ma

Most of our Maya license here however are on Windows. I can run a
Python script that convert all the paths windows paths and save the
file. For example

Z:\project\scene\B.ma

However I'm trying to figure out a way to do this without converting
or altering the original file.... I'll try to explain what I'm trying to do.

  • Run the script to open the file.
  • The script checks for the linux formatted reference path, and all
    child path down the hierarchy.
  • Maps all paths to their appropriate windows formatted paths.
  • Giving the animators the ability to "save" files normally without running a separate save script.

Is this possible to achieve this with Python script? Or will I need a
fully-compiled plug in to get this to work?

Any suggestion is greatly appreciated.


edit: Thank you for your input.

A little more clarification. The projects were set up for us by a remote company and part of the requirement is that we have to keep the path as is. They come as absolute path and we have no choice in that matter.

We match the mount //linux/ on our Fedora workstations. That same drive is mapped to Z:\ on our windows workstations. We only have 2 Maya license for Linux tho which is why I'm trying to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

摘星┃星的人 2024-10-22 19:41:44

这是一个解决方案。第一步是创建一个 dict 来跟踪 linux/windows 引用(不要忘记导入 regexp 的 re 模块):

>>> def windows_path(path):
    return path.replace('//linux', 'Z:').replace('/', '\\')

>>> reg = re.compile('(\w+\.ma) , referencing objects from --> (.*)')
>>> d = {}
>>> for line in open('D:\\temp\\Toto.txt'):
    match = reg.match(line)
    if match:
        file_name = match.groups()[0]
        linux_path = match.groups()[1]
        d[file_name] = (linux_path, windows_path(linux_path))


>>> d
{'B.ma': ('//linux/project/scene/C.ma', 'Z:\\project\\scene\\C.ma'),
 'A.ma': ('//linux/project/scene/B.ma', 'Z:\\project\\scene\\B.ma')}

然后你只需要循环这个 dict 要求保存文件:

>>> for file_name in d.keys():
    s = raw_input('do you want to save file %s ? ' % file_name)
    if s.lower() in ('y', 'yes'):
        # TODO: save your file thanks to d[file][0] for linux path, 
        # d[file][1] for windows path
        print '-> file %s was saved' % file_name
    else:
        print '-> file %s was not saved' % file_name


do you want to save file B.ma ? n
-> file B.ma was not saved
do you want to save file A.ma ? yes
-> file A.ma was saved

Here is a solution. First step is to create a dict that keeps track of linux/windows references (don't forget to import the re module for regexp):

>>> def windows_path(path):
    return path.replace('//linux', 'Z:').replace('/', '\\')

>>> reg = re.compile('(\w+\.ma) , referencing objects from --> (.*)')
>>> d = {}
>>> for line in open('D:\\temp\\Toto.txt'):
    match = reg.match(line)
    if match:
        file_name = match.groups()[0]
        linux_path = match.groups()[1]
        d[file_name] = (linux_path, windows_path(linux_path))


>>> d
{'B.ma': ('//linux/project/scene/C.ma', 'Z:\\project\\scene\\C.ma'),
 'A.ma': ('//linux/project/scene/B.ma', 'Z:\\project\\scene\\B.ma')}

Then you just need to loop on this dict to ask for file save:

>>> for file_name in d.keys():
    s = raw_input('do you want to save file %s ? ' % file_name)
    if s.lower() in ('y', 'yes'):
        # TODO: save your file thanks to d[file][0] for linux path, 
        # d[file][1] for windows path
        print '-> file %s was saved' % file_name
    else:
        print '-> file %s was not saved' % file_name


do you want to save file B.ma ? n
-> file B.ma was not saved
do you want to save file A.ma ? yes
-> file A.ma was saved
那支青花 2024-10-22 19:41:44

许多 Windows 应用程序会将带有两个前导“/”的路径解释为 UNC 路径。我不知道 Maya 是否是其中之一,但尝试一下。如果 Maya 可以理解类似“//servername/share/foo”的路径,那么您所需要做的就是设置一个名为“linux”的 SMB 服务器,并且路径将按原样工作。我猜想这实际上是您的客户端所做的,因为路径“//linux”在仅限 Linux 的环境中没有意义。

Many Windows applications will interpret paths with two leading "/"s as UNC paths. I don't know if Maya is one of those, but try it out. If Maya can understand paths like "//servername/share/foo", then all you need to do is set up a SMB server named "linux", and the paths will work as they are. I would guess that this is actually what your client does, since the path "//linux" would not make sense in a Linux-only environment.

旧人哭 2024-10-22 19:41:44

您可以使用环境变量来执行此操作。 Maya 将扩展文件路径中存在的环境变量,您可以使用 Maya.env 为每个平台正确设置它们。

You can use environment variables to do this. Maya will expand environment vars present in a file path, you could use Maya.env to set them up properly for each platform.

雨落□心尘 2024-10-22 19:41:44

您正在寻找的是 dirmap mel 命令。它对您的文件完全无干扰,因为您只需定义从 linux 路径到 windows 的映射和/或反之亦然。 Maya 将在内部应用映射来解析路径,而在保存文件时不会更改它们。

要设置 dirmap,您需要运行 MEL 脚本,该脚本在 Maya 启动时发出相应的命令。 UserSetup.mel 可能是放置它的一个地方。

有关更多详细信息,请参阅官方文档 - 此特定链接指向 Maya 2012,但该命令在 Maya 7.0 及更早版本中也可用:
http://download.autodesk.com/global/docs/maya2012 /en_us/Commands/dirmap.html

What you are looking for is the dirmap mel command. It is completely non-intrusive to your files as you just define a mapping from your linux paths to windows and/or vice versa. Maya will internally apply the mapping to resolve the paths, without changing them when saving the file.

To setup dirmap, you need to run a MEL script which issues the respective commands on maya startup. UserSetup.mel could be one place to put it.

For more details, see the official documentation - this particular link points to maya 2012, the command is available in Maya 7.0 and earlier as well though:
http://download.autodesk.com/global/docs/maya2012/en_us/Commands/dirmap.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文