static void ProcessSections(SolidEdgeDraft.Sections sections)
        {
            Console.WriteLine("--> {0}", System.Reflection.MethodBase.GetCurrentMethod().ToString());

            SolidEdgeDraft.Section section = null;

            for (int i = 1; i <= sections.Count; i++)
            {
                section = sections.Item(i);
                Console.WriteLine(String.Format("\tSection.Type: {0}", section.Type));

                ProcessSectionSheets(section.Sheets);
            }

            Console.WriteLine("<-- {0}", System.Reflection.MethodBase.GetCurrentMethod().ToString());
        }
        static void ProcessWorkingSectionDrawingViews(SolidEdgeDraft.Section section)
        {
            Console.WriteLine("--> {0}", System.Reflection.MethodBase.GetCurrentMethod().ToString());

            SolidEdgeDraft.SectionSheets sectionSheets = null;
            SolidEdgeDraft.Sheet         sheet         = null;
            SolidEdgeDraft.DrawingViews  drawingViews  = null;
            SolidEdgeDraft.DrawingView   drawingView   = null;

            if (section.Type == SolidEdgeDraft.SheetSectionTypeConstants.igWorkingSection)
            {
                sectionSheets = section.Sheets;

                for (int i = 1; i <= sectionSheets.Count; i++)
                {
                    sheet = sectionSheets.Item(i);
                    Console.WriteLine("\tSheet.Name: {0}", sheet.Name);

                    drawingViews = sheet.DrawingViews;
                    for (int j = 1; j <= sectionSheets.Count; j++)
                    {
                        drawingView = drawingViews.Item(j);
                        Console.WriteLine("\tDrawingView.Name: {0}", drawingView.Name);

                        ProcessDrawingViewModelLink(drawingView);
                        ProcessDrawingViewModelMembers(drawingView);
                    }
                }
            }
            else
            {
                Console.WriteLine("Section '{0}' is not an igWorkingSection.", section);
            }

            Console.WriteLine("<-- {0}", System.Reflection.MethodBase.GetCurrentMethod().ToString());
        }
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application   = null;
            SolidEdgeFramework.Documents   documents     = null;
            SolidEdgeDraft.DraftDocument   draftDocument = null;
            SolidEdgeDraft.Sheets          sheets        = null;
            SolidEdgeDraft.Sheet           sheet         = null;
            SolidEdgeDraft.Sections        sections      = null;
            SolidEdgeDraft.Section         section       = null;

            try
            {
                Console.WriteLine("Registering OleMessageFilter.");

                // Register with OLE to handle concurrency issues on the current thread.
                OleMessageFilter.Register();

                Console.WriteLine("Connecting to Solid Edge.");

                // Connect to or start Solid Edge.
                application = SolidEdgeUtils.Connect(true);

                // Make sure user can see the GUI.
                application.Visible = true;

                // Bring Solid Edge to the foreground.
                application.Activate();

                // Get a reference to the documents collection.
                documents = application.Documents;

                // Note: these two will throw exceptions if no document is open.
                //application.ActiveDocument
                //application.ActiveDocumentType;

                if ((documents.Count > 0) && (application.ActiveDocumentType == SolidEdgeFramework.DocumentTypeConstants.igDraftDocument))
                {
                    // Get a reference to the documents collection.
                    draftDocument = (SolidEdgeDraft.DraftDocument)application.ActiveDocument;

                    // Get a reference to the sheets collection.
                    sheets = draftDocument.Sheets;

                    // Get a reference to the active sheet.
                    sheet = draftDocument.ActiveSheet;
                    Console.WriteLine("DraftDocument.ActiveSheet: {0}", sheet.Name);

                    // Get a reference to all sections.
                    sections = draftDocument.Sections;

                    // Get a reference to the active section.
                    section = draftDocument.ActiveSection;
                    Console.WriteLine("DraftDocument.ActiveSection: {0}", section.Type);

                    Console.WriteLine();
                    ProcessSheets(draftDocument.Sheets);
                    Console.WriteLine();
                    ProcessSections(draftDocument.Sections);
                    Console.WriteLine();
                    ProcessWorkingSectionDrawingViews(sections.WorkingSection);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("Draft file not open.");
                }
            }
            catch (System.Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                Console.WriteLine(ex.Message);
            }
        }
예제 #4
0
        static void CreateDraft()
        {
            //draft = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument", Missing.Value);
            try
            {
                //add a draft document
                documents = application.Documents;
                draft = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument", Missing.Value);

                // Get a reference to the sheets collection
                sheets = draft.Sheets;

                // Add sheets to draft document
                // Loop thru list of wall - to do

                // Add a new sheet
                sheet = sheets.Item(1);
                sheet.Activate();
                sheet.Name = "MUR A";
                // Add wall drawings

                //Insert next wall
                sheet = sheets.AddSheet("MUR B", SheetSectionTypeConstants.igWorkingSection, Missing.Value, Missing.Value);
                sheet.Activate();
                // Add wall drawing

                //Insert next wall
                sheet = sheets.AddSheet("MUR C", SheetSectionTypeConstants.igWorkingSection, Missing.Value, Missing.Value);
                sheet.Activate();
                // Add wall drawings

                //Insert next wall
                sheet = sheets.AddSheet("MUR D", SheetSectionTypeConstants.igWorkingSection, Missing.Value, Missing.Value);
                sheet.Activate();
                // Add wall drawings

                //Insert next wall
                sheet = sheets.AddSheet("CHEVRONS", SheetSectionTypeConstants.igWorkingSection, Missing.Value, Missing.Value);
                sheet.Activate();
                // Add wall drawings

            }

            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (sheet != null)
                {
                    Marshal.ReleaseComObject(sheet);
                    sheet = null;
                }
                if (sheets != null)
                {
                    Marshal.ReleaseComObject(sheets);
                    sheets = null;
                }
                if (sectionSheets != null)
                {
                    Marshal.ReleaseComObject(sectionSheets);
                    sectionSheets = null;
                }
                if (section != null)
                {
                    Marshal.ReleaseComObject(section);
                    section = null;
                }
                if (draft != null)
                {
                    Marshal.ReleaseComObject(draft);
                    draft = null;
                }
                if (documents != null)
                {
                    Marshal.ReleaseComObject(documents);
                    documents = null;
                }
                if (application != null)
                {
                    Marshal.ReleaseComObject(application);
                    application = null;
                }

            }
        }