Hello, there is a problem with the program I wrote for solid edge 2022

Hello, I created a program for solid edge 2022 that makes scans of sheet parts in the assembly, saves these scans in .psm format and .dxf format, in .psm format everything opens and the scan is shown, and in .dxf format it is just a black square without the geometry of the scan. If you manually scan and save manually in .dxf format, then everything is shown. Please tell me what the problem might be. I am attaching the program code.

using System;
using System.IO;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using SolidEdgeCommunity;
using SolidEdgeFramework;
using SolidEdgePart;
using SolidEdgeAssembly;
using SolidEdgeGeometry;

namespace DXFExporter
{
    public partial class MainForm : Form
    {
        private SolidEdgeFramework.Application _seApplication;
        private AssemblyDocument _seAssemblyDoc;
        private ListBox listBoxDetails;
        private TextBox txtSelectedAssembly;
        private TextBox txtExportFolder;
        private string exportFolderPath;
        private HashSet<string> processedSheetMetals;

        public MainForm()
        {
            InitializeComponent();
            InitializeCustomComponents();
            processedSheetMetals = new HashSet<string>();
            exportFolderPath = @"C:DXFExport";
            txtExportFolder.Text = exportFolderPath;
        }

        private void InitializeCustomComponents()
        {
            this.BackColor = Color.Honeydew;
            this.Text = "Сохранение развёртки листовых деталей сборки";
            this.ShowIcon = false;

            var lblSelectedAssembly = new Label
            {
                Text = "Выбранная сборка:",
                Location = new Point(20, 20),
                AutoSize = true,
                ForeColor = Color.DarkGreen
            };
            this.Controls.Add(lblSelectedAssembly);

            txtSelectedAssembly = new TextBox
            {
                Location = new Point(150, 20),
                Width = 400,
                ReadOnly = true,
                BackColor = Color.PaleGreen,
                ForeColor = Color.DarkGreen,
                BorderStyle = BorderStyle.None
            };
            this.Controls.Add(txtSelectedAssembly);

            var btnSelectAssembly = new Button
            {
                Text = "Выбрать сборку",
                Location = new Point(570, 15),
                Width = 150,
                BackColor = ColorTranslator.FromHtml("#0E5C42"),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat,
            };
            btnSelectAssembly.FlatAppearance.BorderSize = 0;
            btnSelectAssembly.Click += BtnSelectAssembly_Click;
            this.Controls.Add(btnSelectAssembly);

            var lblExportFolder = new Label
            {
                Text = "Папка для экспорта:",
                Location = new Point(20, 60),
                AutoSize = true,
                ForeColor = Color.DarkGreen
            };
            this.Controls.Add(lblExportFolder);

            txtExportFolder = new TextBox
            {
                Location = new Point(150, 60),
                Width = 400,
                ReadOnly = true,
                BackColor = Color.PaleGreen,
                ForeColor = Color.DarkGreen,
                BorderStyle = BorderStyle.None
            };
            this.Controls.Add(txtExportFolder);

            var btnSelectFolder = new Button
            {
                Text = "Выбрать папку",
                Location = new Point(570, 55),
                Width = 150,
                BackColor = ColorTranslator.FromHtml("#0E5C42"),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat
            };
            btnSelectFolder.FlatAppearance.BorderSize = 0;
            btnSelectFolder.Click += BtnSelectFolder_Click;
            this.Controls.Add(btnSelectFolder);

            listBoxDetails = new ListBox
            {
                Location = new Point(20, 100),
                Width = 700,
                Height = 200,
                BackColor = Color.MintCream,
                ForeColor = Color.DarkGreen,
            };
            this.Controls.Add(listBoxDetails);

            var btnProcess = new Button
            {
                Text = "Запустить",
                Location = new Point(20, 320),
                Width = 700,
                Height = 40,
                BackColor = ColorTranslator.FromHtml("#0E5C42"),
                ForeColor = Color.White,
                FlatStyle = FlatStyle.Flat
            };
            btnProcess.FlatAppearance.BorderSize = 0;
            btnProcess.Click += BtnProcess_Click;
            this.Controls.Add(btnProcess);
        }

