Exemple #1
0
        private void CopySolidworksFile(string file_from, string file_to, string replease_from, string replact_to)
        {
            ISldWorks swApp      = Utility.ConnectToSolidWorks();
            string    source     = System.IO.Path.GetDirectoryName(file_from);
            string    target     = System.IO.Path.GetDirectoryName(file_to);
            string    sourcefile = file_from;;
            string    tempfile   = System.IO.Path.GetFileName(file_to);

            bool traverse        = false;
            bool search          = false;
            bool addreadonlyinfo = false;

            object[]  depends     = null;
            string[]  sourcefiles = null;
            string[]  targetfiles = null;
            int       idx         = 0;
            int       sourcecount = 0;
            int       copyopt     = 0;
            int       errors      = 0;
            int       lind        = 0;
            ModelDoc2 doc         = default(ModelDoc2);

            // sourcefile = file_from;

            tempfile = file_to;// System.IO.Path.GetDirectoryName(file_to);
            lind     = tempfile.LastIndexOf("\\");
            target   = tempfile.Substring(0, lind);

            traverse        = true;
            search          = true;
            addreadonlyinfo = false;

            depends = (object[])swApp.GetDocumentDependencies2(sourcefile, traverse, search, addreadonlyinfo);

            if ((depends == null))
            {
                return;
            }

            idx = 1;

            while (idx <= depends.GetUpperBound(0))
            {
                Array.Resize(ref sourcefiles, sourcecount + 1);
                Array.Resize(ref targetfiles, sourcecount + 1);

                sourcefiles[sourcecount] = (string)depends[idx];
                lind = sourcefiles[sourcecount].LastIndexOf("\\");
                targetfiles[sourcecount] = target + sourcefiles[sourcecount].Substring(lind, sourcefiles[sourcecount].Length - lind);

                sourcecount = sourcecount + 1;
                idx         = idx + 2;
            }

            swApp.CloseAllDocuments(true);

            copyopt = (int)swMoveCopyOptions_e.swMoveCopyOptionsOverwriteExistingDocs;

            errors = swApp.CopyDocument(sourcefile, target + @"\" + System.IO.Path.GetFileName(sourcefile), (sourcefiles), (targetfiles), (int)copyopt);
        }