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 "";


        }


    }
}
相关推荐
界面开发小八哥1 天前
界面控件DevExpress XAF v26.1新版亮点——AI Agent Skills
ai·c#·跨平台·devexpress·ui开发·xaf
csdn_aspnet1 天前
C# 高效便利的处理数据
开发语言·windows·c#
淡海水1 天前
03-02-线性-List-T-动态数组布局-扩容与操作成本
数据结构·windows·c#·list·编译·clr·机器码
csdn_aspnet1 天前
C# 在逗号分割的字符串中判断是否包含指定字符
c#·正则·linq·string·regex·contains
宝桥南山1 天前
Blazor Web Assembly - 体验一下Authentication State从Server共享给Client
microsoft·微软·c#·asp.net·.net·.netcore
淡海水2 天前
02-06-历史-托管GC机制-垃圾回收如何影响数据结构选择
c#·编译·gc·机器码
longxiaozhang62 天前
C# static:静态成员,小白也能看懂
开发语言·c#
longxiaozhang62 天前
C#继承:让代码少写一点,偷懒的好方法
开发语言·c#
rockey6272 天前
C#脚本引擎之AScript与DynamicExpresso对比
c#·.net·script·动态脚本
Vae_Mars2 天前
C#中的delegate委托
开发语言·c#