From d2f3184eaaef6af7cc5d8f8e0a500a276d12fe7a Mon Sep 17 00:00:00 2001 From: "Asad M. Zaman" Date: Fri, 27 May 2005 01:25:32 +0000 Subject: [PATCH] fixed the referencing bug where mayacopied file was still pointing to artists tree --- pandatool/src/mayaprogs/mayaCopy.cxx | 65 +++++++++++++++++++++++++--- pandatool/src/mayaprogs/mayaCopy.h | 1 + 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/pandatool/src/mayaprogs/mayaCopy.cxx b/pandatool/src/mayaprogs/mayaCopy.cxx index 16c76842b7..1caa0f7556 100644 --- a/pandatool/src/mayaprogs/mayaCopy.cxx +++ b/pandatool/src/mayaprogs/mayaCopy.cxx @@ -24,6 +24,7 @@ #include "pre_maya_include.h" #include +#include #include #include #include @@ -41,6 +42,8 @@ //////////////////////////////////////////////////////////////////// MayaCopy:: MayaCopy() { + _replace_prefix = "none"; + set_program_description ("mayacopy copies one or more Maya .mb files into a " "CVS source hierarchy. " @@ -61,6 +64,12 @@ MayaCopy() { "source filename before it is copied into the tree.", &CVSCopy::dispatch_none, &_keep_ver); + add_option + ("rp", "replace_prefix", 80, + "use this prefix when replacing reference with the recently copied file from the " + "source filename before it is copied into the tree.", + &CVSCopy::dispatch_string, NULL, &_replace_prefix); + add_path_replace_options(); } @@ -185,13 +194,6 @@ copy_maya_file(const Filename &source, const Filename &dest, return false; } - // Now write out the Maya file. - if (!_maya->write(dest)) { - maya_cat.error() - << "Cannot write " << dest << "\n"; - return false; - } - // Finally, copy in any referenced Maya files. unsigned int num_refs = refs.length(); @@ -202,6 +204,40 @@ copy_maya_file(const Filename &source, const Filename &dest, } */ + if (num_refs != 0) { + if (_replace_prefix.find("none") != string::npos) { + maya_cat.error() + << "External references exist: " + << "please make sure to specify a _replace_prefix with -rp option\n"; + exit(1); + } + } + + for (unsigned int ref_index = 0; ref_index < num_refs; ref_index++) { + // one thing we need to do is rename the path to the base file + // that it is referencing to. This will guarantee that the + // refencing will stay in the copied directory. Only way I could + // make it work properly is through following MEL command. the + // pear character is used as an example. The maya API calls of + // removeReference and reference didn't work for the animations + // file -loadReference "mtpRN" -type "mayaBinary" -options "v=0" + // "m_t_pear_zero.mb"; + Filename filename = + _path_replace->convert_path(Filename::from_os_specific(refs[ref_index].asChar())); + + string execString = "file -loadReference \"" + _replace_prefix + "RN\" -type \"mayaBinary\" -options \"v=0\" \"" + filename.get_basename() + "\";"; + maya_cat.info() << "executing command: " << execString << "\n"; + //MGlobal::executeCommand("file -loadReference \"mtpRN\" -type \"mayaBinary\" -options \"v=0\" \"m_t_pear_zero.mb\";"); + MGlobal::executeCommand(MString(execString.c_str())); + } + + // Now write out the Maya file. + if (!_maya->write(dest)) { + maya_cat.error() + << "Cannot write " << dest << "\n"; + return false; + } + for (unsigned int ref_index = 0; ref_index < num_refs; ref_index++) { //maya_cat.info() << "refs filename: " << refs[ref_index].asChar() << "\n"; //maya_cat.info() << "os_specific filename: " << Filename::from_os_specific(refs[ref_index].asChar()) << "\n"; @@ -221,6 +257,21 @@ copy_maya_file(const Filename &source, const Filename &dest, } } + /* + for (unsigned int ref_index = 0; ref_index < num_refs; ref_index++) { + Filename filename = + _path_replace->convert_path(Filename::from_os_specific(refs[ref_index].asChar())); + status = MFileIO::reference(MString(filename.get_basename().c_str())); + if (!status) { + status.perror("MFileIO reference"); + } + status = MFileIO::removeReference(refs[ref_index].asChar()); + if (!status) { + status.perror("MFileIO removeReference"); + } + } + */ + return true; } diff --git a/pandatool/src/mayaprogs/mayaCopy.h b/pandatool/src/mayaprogs/mayaCopy.h index 0508b72e2e..fce8ac4725 100644 --- a/pandatool/src/mayaprogs/mayaCopy.h +++ b/pandatool/src/mayaprogs/mayaCopy.h @@ -72,6 +72,7 @@ private: bool collect_shader_for_node(const MDagPath &dag_path); bool _keep_ver; + string _replace_prefix; PT(MayaApi) _maya; MayaShaders _shaders;