        private void BtnSelectAssembly_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Filter = "Solid Edge Assembly (*.asm)|*.asm"
            };
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                txtSelectedAssembly.Text = openFileDialog.FileName;
                OpenAssembly(openFileDialog.FileName);
            }
        }

        private void BtnSelectFolder_Click(object sender, EventArgs e)
        {
            using (var folderDialog = new FolderBrowserDialog())
            {
                if (folderDialog.ShowDialog() == DialogResult.OK)
                {
                    exportFolderPath = folderDialog.SelectedPath;
                    txtExportFolder.Text = exportFolderPath;
                }
            }
        }

        private void OpenAssembly(string filePath)
        {
            try
            {
                OleMessageFilter.Register();
                _seApplication = SolidEdgeCommunity.SolidEdgeUtils.Connect(true);
                _seApplication.Documents.Open(filePath);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Ошибка при открытии сборки: {ex.Message}");
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }

        private void BtnProcess_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(exportFolderPath))
            {
                MessageBox.Show("Выберите папку для экспорта.");
                return;
            }

            try
            {
                OleMessageFilter.Register();
                if (_seApplication.ActiveDocumentType != SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument)
                {
                    MessageBox.Show("Активный документ не является сборкой.");
                    return;
                }

                _seAssemblyDoc = (AssemblyDocument)_seApplication.ActiveDocument;
                var occurrences = _seAssemblyDoc.Occurrences;

                // Создание папки с именем сборки
                string assemblyFolderName = System.IO.Path.GetFileNameWithoutExtension(_seAssemblyDoc.FullName);
                string assemblyExportPath = System.IO.Path.Combine(exportFolderPath, assemblyFolderName);
                if (!Directory.Exists(assemblyExportPath))
                {
                    Directory.CreateDirectory(assemblyExportPath);
                }

                foreach (Occurrence occurrence in occurrences.OfType<Occurrence>())
                {
                    ProcessOccurrence(occurrence, assemblyExportPath);
                }

                MessageBox.Show("Процесс завершён.");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Ошибка: {ex.Message}");
            }
            finally
            {
                OleMessageFilter.Unregister();
            }
        }


        private void ProcessOccurrence(Occurrence occurrence, string assemblyExportPath)
        {
            if (occurrence.OccurrenceDocument is SheetMetalDocument sheetMetalDoc)
            {
                string fullname = sheetMetalDoc.FullName;

                if (!processedSheetMetals.Contains(sheetMetalDoc.FullName))
                {
                    OpenAndProcessSheetMetal(occurrence.OccurrenceFileName, assemblyExportPath);
                    processedSheetMetals.Add(fullname);
                }
            }
            else if (occurrence.OccurrenceDocument is AssemblyDocument subAssemblyDoc)
            {
                foreach (Occurrence subOccurrence in subAssemblyDoc.Occurrences.OfType<Occurrence>())
                {
                    ProcessOccurrence(subOccurrence, assemblyExportPath);
                }
            }
        }


        private void OpenAndProcessSheetMetal(string filePath, string assemblyExportPath)
        {
            try
            {
                _seApplication.Documents.Open(filePath, DocRelationAutoServer: 8);
                var sheetMetalDoc = (SheetMetalDocument)_seApplication.ActiveDocument;
                SaveSheetMetalAsDXF(sheetMetalDoc, assemblyExportPath);
                sheetMetalDoc.Close(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Ошибка при обработке листовой детали: {ex.Message}");
            }
        }


        private void SaveSheetMetalAsDXF(SheetMetalDocument sheetMetalDoc, string assemblyExportPath)
        {
            try
            {
                // Check if a flat pattern model exists
                FlatPatternModel flatPatternModel;
                if (sheetMetalDoc.FlatPatternModels.Count == 0)
                {
                    flatPatternModel = sheetMetalDoc.FlatPatternModels.Add(sheetMetalDoc.Models.Item(1));
                }
                else
                {
                    flatPatternModel = (FlatPatternModel)sheetMetalDoc.FlatPatternModels.Item(1);
                }

                SolidEdgeGeometry.Body body = (SolidEdgeGeometry.Body)flatPatternModel.Body;
                SolidEdgeGeometry.Face face = null;
                SolidEdgeGeometry.Edge edge = null;
                SolidEdgeGeometry.Vertex vertex = null;

                var queryTypes = new FeatureTopologyQueryTypeConstants[]
                {
                    FeatureTopologyQueryTypeConstants.igQueryPlane,
                    FeatureTopologyQueryTypeConstants.igQueryCylinder,
                    FeatureTopologyQueryTypeConstants.igQueryCone,
                    FeatureTopologyQueryTypeConstants.igQueryAll
                };

                foreach (var queryType in queryTypes)
                {
                    var faces = (SolidEdgeGeometry.Faces)body.Faces[queryType];
                    if (faces.Count > 0)
                    {
                        face = (SolidEdgeGeometry.Face)faces.Item(1);
                        var edges = (SolidEdgeGeometry.Edges)face.Edges;
                        if (edges.Count > 0)
                        {
                            edge = (SolidEdgeGeometry.Edge)edges.Item(1);
                            vertex = (SolidEdgeGeometry.Vertex)edge.StartVertex;
                            break;
                        }
                    }
                }

                if (face == null || edge == null || vertex == null)
                {
                    listBoxDetails.Items.Add($"{sheetMetalDoc.Name}: Не удалось найти подходящие грани, ребра или вершины для создания развёртки.");
                    return;
                }

                SolidEdgePart.FlatPatterns flatPatterns = flatPatternModel.FlatPatterns;
                flatPatterns.Add(
                    ReferenceEdge: edge,
                    ReferenceFace: face,
                    ReferenceVertex: vertex,
                    ModelType: SolidEdgePart.FlattenPatternModelTypeConstants.igFlattenPatternModelTypeFlattenAnything
                );

                string file_name_without_ext = System.IO.Path.GetFileNameWithoutExtension(sheetMetalDoc.Name);
                string FileNameDXF = System.IO.Path.ChangeExtension(file_name_without_ext, ".dxf");
                string dxfPath = System.IO.Path.Combine(assemblyExportPath, $"{file_name_without_ext}.psm");
                sheetMetalDoc.Models.SaveAsFlatDXF(dxfPath, face, edge, vertex);

                dxfPath = System.IO.Path.Combine(assemblyExportPath, $"{FileNameDXF}");
                sheetMetalDoc.Models.SaveAsFlatDXFEx(dxfPath, face, edge, vertex, true);

                listBoxDetails.Items.Add($"{sheetMetalDoc.Name} сохранён как {dxfPath} Успешно");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Ошибка при сохранении DXF: {ex.Message}");
            }
        }

    }
}






I don’t understand where there might be a mistake

New contributor

darety is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật