C# Solidworks二次开发:Pack and Go打包时需要注意的地方,纯干货(可以节省大量查找资料时间)

大家都知道在Solidworks中使用Pack and Go打包时有三种打包类型可以选择,分别是“平展到单一文件夹”、“平展到最少文件夹”、以及“保留完整的文件夹结构”三种类型,如下图所示:

 在使用Pack and Go打包时的代码如下:

 public static void SavePackAndGo(SldWorks swApp, string Path, string Path1)
        {

            ModelDoc2 swModelDoc = default(ModelDoc2);
            ModelDocExtension swModelDocExt = default(ModelDocExtension);
            PackAndGo swPackAndGo = default(PackAndGo);
            string openFile = null;
            bool status = false;
            int warnings = 0;
            int errors = 0;
            int i = 0;
            int namesCount = 0;
            string myPath = null;
            int[] statuses = null;

            // Open assembly
            openFile = Path;
            swModelDoc = (ModelDoc2)swApp.OpenDoc6(openFile, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swModelDocExt = (ModelDocExtension)swModelDoc.Extension;

            // Get Pack and Go object
            Debug.Print("Pack and Go");
            swPackAndGo = (PackAndGo)swModelDocExt.GetPackAndGo();

            // Get number of documents in assembly
            namesCount = swPackAndGo.GetDocumentNamesCount();
            Debug.Print("  Number of model documents: " + namesCount);

            // Include any drawings, SOLIDWORKS Simulation results, and SOLIDWORKS Toolbox components
            swPackAndGo.IncludeDrawings = true;
            Debug.Print(" Include drawings: " + swPackAndGo.IncludeDrawings);
            swPackAndGo.IncludeSimulationResults = true;
            Debug.Print(" Include SOLIDWORKS Simulation results: " + swPackAndGo.IncludeSimulationResults);
            swPackAndGo.IncludeToolboxComponents = true;
            Debug.Print(" Include SOLIDWORKS Toolbox components: " + swPackAndGo.IncludeToolboxComponents);

            // Get current paths and filenames of the assembly's documents
            object fileNames;
            object[] pgFileNames = new object[namesCount - 1];
            status = swPackAndGo.GetDocumentNames(out fileNames);
            pgFileNames = (object[])fileNames;

            Debug.Print("");
            Debug.Print("  Current path and filenames: ");
            if ((pgFileNames != null))
            {
                for (i = 0; i <= pgFileNames.GetUpperBound(0); i++)
                {
                    Debug.Print("    The path and filename is: " + pgFileNames[i]);
                }
            }

            // Get current save-to paths and filenames of the assembly's documents
            object pgFileStatus;
            status = swPackAndGo.GetDocumentSaveToNames(out fileNames, out pgFileStatus);
            pgFileNames = (object[])fileNames;
            Debug.Print("");
            Debug.Print("  Current default save-to filenames: ");
            if ((pgFileNames != null))
            {
                for (i = 0; i <= pgFileNames.GetUpperBound(0); i++)
                {
                    Debug.Print("   The path and filename is: " + pgFileNames[i]);
                }
            }

            swPackAndGo.FlattenToSingleFolder = false;
            // Set folder where to save the files
            myPath = Path1 + "\\";
            status = swPackAndGo.SetSaveToName(true, myPath);

            // Flatten the Pack and Go folder structure; save all files to the root directory
            //swPackAndGo.FlattenToSingleFolder = true;
            //swPackAndGo.
            // Add a prefix and suffix to the filenames
            //swPackAndGo.AddPrefix = "SW_";
            //swPackAndGo.AddSuffix = "_PackAndGo";

            // Verify document paths and filenames after adding prefix and suffix
            object getFileNames;
            object getDocumentStatus;
            string[] pgGetFileNames = new string[namesCount - 1];

            status = swPackAndGo.GetDocumentSaveToNames(out getFileNames, out getDocumentStatus);
            pgGetFileNames = (string[])getFileNames;
            Debug.Print("");
            Debug.Print("  My Pack and Go path and filenames after adding prefix and suffix: ");
            for (i = 0; i <= namesCount - 1; i++)
            {
                Debug.Print("    My path and filename is: " + pgGetFileNames[i]);
            }

            // Pack and Go
            statuses = (int[])swModelDocExt.SavePackAndGo(swPackAndGo);


        }

在上述代码中有如下图所示的一行代码是控制打包类型的:

 当你赋予bool值为false时,打包类型为第三种“保留完整的文件夹结构”,当你赋予bool值为true时,打包类型为第一种“平展到单一文件夹”。

这时细心的大家就会发现为啥没有第二种呢,这就是我今天和大家分享的。我现在也没有发现在使用Pack and Go打包时如何才能选择第二种类型“平展到最少文件夹”进行打包,如果有大神知道,可以私聊我。大家共同进步。

  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喵桑さん

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值