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


        }


    }
}
相关推荐
XiaoZhenHua986 小时前
C#工业机器视觉Recipe配方系统设计:多型号、多相机、多工位参数如何统一管理
c#·软件架构·机器视觉·工业自动化·工业软件·recipe
fujisheng6618 小时前
FUI 导航实践:拆开 Layer、History、Coverage 与 Cache 的组合语义
c#·unity3d
淡海水9 小时前
10-05-高级-模式匹配-CSharp如何改变与数据结构的交互方式
数据结构·算法·c#·模式匹配
XiaoZhenHua9810 小时前
C# WinForms + 西门子S7 + SQLite + EPPlus生产数据采集系统架构设计
系统架构·sqlite·c#
Lost of 程序猿11 小时前
船岸数据同步链路实战:SendFlag、单调版本号与断网三天后的续传
后端·c#·asp.net
cjp5601 天前
012.UG二次开发,UG管道服务器与WPF管道通讯,传输JSON数据
c#
jiushidt1 天前
ArcGIS Pro Add‑in 打包流程详解
arcgis·c#·.net·arcgispro
geovindu2 天前
CSharp: Observer Pattern
开发语言·后端·观察者模式·设计模式·c#·.netcore·行为模式
软件黑马王子2 天前
20.Resources资源加载:基本实现
开发语言·前端框架·c#
张人玉2 天前
基于 C# / .NET 8 + Windows Forms + SQLite 的桌面银行业务演示系统——华夏示范银行管理系统
windows·sqlite·c#·.net