Example #1
0
        static void ConvertAllDrawingViewsTo2D(SolidEdgeDraft.Section section)
        {
            SolidEdgeDraft.SectionSheets sectionSheets = null;
            SolidEdgeDraft.Sheet         sheet         = null;
            SolidEdgeDraft.DrawingViews  drawingViews  = null;
            SolidEdgeDraft.DrawingView   drawingView   = null;

            sectionSheets = section.Sheets;

            for (int i = 1; i <= sectionSheets.Count; i++)
            {
                // Get a reference to the sheet.
                sheet = sectionSheets.Item(i);

                // Get a reference to the DrawingViews collection.
                drawingViews = sheet.DrawingViews;

                for (int j = 1; j < drawingViews.Count; j++)
                {
                    drawingView = drawingViews.Item(j);

                    Console.WriteLine("Dropping (convert to 2D) DrawingView '{0} - {1}'.  ", drawingView.Name, drawingView.Caption);

                    // DrawingView's of type igUserView cannot be converted.
                    if (drawingView.DrawingViewType != SolidEdgeDraft.DrawingViewTypeConstants.igUserView)
                    {
                        // Converts the current DrawingView to an igUserView type containing simple geometry
                        // and disassociates the drawing view from the source 3d Model.
                        drawingView.Drop();
                    }
                }
            }
        }
        void DoOpenSave(SolidEdgeDraft.DraftDocument draftDocument, DraftSettings draftSettings)
        {
            SolidEdgeDraft.Sections      sections      = null;
            SolidEdgeDraft.Section       section       = null;
            SolidEdgeDraft.SectionSheets sectionSheets = null;
            SolidEdgeDraft.Sheet         sheet         = null;
            SolidEdgeDraft.DrawingViews  drawingViews  = null;
            SolidEdgeDraft.DrawingView   drawingView   = null;

            if (draftSettings.UpdateDrawingViews)
            {
                sections = draftDocument.Sections;
                section  = sections.WorkingSection;

                sectionSheets = section.Sheets;

                for (int i = 1; i <= sectionSheets.Count; i++)
                {
                    sheet        = sectionSheets.Item(i);
                    drawingViews = sheet.DrawingViews;

                    for (int j = 1; j <= drawingViews.Count; j++)
                    {
                        drawingView = drawingViews.Item(j);
                        drawingView.Update();
                    }
                }
            }
        }
Example #3
0
        static void AddAssemblyView(SolidEdgeDraft.DraftDocument draftDocument)
        {
            SolidEdgeDraft.Sheet        sheet        = null;
            SolidEdgeDraft.ModelLinks   modelLinks   = null;
            SolidEdgeDraft.ModelLink    modelLink    = null;
            SolidEdgeDraft.DrawingViews drawingViews = null;
            SolidEdgeDraft.DrawingView  drawingView  = null;
            DirectoryInfo trainingDirectory          = GetTrainingDirectory();
            string        fileName = Path.Combine(trainingDirectory.FullName, "Coffee Pot.asm");

            // Get a reference to the active sheet.
            sheet = draftDocument.ActiveSheet;

            // Get a reference to the ModelLinks collection.
            modelLinks = draftDocument.ModelLinks;
            //2holebar.par
            modelLink = modelLinks.Add(fileName);

            drawingViews = sheet.DrawingViews;

            drawingView = drawingViews.AddAssemblyView(
                From: modelLink,
                Orientation: SolidEdgeDraft.ViewOrientationConstants.igDimetricTopBackLeftView,
                Scale: 1.0,
                x: 0.4,
                y: 0.2,
                ViewType: SolidEdgeDraft.AssemblyDrawingViewTypeConstants.seAssemblyDesignedView);
        }
