solidworks导出展开 c# ExportFlatPatternView方法

好像没有工程图的时候是没法用这个的

这个方法不需要doc.Visible也能展开

cs 复制代码
using System;
using System.IO;
using System.Runtime.InteropServices;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Text;
namespace tools
{
    public class Exportdxf_flatview
    {

        static public string run(ModelDoc2 swModel, string thickness)
        {
            try
            {
                Console.OutputEncoding = Encoding.UTF8;
                // 后续逻辑不变...
        

                if (swModel == null || swModel.GetType() != (int)swDocumentTypes_e.swDocPART)
                {
                    Console.WriteLine("错误:请打开一个 SolidWorks 零件文档 (.sldprt)。");
                    return "";
                }

                string fullPath = swModel.GetPathName();

                if (string.IsNullOrEmpty(fullPath))
                {
                    Console.WriteLine("错误:文档尚未保存,请先保存文件。");
                    return "";
                }
                string? directory = Path.GetDirectoryName(fullPath);
                if (string.IsNullOrEmpty(directory))
                {
                    Console.WriteLine("错误:无法获取文件所在目录。");
                    return "";
                }
                PartDoc swPart = (PartDoc)swModel;
                string outputfile = directory + "\\" + "下料" + "\\" + thickness;
                if (!Directory.Exists(outputfile))
                {
                    Directory.CreateDirectory(outputfile);
                }
                string dxfFileName = directory + "\\" + "下料" + "\\" + thickness + "\\" + Path.GetFileNameWithoutExtension(fullPath) + ".dwg";
  
               var result=swPart.ExportFlatPatternView(dxfFileName,0);



                Console.WriteLine($"{result}!生成文档保存在:{dxfFileName}");
                return dxfFileName;

            }
            catch (Exception ex)
            {
                Console.WriteLine($"发生错误: {ex.Message}");
                Console.WriteLine("提示:请确保 SolidWorks 正在运行。");

            }
            return "";


        }


    }
}
相关推荐
He BianGu7 小时前
【笔记】C# 中BindingFlags的详细作用
笔记·c#
?abc!7 小时前
(贪心)621. 任务调度器
java·前端·c#
开开心心就好10 小时前
电脑小说阅读器,支持朗读和自定义皮肤
服务器·开发语言·javascript·算法·pdf·c#·音视频
淡海水11 小时前
07-06-源码-.NET Core GC的极致优化技术
unity·架构·c#·.netcore·gc·1024程序员节
万化冥合12 小时前
怎么批量把 Word 转 PDF?
python·pdf·c#·word
淡海水1 天前
07-02-源码-.NET Core GC分配路径
算法·unity·c#·.netcore·gc·1024程序员节
吴可可1231 天前
C#调用摄像头拍照的三种API方案
c#
Msir_Modern1 天前
Noita 元胞沙盒笔记
算法·unity·c#·游戏引擎·元胞自动机
星之擎1 天前
Task 很优雅的取消方式是什么?C# 里面。
开发语言·c#
czhc11400756631 天前
一周概念复盘:预热、漂移与门禁
c#