Exemplo n.º 1
0
 static void CreateDoc()
 {
     Console.WriteLine("Creation de document test");
     documents = application.Documents;
     assembly = (SolidEdgeAssembly.AssemblyDocument)documents.Add("SolidEdge.AssemblyDocument", Missing.Value);
     draft = (SolidEdgeDraft.DraftDocument)documents.Add("SolidEdge.DraftDocument", Missing.Value);
     part = (SolidEdgePart.PartDocument)documents.Add("SolidEdge.PartDocument", Missing.Value);
     CleanSE();
 }
Exemplo n.º 2
0
        public static void Draw(SolidEdgeFramework.Application application)
        {
            SolidEdgePart.PartDocument   partDocument        = null;
            SolidEdgeDraft.DraftDocument seDraftDocument     = null;
            SolidEdgeDraft.Sheets        sheets              = null;
            SolidEdgeDraft.Sheet         activeSheet         = null;
            SolidEdgeDraft.Sheet         sheetWithBackground = null;
            SolidEdgeDraft.ModelLinks    modelLinks          = null;
            SolidEdgeDraft.ModelLink     modelLink           = null;
            SolidEdgeDraft.DrawingViews  drawingViews        = null;
            SolidEdgeDraft.DrawingView   principalView       = null;
            string fullName = null;

            partDocument = (SolidEdgePart.PartDocument)application.ActiveDocument;

            fullName = partDocument.FullName;

            // Open draft document.(make a function of it)
            seDraftDocument = (DraftDocument)application.Documents.Add("SolidEdge.DraftDocument");
            Console.WriteLine("[+] Draft created");

            // little pause for solid edge.
            application.DoIdle();

            // Add the view of the active part.
            modelLinks = seDraftDocument.ModelLinks;
            modelLink  = modelLinks.Add(fullName);
            sheets     = seDraftDocument.Sheets;

            // Change the background to part.
            sheetWithBackground = sheets.Item(2);
            sheetWithBackground.ReplaceBackground(
                "J:\\PTCR\\_Solidedge\\Template\\Draft (part) TC.dft",
                "Background FORMAT B"
                );
            Console.WriteLine("[+] Background replaced.");

            // Add the views in the drawing.
            activeSheet  = seDraftDocument.ActiveSheet;
            drawingViews = activeSheet.DrawingViews;

            principalView = drawingViews.AddPartView(
                From: modelLink,
                Orientation: SolidEdgeDraft.ViewOrientationConstants.igTopView,
                Scale: 0.5,
                x: 0.150,
                y: 0.125,
                ViewType: SolidEdgeDraft.PartDrawingViewTypeConstants.sePartDesignedView
                );
            Console.WriteLine("\t+ TopView");

            var frontView = drawingViews.AddByFold(From: principalView, foldDir: SolidEdgeDraft.FoldTypeConstants.igFoldUp, x: 0.150, y: 0.200);

            Console.WriteLine("\t+ FoldUp");

            var rightView = drawingViews.AddByFold(From: principalView, foldDir: SolidEdgeDraft.FoldTypeConstants.igFoldRight, x: 0.260, y: 0.125);

            Console.WriteLine("\t+ FoldRight");

            var isoView = drawingViews.AddPartView(From: modelLink, Orientation: SolidEdgeDraft.ViewOrientationConstants.igTopFrontRightView, Scale: 0.5, x: 0.300, y: 0.200, ViewType: SolidEdgeDraft.PartDrawingViewTypeConstants.sePartDesignedView);

            Console.WriteLine("\t+ TopFrontRight");
        }
        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);
            }
        }
Exemplo n.º 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;
                }

            }
        }