Example #4
0
        static void UpdateAllViewsInWorkingSection(SolidEdgeDraft.Section section)
        {
            SolidEdgeDraft.SectionSheets sectionSheets = null;
            SolidEdgeDraft.Sheet         sheet         = null;
            SolidEdgeDraft.DrawingViews  drawingViews  = null;
            SolidEdgeDraft.DrawingView   drawingView   = null;

            sectionSheets = section.Sheets;

            for (int i = 1; i <= sectionSheets.Count; i++)
            {
                sheet = sectionSheets.Item(i);

                drawingViews = sheet.DrawingViews;

                for (int j = 1; j < drawingViews.Count; j++)
                {
                    drawingView = drawingViews.Item(j);

                    Console.WriteLine("Updating DrawingView '{0} - {1}'.", drawingView.Name, drawingView.Caption);

                    // Updates an out-of-date drawing view.
                    drawingView.Update();

                    // Updates the drawing view even if it is not out-of-date.
                    //drawingView.ForceUpdate();
                }
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application   = null;
            SolidEdgeFramework.Documents   documents     = null;
            SolidEdgeDraft.DraftDocument   draftDocument = null;
            SolidEdgeDraft.ModelLinks      modelLinks    = null;
            SolidEdgeDraft.ModelLink       modelLink     = null;
            SolidEdgeDraft.Sheet           sheet         = null;
            SolidEdgeDraft.DrawingViews    drawingViews  = null;
            SolidEdgeDraft.DrawingView     drawingView   = null;
            string filename = null;

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

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

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

                // Create a new draft document.
                draftDocument = documents.AddDraftDocument();

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Build path to part file.
                filename = System.IO.Path.Combine(SolidEdgeCommunity.SolidEdgeUtils.GetTrainingFolderPath(), "Coffee Pot.asm");

                // Get a reference to the ModelLinks collection.
                modelLinks = draftDocument.ModelLinks;

                // Add a new model link.
                modelLink = modelLinks.Add(filename);

                // Get a reference to the DrawingViews collection.
                drawingViews = sheet.DrawingViews;

                // Add a new part drawing view.
                drawingView = drawingViews.AddAssemblyView(
                    From: modelLink,
                    Orientation: SolidEdgeDraft.ViewOrientationConstants.igDimetricTopBackLeftView,
                    Scale: 1.0,
                    x: 0.4,
                    y: 0.4,
                    ViewType: SolidEdgeDraft.AssemblyDrawingViewTypeConstants.seAssemblyDesignedView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Example #6
0
        static void AddPartViewAndDimension(SolidEdgeDraft.DraftDocument draftDocument)
        {
            SolidEdgeDraft.Sheet        sheet        = null;
            SolidEdgeDraft.ModelLinks   modelLinks   = null;
            SolidEdgeDraft.ModelLink    modelLink    = null;
            SolidEdgeDraft.DrawingViews drawingViews = null;
            SolidEdgeDraft.DrawingView  drawingView  = null;
            DirectoryInfo trainingDirectory          = GetTrainingDirectory();
            string        fileName = Path.Combine(trainingDirectory.FullName, "2holebar.par");

            SolidEdgeDraft.DVLines2d             dvLines2d  = null;
            SolidEdgeDraft.DVLine2d              dvLine2d   = null;
            SolidEdgeFrameworkSupport.Dimensions dimensions = null;
            SolidEdgeFrameworkSupport.Dimension  dimension  = null;
            SolidEdgeFrameworkSupport.DimStyle   dimStyle   = null;

            // Get a reference to the active sheet.
            sheet = draftDocument.ActiveSheet;

            // Get a reference to the ModelLinks collection.
            modelLinks = draftDocument.ModelLinks;

            // Add a new model link.
            modelLink = modelLinks.Add(fileName);

            // Get a reference to the DrawingViews collection.
            drawingViews = sheet.DrawingViews;

            // Add a new part drawing view.
            drawingView = drawingViews.AddPartView(
                From: modelLink,
                Orientation: SolidEdgeDraft.ViewOrientationConstants.igDimetricTopBackLeftView,
                Scale: 5.0,
                x: 0.4,
                y: 0.4,
                ViewType: SolidEdgeDraft.PartDrawingViewTypeConstants.sePartDesignedView);

            // Get a reference to the DVLines2d collection.
            dvLines2d = drawingView.DVLines2d;

            // Get the 1st drawing view 2D line.
            dvLine2d = dvLines2d.Item(1);

            // Get a reference to the Dimensions collection.
            dimensions = (SolidEdgeFrameworkSupport.Dimensions)sheet.Dimensions;

            // Add a dimension to the line.
            dimension = dimensions.AddLength(dvLine2d.Reference);

            // Few changes to make the dimensions look right.
            dimension.ProjectionLineDirection = true;
            dimension.TrackDistance           = 0.02;

            // Get a reference to the dimension style.
            // DimStyle has a ton of options...
            dimStyle = dimension.Style;
        }
Example #7
0
        static void AddItemsToSelectSet(SolidEdgeFramework.SolidEdgeDocument document)
        {
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;
            SolidEdgeAssembly.AsmRefPlanes     asmRefPlanes     = null;
            SolidEdgeDraft.DraftDocument       draftDocument    = null;
            SolidEdgeDraft.Sheet             sheet              = null;
            SolidEdgeDraft.DrawingViews      drawingViews       = null;
            SolidEdgePart.PartDocument       partDocument       = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = null;
            SolidEdgePart.EdgebarFeatures    edgeBarFeatures    = null;

            switch (document.Type)
            {
            case SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument:
                assemblyDocument = (SolidEdgeAssembly.AssemblyDocument)document;
                asmRefPlanes     = assemblyDocument.AsmRefPlanes;

                for (int i = 1; i <= asmRefPlanes.Count; i++)
                {
                    assemblyDocument.SelectSet.Add(asmRefPlanes.Item(i));
                }
                break;

            case SolidEdgeFramework.DocumentTypeConstants.igDraftDocument:
                draftDocument = (SolidEdgeDraft.DraftDocument)document;
                sheet         = draftDocument.ActiveSheet;
                drawingViews  = sheet.DrawingViews;

                for (int i = 1; i <= drawingViews.Count; i++)
                {
                    draftDocument.SelectSet.Add(drawingViews.Item(i));
                }

                break;

            case SolidEdgeFramework.DocumentTypeConstants.igPartDocument:
                partDocument    = (SolidEdgePart.PartDocument)document;
                edgeBarFeatures = partDocument.DesignEdgebarFeatures;

                for (int i = 1; i <= edgeBarFeatures.Count; i++)
                {
                    partDocument.SelectSet.Add(edgeBarFeatures.Item(i));
                }

                break;

            case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument:
                sheetMetalDocument = (SolidEdgePart.SheetMetalDocument)document;
                edgeBarFeatures    = sheetMetalDocument.DesignEdgebarFeatures;

                for (int i = 1; i <= edgeBarFeatures.Count; i++)
                {
                    partDocument.SelectSet.Add(edgeBarFeatures.Item(i));
                }
                break;
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application   = null;
            SolidEdgeDraft.DraftDocument   draftDocument = null;
            SolidEdgeDraft.Sections        sections      = null;
            SolidEdgeDraft.Section         section       = null;
            SolidEdgeDraft.SectionSheets   sectionSheets = null;
            SolidEdgeDraft.DrawingViews    drawingViews  = null;

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

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

                draftDocument = application.GetActiveDocument <SolidEdgeDraft.DraftDocument>(false);

                if (draftDocument != null)
                {
                    // Get a reference to the Sections collection.
                    sections = draftDocument.Sections;

                    // Get a reference to the WorkingSection.
                    section = sections.WorkingSection;

                    // Get a reference to the Sheets collection.
                    sectionSheets = section.Sheets;

                    foreach (var sheet in sectionSheets.OfType <SolidEdgeDraft.Sheet>())
                    {
                        Console.WriteLine("Processing sheet '{0}'.", sheet.Name);

                        // Get a reference to the DrawingViews collection.
                        drawingViews = sheet.DrawingViews;

                        foreach (var drawingView in drawingViews.OfType <SolidEdgeDraft.DrawingView>())
                        {
                            // Updates an out-of-date drawing view.
                            drawingView.Update();

                            // Note: You can use ForceUpdate() even if it is not out-of-date.

                            Console.WriteLine("Updated drawing view '{0}'.", drawingView.Name);
                        }
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Example #9
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application       application   = null;
            SolidEdgeFramework.Documents         documents     = null;
            SolidEdgeDraft.DraftDocument         draftDocument = null;
            SolidEdgeDraft.ModelLinks            modelLinks    = null;
            SolidEdgeDraft.ModelLink             modelLink     = null;
            SolidEdgeDraft.Sheet                 sheet         = null;
            SolidEdgeDraft.DrawingViews          drawingViews  = null;
            SolidEdgeDraft.DrawingView           drawingView   = null;
            SolidEdgeDraft.DVLines2d             dvLines2d     = null;
            SolidEdgeDraft.DVLine2d              dvLine2d      = null;
            SolidEdgeFrameworkSupport.Dimensions dimensions    = null;
            SolidEdgeFrameworkSupport.Dimension  dimension     = null;
            SolidEdgeFrameworkSupport.DimStyle   dimStyle      = null;
            string filename = null;

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

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

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

                // Create a new draft document.
                draftDocument = documents.AddDraftDocument();

                // Get a reference to the ModelLinks collection.
                modelLinks = draftDocument.ModelLinks;

                // Build path to part file.
                filename = System.IO.Path.Combine(SolidEdgeCommunity.SolidEdgeUtils.GetTrainingFolderPath(), "2holebar.par");

                // Add a new model link.
                modelLink = modelLinks.Add(filename);

                // Get a reference to the active sheet.
                sheet = draftDocument.ActiveSheet;

                // Get a reference to the DrawingViews collection.
                drawingViews = sheet.DrawingViews;

                // Add a new part drawing view.
                drawingView = drawingViews.AddPartView(
                    From: modelLink,
                    Orientation: SolidEdgeDraft.ViewOrientationConstants.igDimetricTopBackLeftView,
                    Scale: 5.0,
                    x: 0.4,
                    y: 0.4,
                    ViewType: SolidEdgeDraft.PartDrawingViewTypeConstants.sePartDesignedView);

                // Get a reference to the DVLines2d collection.
                dvLines2d = drawingView.DVLines2d;

                // Get the 1st drawing view 2D line.
                dvLine2d = dvLines2d.Item(1);

                // Get a reference to the Dimensions collection.
                dimensions = (SolidEdgeFrameworkSupport.Dimensions)sheet.Dimensions;

                // Add a dimension to the line.
                dimension = dimensions.AddLength(dvLine2d.Reference);

                // Few changes to make the dimensions look right.
                dimension.ProjectionLineDirection = true;
                dimension.TrackDistance           = 0.02;

                // Get a reference to the dimension style.
                // DimStyle has a ton of options...
                dimStyle = dimension.Style;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Example #10
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application       application      = null;
            SolidEdgeFramework.SolidEdgeDocument document         = null;
            SolidEdgeFramework.SelectSet         selectSet        = null;
            SolidEdgeAssembly.AssemblyDocument   assemblyDocument = null;
            SolidEdgeAssembly.AsmRefPlanes       asmRefPlanes     = null;
            SolidEdgeDraft.DraftDocument         draftDocument    = null;
            SolidEdgeDraft.Sheet             sheet              = null;
            SolidEdgeDraft.DrawingViews      drawingViews       = null;
            SolidEdgePart.PartDocument       partDocument       = null;
            SolidEdgePart.SheetMetalDocument sheetMetalDocument = null;
            SolidEdgePart.EdgebarFeatures    edgeBarFeatures    = null;

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

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

                // Get a reference to the active selectset.
                selectSet = application.ActiveSelectSet;

                // Temporarily suspend selectset UI updates.
                selectSet.SuspendDisplay();

                // Clear the selectset.
                selectSet.RemoveAll();

                // Get a reference to the active document.
                document = application.GetActiveDocument <SolidEdgeFramework.SolidEdgeDocument>(false);

                if (document != null)
                {
                    // Determine document type.
                    switch (document.Type)
                    {
                    case SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument:
                        assemblyDocument = (SolidEdgeAssembly.AssemblyDocument)document;
                        asmRefPlanes     = assemblyDocument.AsmRefPlanes;

                        for (int i = 1; i <= asmRefPlanes.Count; i++)
                        {
                            selectSet.Add(asmRefPlanes.Item(i));
                        }

                        break;

                    case SolidEdgeFramework.DocumentTypeConstants.igDraftDocument:
                        draftDocument = (SolidEdgeDraft.DraftDocument)document;
                        sheet         = draftDocument.ActiveSheet;
                        drawingViews  = sheet.DrawingViews;

                        for (int i = 1; i <= drawingViews.Count; i++)
                        {
                            draftDocument.SelectSet.Add(drawingViews.Item(i));
                        }

                        break;

                    case SolidEdgeFramework.DocumentTypeConstants.igPartDocument:
                        partDocument    = (SolidEdgePart.PartDocument)document;
                        edgeBarFeatures = partDocument.DesignEdgebarFeatures;

                        for (int i = 1; i <= edgeBarFeatures.Count; i++)
                        {
                            partDocument.SelectSet.Add(edgeBarFeatures.Item(i));
                        }

                        break;

                    case SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument:
                        sheetMetalDocument = (SolidEdgePart.SheetMetalDocument)document;
                        edgeBarFeatures    = sheetMetalDocument.DesignEdgebarFeatures;

                        for (int i = 1; i <= edgeBarFeatures.Count; i++)
                        {
                            partDocument.SelectSet.Add(edgeBarFeatures.Item(i));
                        }
                        break;
                    }
                }
                else
                {
                    throw new System.Exception("No active document");
                }

                // Re-enable selectset UI display.
                selectSet.ResumeDisplay();

                // Manually refresh the selectset UI display.
                selectSet.RefreshDisplay();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Example #11
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application   = null;
            SolidEdgeDraft.DraftDocument   draftDocument = null;
            SolidEdgeDraft.Sections        sections      = null;
            SolidEdgeDraft.Section         section       = null;
            SolidEdgeDraft.SectionSheets   sectionSheets = null;
            SolidEdgeDraft.DrawingViews    drawingViews  = null;

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

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

                // Get a reference to the active draft document.
                draftDocument = application.GetActiveDocument <SolidEdgeDraft.DraftDocument>(false);

                if (draftDocument != null)
                {
                    // Get a reference to the Sections collection.
                    sections = draftDocument.Sections;

                    // Get a reference to the working section.
                    section = sections.WorkingSection;

                    // Get a reference to the working section sheets.
                    sectionSheets = section.Sheets;

                    foreach (var sheet in sectionSheets.OfType <SolidEdgeDraft.Sheet>())
                    {
                        // Get a reference to the DrawingViews collection.
                        drawingViews = sheet.DrawingViews;

                        foreach (var drawingView in drawingViews.OfType <SolidEdgeDraft.DrawingView>())
                        {
                            // DrawingView's of type igUserView cannot be converted.
                            if (drawingView.DrawingViewType != SolidEdgeDraft.DrawingViewTypeConstants.igUserView)
                            {
                                // Converts the current DrawingView to an igUserView type containing simple geometry
                                // and disassociates the drawing view from the source 3d Model.
                                drawingView.Drop();
                            }
                        }
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Example #12
0
        // Restituisce il nome del foglio di background attivo
        public string NomeFoglioBackgroundAttivo()
        {
            string messaggio = "";									// Cancella i dati preesistenti
            try {
                application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application");
                } catch {
                messaggio = "Nessuna istanza attiva";
                application = null;
                }
            try {
                document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument;
                if (document.Type == DocumentTypeConstants.igDraftDocument)					// Se e` un draft...
                    {
                    messaggio = ((SolidEdgeDraft.DraftDocument)document).ActiveSheet.Background.Name;
                    }
                else {
                    messaggio = "Non e` un draft";
                    }
                } catch (System.Exception ex)							// Messaggio se eccezione
                {
                messaggio = "Eccezione: " + ex.Message + " + Nessun documento attivo";
                }
            finally {
                if (drawingViews != null) {
                    foreach (SolidEdgeDraft.DrawingView drawingView in drawingViews) {
                        Marshal.ReleaseComObject(drawingView);
                        }
                    }
                if (drawingViews != null) {
                    Marshal.ReleaseComObject(drawingViews);
                    drawingViews = null;
                    }

                if (document != null) {
                    Marshal.ReleaseComObject(document);
                    document = null;
                    }
                if (application != null) {
                    Marshal.ReleaseComObject(application);
                    application = null;
                    }
                }
            return messaggio;
        }
Example #13
0
        // Riempie una lista con le scale delle viste del draft
        public string CreaListaScale()
        {
            string messaggio = "";									// Cancella i dati preesistenti
            listaScale.Clear();
            try {
                application = (SolidEdgeFramework.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application");
                } catch {
                messaggio = "Nessuna istanza attiva";
                application = null;
                }
            try {
                document = (SolidEdgeFramework.SolidEdgeDocument)application.ActiveDocument;
                if (document.Type == DocumentTypeConstants.igDraftDocument)					// Se e` un draft...
                    {
                    int count, i;															// ... estrae le viste del foglio attivo
                    double scala;
                    string tScala;
                    drawingViews = ((SolidEdgeDraft.DraftDocument)document).ActiveSheet.DrawingViews;
                    count = drawingViews.Count;
                    for (i = 0; i < count; i++)												// Percorre le viste
                        {
                        drawingView = drawingViews.Item(i+1);
                        scala = drawingView.ScaleFactor;
                        if(scala >= 1.0)
                            tScala = scala.ToString()+":1";
                        else
                            tScala = "1:"+(1.0/scala).ToString();
                        listaScale.Add(tScala);
                        }
                    }
                else {
                    messaggio = "Non e` un draft";
                    }
                } catch (System.Exception ex)							// Messaggio se eccezione
                {
                messaggio = "Eccezione: " + ex.Message + " + Nessun documento attivo";
                }
            finally {
                if (drawingViews != null) {
                    foreach (SolidEdgeDraft.DrawingView drawingView in drawingViews) {
                        Marshal.ReleaseComObject(drawingView);
                        }
                    }
                if (drawingViews != null) {
                    Marshal.ReleaseComObject(drawingViews);
                    drawingViews = null;
                    }

                if (document != null) {
                    Marshal.ReleaseComObject(document);
                    document = null;
                    }
                if (application != null) {
                    Marshal.ReleaseComObject(application);
                    application = null;
                    }
                }
            return messaggio;
        }
Example #14
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application    = null;
            SolidEdgeDraft.DraftDocument   draftDocument  = null;
            SolidEdgeDraft.Sections        sections       = null;
            SolidEdgeDraft.Section         section        = null;
            SolidEdgeDraft.SectionSheets   sectionSheets  = null;
            SolidEdgeDraft.DrawingViews    drawingViews   = null;
            SolidEdgeDraft.ModelMembers    modelMembers   = null;
            SolidEdgeDraft.GraphicMembers  graphicMembers = null;

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

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

                draftDocument = application.GetActiveDocument <SolidEdgeDraft.DraftDocument>(false);

                if (draftDocument != null)
                {
                    // Get a reference to the Sections collection.
                    sections = draftDocument.Sections;

                    // Get a reference to the WorkingSection.
                    section = sections.WorkingSection;

                    // Get a reference to the Sheets collection.
                    sectionSheets = section.Sheets;

                    foreach (var sheet in sectionSheets.OfType <SolidEdgeDraft.Sheet>())
                    {
                        Console.WriteLine();
                        Console.WriteLine("Processing sheet '{0}'.", sheet.Name);

                        // Get a reference to the DrawingViews collection.
                        drawingViews = sheet.DrawingViews;

                        foreach (var drawingView in drawingViews.OfType <SolidEdgeDraft.DrawingView>())
                        {
                            Console.WriteLine();
                            Console.WriteLine("Processing drawing view '{0}'.", drawingView.Name);

                            double xOrigin = 0;
                            double yOrigin = 0;
                            drawingView.GetOrigin(out xOrigin, out yOrigin);

                            Console.WriteLine("Origin: x={0} y={1}.", xOrigin, yOrigin);

                            // Get a reference to the ModelMembers collection.
                            modelMembers = drawingView.ModelMembers;

                            foreach (var modelMember in modelMembers.OfType <SolidEdgeDraft.ModelMember>())
                            {
                                Console.WriteLine("Processing model member '{0}'.", modelMember.FileName);
                                Console.WriteLine("ComponentType: '{0}'.", modelMember.ComponentType);
                                Console.WriteLine("DisplayType: '{0}'.", modelMember.DisplayType);
                                Console.WriteLine("Type: '{0}'.", modelMember.Type);
                            }

                            // Get a reference to the ModelMembers collection.
                            graphicMembers = drawingView.GraphicMembers;

                            ReportGraphicMembers(graphicMembers);
                        }
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }