/// <summary>
 /// Displays the configuration container used for changing values associated with part properties
 /// </summary>
 private void ShowConfigurationContainer(string filePath)
 {
     try {
         Log.Debug("filePath: " + filePath);
         this._filePath = filePath;
         this.partPropertyBindingSource.Clear();
         SolidEdgePart.PartDocument partDocument = (SolidEdgePart.PartDocument) this.Document.Application.Documents.Open(filePath, 0x00000008);//, "8");
         this.Document.Application.DoIdle();
         // Get a reference to the Variables collection.
         SolidEdgeFramework.Variables variables = (SolidEdgeFramework.Variables)partDocument.Variables;
         // Get a reference to the variableList.
         SolidEdgeFramework.VariableList variableList = (SolidEdgeFramework.VariableList)variables.Query("*", SolidEdgeConstants.VariableNameBy.seVariableNameByBoth, SolidEdgeConstants.VariableVarType.SeVariableVarTypeBoth, false);
         Marshal.FinalReleaseComObject(variables);
         PartProperty partProperty = null;
         foreach (var property in variableList)
         {
             partProperty = new PartProperty(property, partDocument.UnitsOfMeasure);
             if (this._settings.isVariableDefined(partProperty.Name))
             {
                 Log.Debug("partProperty: " + partProperty.Name);
                 this.partPropertyBindingSource.Add(partProperty);
             }
         }
         Marshal.FinalReleaseComObject(variableList);
         // TODO: figure out what causes this to throw "Exception thrown: 'System.MissingMemberException' in Microsoft.VisualBasic.dll"
         partDocument.Close(false);
         Log.Debug("this.Document.Name: " + this.Document.Name);
         this.Document.Application.DoIdle();
         Marshal.FinalReleaseComObject(partDocument);
         this.edgeBar.Panel2Collapsed = false;
     } catch (Exception ex) {
         Log.Error("Unable to open solid edge partDocument | " + ex.Message);
     }
 }
示例#2
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;
            SolidEdgePart.PartDocument     document    = null;

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

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

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

                if (document != null)
                {
                    DocumentHelper.SaveAsJT(document);
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
示例#3
0
        private void button3_Click(object sender, EventArgs e)
        {
            // Connect to or start Solid Edge.
            YCC_solidedge.getEdgeApplication(ref SEApp, true);


            SolidEdgeAssembly.AssemblyDocument asydoc = (SolidEdgeAssembly.AssemblyDocument)SEApp.ActiveDocument;

            SolidEdgeAssembly.Occurrences occs = (SolidEdgeAssembly.Occurrences)asydoc.Occurrences;
            SolidEdgeAssembly.Occurrence  occ  = (SolidEdgeAssembly.Occurrence)occs.Item(2);

            Array MinRangePoint = Array.CreateInstance(typeof(double), 0);
            Array MaxRangePoint = Array.CreateInstance(typeof(double), 0);

            //object[] w = new object[3];

            occ.GetRangeBox(ref MinRangePoint, ref MaxRangePoint);


            SolidEdgePart.PartDocument ps = (SolidEdgePart.PartDocument)occ.OccurrenceDocument;
            //SolidEdgePart.Models ms = (SolidEdgePart.Models)ps.Models.Item[1];
            SolidEdgePart.Model m = (SolidEdgePart.Model)ps.Models.Item(1);

            SolidEdgeGeometry.Body b = (SolidEdgeGeometry.Body)m.Body;

            SolidEdgeGeometry.Edges ees = (SolidEdgeGeometry.Edges)b.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];
            SolidEdgeGeometry.Edge  ee  = (SolidEdgeGeometry.Edge)ees.Item(1);

            //ee.GetRange(ref MinRangePoint, ref MaxRangePoint);


            b.GetRange(ref MinRangePoint, ref MaxRangePoint);
        }
        static void CreateFaceRotateByGeometry(SolidEdgePart.PartDocument partDocument)
        {
            SolidEdgePart.Models      models      = null;
            SolidEdgePart.Model       model       = null;
            SolidEdgeGeometry.Body    body        = null;
            SolidEdgePart.FaceRotates faceRotates = null;
            SolidEdgePart.FaceRotate  faceRotate  = null;
            SolidEdgeGeometry.Faces   faces       = null;
            SolidEdgeGeometry.Face    face        = null;
            SolidEdgeGeometry.Edges   edges       = null;
            SolidEdgeGeometry.Edge    edge        = null;
            double angle = 0.5;

            // Get a reference to the models collection.
            models = partDocument.Models;
            model  = models.Item(1);
            body   = (SolidEdgeGeometry.Body)model.Body;
            faces  = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];
            face   = (SolidEdgeGeometry.Face)faces.Item(2);
            edges  = (SolidEdgeGeometry.Edges)body.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];
            edge   = (SolidEdgeGeometry.Edge)edges.Item(5);

            faceRotates = model.FaceRotates;

            // Add face rotate.
            faceRotate = faceRotates.Add(
                face,
                SolidEdgePart.FaceRotateConstants.igFaceRotateByGeometry,
                SolidEdgePart.FaceRotateConstants.igFaceRotateRecreateBlends,
                null,
                null,
                edge,
                SolidEdgePart.FaceRotateConstants.igFaceRotateAxisEnd,
                angle);
        }
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application  = null;
            SolidEdgeFramework.Documents   documents    = null;
            SolidEdgePart.PartDocument     partDocument = 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;

                Console.WriteLine("Creating a new part document.");

                // Create a new part document.
                partDocument = (SolidEdgePart.PartDocument)
                               documents.Add("SolidEdge.PartDocument");

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                Console.WriteLine("Creating geometry.");

                // Create geometry.
                CreateFiniteExtrudedProtrusion(partDocument);

                Console.WriteLine("Creating holes with user defined patterns.");

                // Create holes.
                CreateHolesWithUserDefinedPattern(partDocument);

                Console.WriteLine("Switching to ISO view.");

                // Switch to ISO view.
                application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                Console.WriteLine(ex.Message);
            }
        }
示例#6
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();
 }
示例#7
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application    application         = null;
            SolidEdgeFramework.Documents      documents           = null;
            SolidEdgePart.PartDocument        partDocument        = null;
            SolidEdgePart.Model               model               = null;
            SolidEdgePart.RevolvedProtrusions revolvedProtrusions = null;
            SolidEdgePart.RevolvedProtrusion  revolvedProtrusion  = null;
            SolidEdgeFramework.SelectSet      selectSet           = 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 PartDocument.
                partDocument = documents.AddPartDocument();

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                // Call helper method to create the actual geometry.
                model = PartHelper.CreateFiniteRevolvedProtrusion(partDocument);

                // Get a reference to the RevolvedProtrusions collection.
                revolvedProtrusions = model.RevolvedProtrusions;

                // Get a reference to the new RevolvedProtrusion.
                revolvedProtrusion = revolvedProtrusions.Item(1);

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

                // Empty ActiveSelectSet.
                selectSet.RemoveAll();

                // Add new RevolvedProtrusion to ActiveSelectSet.
                selectSet.Add(revolvedProtrusion);

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
示例#8
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;
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application  = null;
            SolidEdgePart.PartDocument     partDocument = null;
            SolidEdgePart.Models           models       = null;
            SolidEdgePart.Model            model        = null;
            SolidEdgeGeometry.Body         body         = 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);

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

                // Get a reference to the active part document.
                partDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false);

                if (partDocument != null)
                {
                    models = partDocument.Models;

                    if (models.Count == 0)
                    {
                        throw new System.Exception("No geometry defined.");
                    }

                    model = models.Item(1);
                    body  = (SolidEdgeGeometry.Body)model.Body;

                    Array MinRangePoint = Array.CreateInstance(typeof(double), 0);
                    Array MaxRangePoint = Array.CreateInstance(typeof(double), 0);

                    body.GetRange(ref MinRangePoint, ref MaxRangePoint);
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application     = null;
            SolidEdgePart.PartDocument     partDocument    = 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(true, true);

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

                // Get a reference to the active part document.
                partDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false);

                if (partDocument != null)
                {
                    // Get a reference to the DesignEdgebarFeatures collection.
                    edgebarFeatures = partDocument.DesignEdgebarFeatures;

                    // Interate through the features.
                    for (int i = 1; i <= edgebarFeatures.Count; i++)
                    {
                        // Get the EdgebarFeature at current index.
                        object edgebarFeature = edgebarFeatures.Item(i);

                        // Get the managed type.
                        var type = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetType(edgebarFeature);

                        Console.WriteLine("Item({0}) is of type '{1}'", i, type);
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
示例#11
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application  = null;
            SolidEdgePart.PartDocument     partDocument = 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);

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

                // Get a reference to the active sheetmetal document.
                partDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false);

                if (partDocument != null)
                {
                    switch (partDocument.ModelingMode)
                    {
                    case SolidEdgePart.ModelingModeConstants.seModelingModeOrdered:
                        partDocument.ModelingMode = SolidEdgePart.ModelingModeConstants.seModelingModeSynchronous;
                        Console.WriteLine("Modeling mode changed to synchronous.");
                        break;

                    case SolidEdgePart.ModelingModeConstants.seModelingModeSynchronous:
                        partDocument.ModelingMode = SolidEdgePart.ModelingModeConstants.seModelingModeOrdered;
                        Console.WriteLine("Modeling mode changed to ordered (traditional).");
                        break;
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
示例#12
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application  = null;
            SolidEdgePart.PartDocument     partDocument = null;
            SolidEdgePart.Models           models       = null;
            SolidEdgePart.Model            model        = 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);

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

                // Get a reference to the active part document.
                partDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false);

                if (partDocument != null)
                {
                    models = partDocument.Models;

                    for (int i = 1; i <= models.Count; i++)
                    {
                        model = models.Item(i);
                        model.HealAndOptimizeBody(true, true);
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
示例#13
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application      application  = null;
            SolidEdgePart.PartDocument          document     = null;
            SolidEdgeFramework.Variables        variables    = null;
            SolidEdgeFramework.VariableList     variableList = null;
            SolidEdgeFramework.variable         variable     = null;
            SolidEdgeFrameworkSupport.Dimension dimension    = 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 document.
                document = application.GetActiveDocument <SolidEdgePart.PartDocument>(false);

                // Make sure we have a document.
                if (document != null)
                {
                    VariablesHelper.ReportVariables(document);
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
示例#14
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application  = null;
            SolidEdgeFramework.Documents   documents    = null;
            SolidEdgePart.PartDocument     partDocument = 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 part document using PROGID.
                partDocument = (SolidEdgePart.PartDocument)documents.Add("SolidEdge.PartDocument");

                // Create a new part document using PROGID defined in Interop.SolidEdge.dll.
                partDocument = (SolidEdgePart.PartDocument)documents.Add(SolidEdgeSDK.PROGID.SolidEdge_PartDocument);

                // Create a new part document using SolidEdge.Community.dll extension method.
                partDocument = documents.AddPartDocument();

                // Create a new part document using SolidEdge.Community.dll extension method.
                partDocument = documents.Add <SolidEdgePart.PartDocument>();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
        static void CreateFaceRotateByPoints(SolidEdgePart.PartDocument partDocument)
        {
            SolidEdgePart.Models       models      = null;
            SolidEdgePart.Model        model       = null;
            SolidEdgeGeometry.Body     body        = null;
            SolidEdgePart.FaceRotates  faceRotates = null;
            SolidEdgePart.FaceRotate   faceRotate  = null;
            SolidEdgeGeometry.Faces    faces       = null;
            SolidEdgeGeometry.Face     face        = null;
            SolidEdgeGeometry.Vertices vertices    = null;
            SolidEdgeGeometry.Vertex   point1      = null;
            SolidEdgeGeometry.Vertex   point2      = null;
            double angle = 0.0872664625997165;

            // Get a reference to the models collection.
            models = partDocument.Models;
            model  = models.Item(1);
            body   = (SolidEdgeGeometry.Body)model.Body;
            faces  = (SolidEdgeGeometry.Faces)body.Faces[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];
            face   = (SolidEdgeGeometry.Face)faces.Item(1);

            vertices = (SolidEdgeGeometry.Vertices)face.Vertices;
            point1   = (SolidEdgeGeometry.Vertex)vertices.Item(1);
            point2   = (SolidEdgeGeometry.Vertex)vertices.Item(2);

            faceRotates = model.FaceRotates;

            // Add face rotate.
            faceRotate = faceRotates.Add(
                face,
                SolidEdgePart.FaceRotateConstants.igFaceRotateByPoints,
                SolidEdgePart.FaceRotateConstants.igFaceRotateRecreateBlends,
                point1,
                point2,
                null,
                SolidEdgePart.FaceRotateConstants.igFaceRotateNone,
                angle);
        }
        static void CreateFiniteExtrudedProtrusion(SolidEdgePart.PartDocument partDocument)
        {
            SolidEdgePart.ProfileSets             profileSets = null;
            SolidEdgePart.ProfileSet              profileSet  = null;
            SolidEdgePart.Profiles                profiles    = null;
            SolidEdgePart.Profile                 profile     = null;
            SolidEdgePart.RefPlanes               refplanes   = null;
            SolidEdgeFrameworkSupport.Relations2d relations2d = null;
            SolidEdgeFrameworkSupport.Relation2d  relation2d  = null;
            SolidEdgeFrameworkSupport.Lines2d     lines2d     = null;
            SolidEdgeFrameworkSupport.Line2d      line2d      = null;
            SolidEdgePart.Models models    = null;
            SolidEdgePart.Model  model     = null;
            System.Array         aProfiles = null;

            // Get a reference to the profile sets collection.
            profileSets = partDocument.ProfileSets;

            // Add a new profile set.
            profileSet = profileSets.Add();

            // Get a reference to the profiles collection.
            profiles = profileSet.Profiles;

            // Get a reference to the ref planes collection.
            refplanes = partDocument.RefPlanes;

            // Add a new profile.
            profile = profiles.Add(refplanes.Item(3));

            // Get a reference to the lines2d collection.
            lines2d = profile.Lines2d;

            // UOM = meters.
            double[,] lineMatrix = new double[, ]
            {
                //{x1, y1, x2, y2}
                { 0, 0, 0.08, 0 },
                { 0.08, 0, 0.08, 0.06 },
                { 0.08, 0.06, 0.064, 0.06 },
                { 0.064, 0.06, 0.064, 0.02 },
                { 0.064, 0.02, 0.048, 0.02 },
                { 0.048, 0.02, 0.048, 0.06 },
                { 0.048, 0.06, 0.032, 0.06 },
                { 0.032, 0.06, 0.032, 0.02 },
                { 0.032, 0.02, 0.016, 0.02 },
                { 0.016, 0.02, 0.016, 0.06 },
                { 0.016, 0.06, 0, 0.06 },
                { 0, 0.06, 0, 0 }
            };

            // Draw the Base Profile.
            for (int i = 0; i <= lineMatrix.GetUpperBound(0); i++)
            {
                line2d = lines2d.AddBy2Points(
                    x1: lineMatrix[i, 0],
                    y1: lineMatrix[i, 1],
                    x2: lineMatrix[i, 2],
                    y2: lineMatrix[i, 3]);
            }

            // Define Relations among the Line objects to make the Profile closed.
            relations2d = (SolidEdgeFrameworkSupport.Relations2d)profile.Relations2d;

            // Connect all of the lines.
            for (int i = 1; i <= lines2d.Count; i++)
            {
                int j = i + 1;

                // When we reach the last line, wrap around and connect it to the first line.
                if (j > lines2d.Count)
                {
                    j = 1;
                }

                relation2d = relations2d.AddKeypoint(
                    Object1: lines2d.Item(i),
                    Index1: (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    Object2: lines2d.Item(j),
                    Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart,
                    guaranteed_ok: true);
            }

            // Close the profile.
            profile.End(SolidEdgePart.ProfileValidationType.igProfileClosed);

            // Hide the profile.
            profile.Visible = false;

            // Create a new array of profile objects.
            aProfiles = Array.CreateInstance(typeof(SolidEdgePart.Profile), 1);
            aProfiles.SetValue(profile, 0);

            // Get a reference to the models collection.
            models = partDocument.Models;

            Console.WriteLine("Creating finite extruded protrusion.");

            // Create the extended protrusion.
            model = models.AddFiniteExtrudedProtrusion(
                NumberOfProfiles: aProfiles.Length,
                ProfileArray: ref aProfiles,
                ProfilePlaneSide: SolidEdgePart.FeaturePropertyConstants.igRight,
                ExtrusionDistance: 0.005);
        }
        static void GetPhysicalProperties(SolidEdgePart.PartDocument partDocument, bool compute)
        {
            SolidEdgePart.Models models = null;
            SolidEdgePart.Model  model  = null;

            models = partDocument.Models;
            model  = models.Item(1);

            double density                   = 0;
            double accuracy                  = 0;
            double volume                    = 0;
            double area                      = 0;
            double mass                      = 0;
            Array  cetnerOfGravity           = Array.CreateInstance(typeof(double), 3);
            Array  centerOfVolumne           = Array.CreateInstance(typeof(double), 3);
            Array  globalMomentsOfInteria    = Array.CreateInstance(typeof(double), 6); // Ixx, Iyy, Izz, Ixy, Ixz and Iyz
            Array  principalMomentsOfInteria = Array.CreateInstance(typeof(double), 3); // Ixx, Iyy and Izz
            Array  principalAxes             = Array.CreateInstance(typeof(double), 9); // 3 axes x 3 coords
            Array  radiiOfGyration           = Array.CreateInstance(typeof(double), 9); // 3 axes x 3 coords
            double relativeAccuracyAchieved  = 0;
            int    status                    = 0;

            if (compute)
            {
                density  = 1;
                accuracy = 0.05;

                model.ComputePhysicalProperties(
                    Density: density,
                    Accuracy: accuracy,
                    Volume: out volume,
                    Area: out area,
                    Mass: out mass,
                    CenterOfGravity: ref cetnerOfGravity,
                    CenterOfVolume: ref centerOfVolumne,
                    GlobalMomentsOfInteria: ref globalMomentsOfInteria,
                    PrincipalMomentsOfInteria: ref principalMomentsOfInteria,
                    PrincipalAxes: ref principalAxes,
                    RadiiOfGyration: ref radiiOfGyration,
                    RelativeAccuracyAchieved: out relativeAccuracyAchieved,
                    Status: out status);

                Console.WriteLine("ComputePhysicalProperties() results:");
            }
            else
            {
                model.GetPhysicalProperties(
                    Status: out status,
                    Density: out density,
                    Accuracy: out accuracy,
                    Volume: out volume,
                    Area: out area,
                    Mass: out mass,
                    CenterOfGravity: ref cetnerOfGravity,
                    CenterOfVolume: ref centerOfVolumne,
                    GlobalMomentsOfInteria: ref globalMomentsOfInteria,
                    PrincipalMomentsOfInteria: ref principalMomentsOfInteria,
                    PrincipalAxes: ref principalAxes,
                    RadiiOfGyration: ref radiiOfGyration,
                    RelativeAccuracyAchieved: out relativeAccuracyAchieved);

                Console.WriteLine("GetPhysicalProperties() results:");
            }

            // Write results to screen.

            Console.WriteLine("Density: {0}", density);
            Console.WriteLine("Accuracy: {0}", accuracy);
            Console.WriteLine("Volume: {0}", volume);
            Console.WriteLine("Area: {0}", area);
            Console.WriteLine("Mass: {0}", mass);

            // Convert from System.Array to double[].  double[] is easier to work with.
            double[] m = cetnerOfGravity.OfType <double>().ToArray();

            Console.WriteLine("CenterOfGravity:");
            Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);

            m = centerOfVolumne.OfType <double>().ToArray();

            Console.WriteLine("CenterOfVolume:");
            Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);

            m = globalMomentsOfInteria.OfType <double>().ToArray();

            Console.WriteLine("GlobalMomentsOfInteria:");
            Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);
            Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]);

            m = principalMomentsOfInteria.OfType <double>().ToArray();

            Console.WriteLine("PrincipalMomentsOfInteria:");
            Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);

            m = principalAxes.OfType <double>().ToArray();

            Console.WriteLine("PrincipalAxes:");
            Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);
            Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]);
            Console.WriteLine("\t|{0}, {1}, {2}|", m[6], m[7], m[8]);

            m = radiiOfGyration.OfType <double>().ToArray();

            Console.WriteLine("RadiiOfGyration:");
            Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);
            Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]);
            Console.WriteLine("\t|{0}, {1}, {2}|", m[6], m[7], m[8]);

            Console.WriteLine("RelativeAccuracyAchieved: {0}", relativeAccuracyAchieved);
            Console.WriteLine("Status: {0}", status);
            Console.WriteLine();
        }
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application  = null;
            SolidEdgeFramework.Documents   documents    = null;
            SolidEdgePart.PartDocument     partDocument = 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;

                Console.WriteLine("Creating a new part document.");

                // Create a new part document.
                partDocument = (SolidEdgePart.PartDocument)
                               documents.Add("SolidEdge.PartDocument");

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                Console.WriteLine("Drawing part.");

                // Create geometry.
                CreateFiniteExtrudedProtrusion(partDocument);

                Console.WriteLine();

                // Physical properties have not yet been computed for this model
                // so all values will be 0 with a status of 2.
                GetPhysicalProperties(partDocument, false);

                // This time, we will compute the physical properties of the model.
                GetPhysicalProperties(partDocument, true);

                Console.WriteLine("Switching to ISO view.");

                // Switch to ISO view.
                application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)SolidEdgeConstants.PartCommandConstants.PartViewISOView);

                // Show physical properties window.
                application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)SolidEdgeConstants.PartCommandConstants.PartToolsPhysicalProperties);
            }
            catch (System.Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                Console.WriteLine(ex.Message);
            }
        }
示例#19
0
        private void button4_Click(object sender, EventArgs e)
        {
            YCC_solidedge.getEdgeApplication(ref SEApp, true);
            partDoc = (SolidEdgePart.PartDocument)SEApp.ActiveDocument;
            SolidEdgePart.Model     md = partDoc.Models.Item(1);
            SolidEdgeGeometry.Body  by = (SolidEdgeGeometry.Body)md.Body;
            SolidEdgeGeometry.Edges ed = (SolidEdgeGeometry.Edges)by.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryStraight];

            List <SolidEdgeGeometry.Edge> ListExceptionEdge = new List <SolidEdgeGeometry.Edge>();

            int Count = 0;

            foreach (SolidEdgeGeometry.Edge _e in ed)
            {
                if (ListExceptionEdge.Contains(_e))
                {
                    continue;
                }

                SEEdge newpoint = new SEEdge(_e);

                if (newpoint.Len == 23.09 || newpoint.Len == 11.55)
                {
                    POP newPOP = new POP(newpoint);
                    Count = Count + 1;

                    if (newPOP.ListHexagonEdge.Count == 6)
                    {
                        foreach (SolidEdgeGeometry.Edge _edge in newPOP.ListHexagonEdge)
                        {
                            ListExceptionEdge.Add(_edge);
                        }
                        foreach (SolidEdgeGeometry.Edge _edge in newPOP.ListHoleEdge)
                        {
                            ListExceptionEdge.Add(_edge);
                        }
                        foreach (SolidEdgeGeometry.Edge _edge in newPOP.ListOtherHexagonEdge)
                        {
                            ListExceptionEdge.Add(_edge);
                        }
                    }
                }
            }


            //bool done = true;
            //int count = 0;
            //while (done)
            //{
            //    foreach (SEEdge _p in point23)
            //    {
            //        if (www(ref point23, _p))
            //        {
            //            count++;
            //            break;
            //        }

            //        if (_p == point23[point23.Count() - 1]) done = false;
            //    }

            //    if (point23.Count == 0) done = false;
            //}
        }
示例#20
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");
        }
示例#21
0
    public static SolidEdgePart.Model CreateFiniteRevolvedProtrusion(SolidEdgePart.PartDocument partDocument)
    {
        SolidEdgePart.RefPlanes               refPlanes   = null;
        SolidEdgePart.RefPlane                refPlane    = null;
        SolidEdgePart.ProfileSets             profileSets = null;
        SolidEdgePart.ProfileSet              profileSet  = null;
        SolidEdgePart.Profiles                profiles    = null;
        SolidEdgePart.Profile                 profile     = null;
        SolidEdgePart.Models                  models      = null;
        SolidEdgePart.Model                   model       = null;
        SolidEdgeFrameworkSupport.Lines2d     lines2d     = null;
        SolidEdgeFrameworkSupport.Line2d      axis        = null;
        SolidEdgeFrameworkSupport.Arcs2d      arcs2d      = null;
        SolidEdgeFrameworkSupport.Relations2d relations2d = null;
        SolidEdgePart.RefAxis                 refaxis     = null;
        Array aProfiles = null;

        // Get a reference to the models collection.
        models = (SolidEdgePart.Models)partDocument.Models;

        // D1 to FA are parameters in a form, introduced by the user.
        double D1 = 0.020;
        double D2 = 0.026;
        double D3 = 0.003;
        double D4 = 0.014;
        double L1 = 0.040;
        double L2 = 0.030;
        double L3 = 0.005;

        // Get a reference to the ref planes collection.
        refPlanes = partDocument.RefPlanes;

        // Get a reference to front RefPlane.
        refPlane = refPlanes.GetFrontPlane();

        // Get a reference to the profile sets collection.
        profileSets = (SolidEdgePart.ProfileSets)partDocument.ProfileSets;

        // Create a new profile set.
        profileSet = profileSets.Add();

        // Get a reference to the profiles collection.
        profiles = profileSet.Profiles;

        // Create a new profile.
        profile = profiles.Add(refPlane);

        // Get a reference to the profile lines2d collection.
        lines2d = profile.Lines2d;

        // Get a reference to the profile arcs2d collection.
        arcs2d = profile.Arcs2d;

        double H = L1 - L2;
        double y = L1 - L3 - (D4 - D3) / (2 * Math.Tan((118 / 2) * (Math.PI / 180)));

        lines2d.AddBy2Points(D3 / 2, 0, D2 / 2, 0);        // Line1
        lines2d.AddBy2Points(D2 / 2, 0, D2 / 2, H);        // Line2
        lines2d.AddBy2Points(D2 / 2, H, D1 / 2, H);        // Line3
        lines2d.AddBy2Points(D1 / 2, H, D1 / 2, L1);       // Line4
        lines2d.AddBy2Points(D1 / 2, L1, D4 / 2, L1);      // Line5
        lines2d.AddBy2Points(D4 / 2, L1, D4 / 2, L1 - L3); // Line6
        lines2d.AddBy2Points(D4 / 2, L1 - L3, D3 / 2, y);  // Line7
        lines2d.AddBy2Points(D3 / 2, y, D3 / 2, 0);        // Line8

        axis = lines2d.AddBy2Points(0, 0, 0, L1);
        profile.ToggleConstruction(axis);

        // relations
        relations2d = (SolidEdgeFrameworkSupport.Relations2d)profile.Relations2d;
        relations2d.AddKeypoint(lines2d.Item(1), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(2), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
        relations2d.AddKeypoint(lines2d.Item(2), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(3), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
        relations2d.AddKeypoint(lines2d.Item(3), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(4), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
        relations2d.AddKeypoint(lines2d.Item(4), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(5), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
        relations2d.AddKeypoint(lines2d.Item(5), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(6), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
        relations2d.AddKeypoint(lines2d.Item(6), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(7), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
        relations2d.AddKeypoint(lines2d.Item(7), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(8), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
        relations2d.AddKeypoint(lines2d.Item(8), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(1), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);

        refaxis = (SolidEdgePart.RefAxis)profile.SetAxisOfRevolution(axis);

        // Close the profile.
        int status = profile.End(SolidEdgePart.ProfileValidationType.igProfileRefAxisRequired);

        profile.Visible = false;

        // Create a new array of profile objects.
        aProfiles = Array.CreateInstance(typeof(SolidEdgePart.Profile), 1);
        aProfiles.SetValue(profile, 0);

        // add Finite Revolved Protrusion.
        model = models.AddFiniteRevolvedProtrusion(
            aProfiles.Length,
            ref aProfiles,
            refaxis,
            SolidEdgePart.FeaturePropertyConstants.igRight,
            2 * Math.PI,
            null,
            null);

        return(model);
    }
示例#22
0
    public static SolidEdgePart.Model CreateSweptProtrusion(SolidEdgePart.PartDocument partDocument)
    {
        SolidEdgePart.Models                models        = null;
        SolidEdgePart.Model                 model         = null;
        SolidEdgePart.Sketchs               sketches      = null;
        SolidEdgePart.Sketch                sketch        = null;
        SolidEdgePart.RefPlanes             refPlanes     = null;
        SolidEdgePart.RefPlane              refPlane      = null;
        SolidEdgePart.ProfileSets           profileSets   = null;
        SolidEdgePart.ProfileSet            profileSet    = null;
        SolidEdgePart.Profiles              profiles      = null;
        SolidEdgePart.Profile               sketchProfile = null;
        SolidEdgePart.Profile               profile       = null;
        SolidEdgeFrameworkSupport.Circles2d circles2d     = null;

        List <SolidEdgePart.Profile> listPaths = new List <SolidEdgePart.Profile>();
        List <SolidEdgePart.FeaturePropertyConstants> listPathTypes = new List <SolidEdgePart.FeaturePropertyConstants>();
        List <SolidEdgePart.Profile> listSections = new List <SolidEdgePart.Profile>();
        List <SolidEdgePart.FeaturePropertyConstants> listSectionTypes = new List <SolidEdgePart.FeaturePropertyConstants>();
        List <int> listOrigins = new List <int>();

        // Get a reference to the models collection.
        models = (SolidEdgePart.Models)partDocument.Models;

        // Get a reference to the Sketches collections.
        sketches = (SolidEdgePart.Sketchs)partDocument.Sketches;

        // Get a reference to the profile sets collection.
        profileSets = (SolidEdgePart.ProfileSets)partDocument.ProfileSets;

        // Get a reference to the ref planes collection.
        refPlanes = (SolidEdgePart.RefPlanes)partDocument.RefPlanes;

        // Get a reference to front RefPlane.
        refPlane = refPlanes.GetFrontPlane();

        // Add a new sketch.
        sketch = (SolidEdgePart.Sketch)sketches.Add();

        // Add profile for sketch on specified refplane.
        sketchProfile = sketch.Profiles.Add(refPlane);

        // Get a reference to the Circles2d collection.
        circles2d = sketchProfile.Circles2d;

        // Draw the Base Profile.
        circles2d.AddByCenterRadius(0, 0, 0.02);

        // Close the profile.
        sketchProfile.End(SolidEdgePart.ProfileValidationType.igProfileClosed);

        // Arrays for AddSweptProtrusion().
        listPaths.Add(sketchProfile);
        listPathTypes.Add(SolidEdgePart.FeaturePropertyConstants.igProfileBasedCrossSection);

        // NOTE: profile is the Curve.
        refPlane = refPlanes.AddNormalToCurve(
            sketchProfile,
            SolidEdgePart.ReferenceElementConstants.igCurveEnd,
            refPlanes.GetFrontPlane(),
            SolidEdgePart.ReferenceElementConstants.igPivotEnd,
            true,
            System.Reflection.Missing.Value);

        // Add a new profile set.
        profileSet = (SolidEdgePart.ProfileSet)profileSets.Add();

        // Get a reference to the profiles collection.
        profiles = (SolidEdgePart.Profiles)profileSet.Profiles;

        // add a new profile.
        profile = (SolidEdgePart.Profile)profiles.Add(refPlane);

        // Get a reference to the Circles2d collection.
        circles2d = profile.Circles2d;

        // Draw the Base Profile.
        circles2d.AddByCenterRadius(0, 0, 0.01);

        // Close the profile.
        profile.End(SolidEdgePart.ProfileValidationType.igProfileClosed);

        // Arrays for AddSweptProtrusion().
        listSections.Add(profile);
        listSectionTypes.Add(SolidEdgePart.FeaturePropertyConstants.igProfileBasedCrossSection);
        listOrigins.Add(0); //Use 0 for closed profiles.

        // Create the extended protrusion.
        model = models.AddSweptProtrusion(
            listPaths.Count,
            listPaths.ToArray(),
            listPathTypes.ToArray(),
            listSections.Count,
            listSections.ToArray(),
            listSectionTypes.ToArray(),
            listOrigins.ToArray(),
            0,
            SolidEdgePart.FeaturePropertyConstants.igLeft,
            SolidEdgePart.FeaturePropertyConstants.igNone,
            0.0,
            null,
            SolidEdgePart.FeaturePropertyConstants.igNone,
            0.0,
            null);

        // Hide profiles.
        sketchProfile.Visible = false;
        profile.Visible       = false;

        return(model);
    }
示例#23
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application    application         = null;
            SolidEdgeFramework.Documents      documents           = null;
            SolidEdgePart.PartDocument        partDocument        = null;
            SolidEdgePart.RefPlanes           refPlanes           = null;
            SolidEdgePart.RefPlane            refPlane            = null;
            SolidEdgePart.Model               model               = null;
            SolidEdgePart.ExtrudedProtrusions extrudedProtrusions = null;
            SolidEdgeFramework.SelectSet      selectSet           = null;
            SolidEdgePart.ExtrudedProtrusion  extrudedProtrusion  = 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 part document.
                partDocument = documents.AddPartDocument();

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                // Get a reference to the RefPlanes collection.
                refPlanes = partDocument.RefPlanes;

                // Get a reference to a RefPlane.
                refPlane = refPlanes.GetFrontPlane();

                List <double[]> linesArray = new List <double[]>();
                linesArray.Add(new double[] { 0, 0, 0.08, 0 });
                linesArray.Add(new double[] { 0.08, 0, 0.08, 0.06 });
                linesArray.Add(new double[] { 0.08, 0.06, 0.064, 0.06 });
                linesArray.Add(new double[] { 0.064, 0.06, 0.064, 0.02 });
                linesArray.Add(new double[] { 0.064, 0.02, 0.048, 0.02 });
                linesArray.Add(new double[] { 0.048, 0.02, 0.048, 0.06 });
                linesArray.Add(new double[] { 0.048, 0.06, 0.032, 0.06 });
                linesArray.Add(new double[] { 0.032, 0.06, 0.032, 0.02 });
                linesArray.Add(new double[] { 0.032, 0.02, 0.016, 0.02 });
                linesArray.Add(new double[] { 0.016, 0.02, 0.016, 0.06 });
                linesArray.Add(new double[] { 0.016, 0.06, 0, 0.06 });
                linesArray.Add(new double[] { 0, 0.06, 0, 0 });

                // Call helper method to create the actual geometry.
                model = PartHelper.CreateFiniteExtrudedProtrusion(partDocument, refPlane, linesArray.ToArray(), SolidEdgePart.FeaturePropertyConstants.igRight, 0.005);

                // Get a reference to the ExtrudedProtrusions collection.
                extrudedProtrusions = model.ExtrudedProtrusions;

                // Get a reference to the new ExtrudedProtrusion.
                extrudedProtrusion = extrudedProtrusions.Item(1);

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

                // Empty ActiveSelectSet.
                selectSet.RemoveAll();

                // Add new protrusion to ActiveSelectSet.
                selectSet.Add(extrudedProtrusion);

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
示例#24
0
    public static void CreateHolesWithUserDefinedPattern(SolidEdgePart.PartDocument partDocument)
    {
        SolidEdgePart.RefPlanes          refplanes          = null;
        SolidEdgePart.RefPlane           refplane           = null;
        SolidEdgePart.Models             models             = null;
        SolidEdgePart.Model              model              = null;
        SolidEdgePart.HoleDataCollection holeDataCollection = null;
        SolidEdgePart.ProfileSets        profileSets        = null;
        SolidEdgePart.ProfileSet         profileSet         = null;
        SolidEdgePart.Profiles           profiles           = null;
        SolidEdgePart.Profile            profile            = null;
        SolidEdgePart.Holes2d            holes2d            = null;
        SolidEdgePart.Hole2d             hole2d             = null;
        SolidEdgePart.Holes              holes              = null;
        SolidEdgePart.Hole hole = null;
        long profileStatus      = 0;
        List <SolidEdgePart.Profile> profileList = new List <SolidEdgePart.Profile>();

        SolidEdgePart.UserDefinedPatterns userDefinedPatterns = null;
        SolidEdgePart.UserDefinedPattern  userDefinedPattern  = null;

        // Get a reference to the RefPlanes collection.
        refplanes = partDocument.RefPlanes;

        // Get a reference to front RefPlane.
        refplane = refplanes.GetFrontPlane();

        List <double[]> linesArray = new List <double[]>();

        linesArray.Add(new double[] { 0, 0, 0.08, 0 });
        linesArray.Add(new double[] { 0.08, 0, 0.08, 0.06 });
        linesArray.Add(new double[] { 0.08, 0.06, 0.064, 0.06 });
        linesArray.Add(new double[] { 0.064, 0.06, 0.064, 0.02 });
        linesArray.Add(new double[] { 0.064, 0.02, 0.048, 0.02 });
        linesArray.Add(new double[] { 0.048, 0.02, 0.048, 0.06 });
        linesArray.Add(new double[] { 0.048, 0.06, 0.032, 0.06 });
        linesArray.Add(new double[] { 0.032, 0.06, 0.032, 0.02 });
        linesArray.Add(new double[] { 0.032, 0.02, 0.016, 0.02 });
        linesArray.Add(new double[] { 0.016, 0.02, 0.016, 0.06 });
        linesArray.Add(new double[] { 0.016, 0.06, 0, 0.06 });
        linesArray.Add(new double[] { 0, 0.06, 0, 0 });

        // Call helper method to create the actual geometry.
        CreateFiniteExtrudedProtrusion(partDocument, refplane, linesArray.ToArray(), SolidEdgePart.FeaturePropertyConstants.igRight, 0.005);

        // Get a reference to the Models collection.
        models = partDocument.Models;

        // Get a reference to Model.
        model = models.Item(1);

        // Get a reference to the ProfileSets collection.
        profileSets = partDocument.ProfileSets;

        // Add new ProfileSet.
        profileSet = profileSets.Add();

        // Get a reference to the Profiles collection.
        profiles = profileSet.Profiles;

        // Add new Profile.
        profile = profiles.Add(refplane);

        // Get a reference to the Holes2d collection.
        holes2d = profile.Holes2d;

        double[,] holeMatrix = new double[, ]
        {
            //{x, y}
            { 0.01, 0.01 },
            { 0.02, 0.01 },
            { 0.03, 0.01 },
            { 0.04, 0.01 },
            { 0.05, 0.01 },
            { 0.06, 0.01 },
            { 0.07, 0.01 }
        };

        // Draw the Base Profile.
        for (int i = 0; i <= holeMatrix.GetUpperBound(0); i++)
        {
            // Add new Hole2d.
            hole2d = holes2d.Add(
                XCenter: holeMatrix[i, 0],
                YCenter: holeMatrix[i, 1]);
        }

        // Hide the profile.
        profile.Visible = false;

        // Close profile.
        profileStatus = profile.End(SolidEdgePart.ProfileValidationType.igProfileClosed);

        // Get a reference to the ProfileSet.
        profileSet = (SolidEdgePart.ProfileSet)profile.Parent;

        // Get a reference to the Profiles collection.
        profiles = profileSet.Profiles;

        // Add profiles to list for AddByProfiles().
        for (int i = 1; i <= profiles.Count; i++)
        {
            profileList.Add(profiles.Item(i));
        }

        // Get a reference to the HoleDataCollection collection.
        holeDataCollection = partDocument.HoleDataCollection;

        // Add new HoleData.
        SolidEdgePart.HoleData holeData = holeDataCollection.Add(
            HoleType: SolidEdgePart.FeaturePropertyConstants.igRegularHole,
            HoleDiameter: 0.005,
            BottomAngle: 90);

        // Get a reference to the Holes collection.
        holes = model.Holes;

        // Add hole.
        hole = holes.AddFinite(
            Profile: profile,
            ProfilePlaneSide: SolidEdgePart.FeaturePropertyConstants.igRight,
            FiniteDepth: 0.005,
            Data: holeData);

        // Get a reference to the UserDefinedPatterns collection.
        userDefinedPatterns = model.UserDefinedPatterns;

        // Create the user defined pattern.
        userDefinedPattern = userDefinedPatterns.AddByProfiles(
            NumberOfProfiles: profileList.Count,
            ProfilesArray: profileList.ToArray(),
            SeedFeature: hole);
    }
示例#25
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application  = null;
            SolidEdgePart.PartDocument     partDocument = null;
            SolidEdgePart.Models           models       = null;
            SolidEdgePart.Model            model        = null;
            double density                   = 0;
            double accuracy                  = 0;
            double volume                    = 0;
            double area                      = 0;
            double mass                      = 0;
            Array  cetnerOfGravity           = Array.CreateInstance(typeof(double), 3);
            Array  centerOfVolumne           = Array.CreateInstance(typeof(double), 3);
            Array  globalMomentsOfInteria    = Array.CreateInstance(typeof(double), 6); // Ixx, Iyy, Izz, Ixy, Ixz and Iyz
            Array  principalMomentsOfInteria = Array.CreateInstance(typeof(double), 3); // Ixx, Iyy and Izz
            Array  principalAxes             = Array.CreateInstance(typeof(double), 9); // 3 axes x 3 coords
            Array  radiiOfGyration           = Array.CreateInstance(typeof(double), 9); // 3 axes x 3 coords
            double relativeAccuracyAchieved  = 0;
            int    status                    = 0;

            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 document.
                partDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false);

                if (partDocument != null)
                {
                    density  = 1;
                    accuracy = 0.05;

                    // Get a reference to the Models collection.
                    models = partDocument.Models;

                    // Get a reference to the Model.
                    model = models.Item(1);

                    // Compute the physical properties.
                    model.ComputePhysicalProperties(
                        Density: density,
                        Accuracy: accuracy,
                        Volume: out volume,
                        Area: out area,
                        Mass: out mass,
                        CenterOfGravity: ref cetnerOfGravity,
                        CenterOfVolume: ref centerOfVolumne,
                        GlobalMomentsOfInteria: ref globalMomentsOfInteria,
                        PrincipalMomentsOfInteria: ref principalMomentsOfInteria,
                        PrincipalAxes: ref principalAxes,
                        RadiiOfGyration: ref radiiOfGyration,
                        RelativeAccuracyAchieved: out relativeAccuracyAchieved,
                        Status: out status);

                    Console.WriteLine("ComputePhysicalProperties() results:");

                    // Write results to screen.

                    Console.WriteLine("Density: {0}", density);
                    Console.WriteLine("Accuracy: {0}", accuracy);
                    Console.WriteLine("Volume: {0}", volume);
                    Console.WriteLine("Area: {0}", area);
                    Console.WriteLine("Mass: {0}", mass);

                    // Convert from System.Array to double[].  double[] is easier to work with.
                    double[] m = cetnerOfGravity.OfType <double>().ToArray();

                    Console.WriteLine("CenterOfGravity:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);

                    m = centerOfVolumne.OfType <double>().ToArray();

                    Console.WriteLine("CenterOfVolume:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);

                    m = globalMomentsOfInteria.OfType <double>().ToArray();

                    Console.WriteLine("GlobalMomentsOfInteria:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]);

                    m = principalMomentsOfInteria.OfType <double>().ToArray();

                    Console.WriteLine("PrincipalMomentsOfInteria:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);

                    m = principalAxes.OfType <double>().ToArray();

                    Console.WriteLine("PrincipalAxes:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]);
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[6], m[7], m[8]);

                    m = radiiOfGyration.OfType <double>().ToArray();

                    Console.WriteLine("RadiiOfGyration:");
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[0], m[1], m[2]);
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[3], m[4], m[5]);
                    Console.WriteLine("\t|{0}, {1}, {2}|", m[6], m[7], m[8]);

                    Console.WriteLine("RelativeAccuracyAchieved: {0}", relativeAccuracyAchieved);
                    Console.WriteLine("Status: {0}", status);
                    Console.WriteLine();

                    // Show physical properties window.
                    application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartToolsPhysicalProperties);
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
示例#26
0
    public static SolidEdgePart.Model CreateFiniteExtrudedProtrusion(SolidEdgePart.PartDocument partDocument, SolidEdgePart.RefPlane refPlane, double[][] linesArray, SolidEdgePart.FeaturePropertyConstants profilePlaneSide, double extrusionDistance)
    {
        SolidEdgePart.ProfileSets             profileSets = null;
        SolidEdgePart.ProfileSet              profileSet  = null;
        SolidEdgePart.Profiles                profiles    = null;
        SolidEdgePart.Profile                 profile     = null;
        SolidEdgeFrameworkSupport.Relations2d relations2d = null;
        SolidEdgeFrameworkSupport.Relation2d  relation2d  = null;
        SolidEdgeFrameworkSupport.Lines2d     lines2d     = null;
        SolidEdgeFrameworkSupport.Line2d      line2d      = null;
        SolidEdgePart.Models models    = null;
        SolidEdgePart.Model  model     = null;
        System.Array         aProfiles = null;

        // Get a reference to the profile sets collection.
        profileSets = partDocument.ProfileSets;

        // Add a new profile set.
        profileSet = profileSets.Add();

        // Get a reference to the profiles collection.
        profiles = profileSet.Profiles;

        // Add a new profile.
        profile = profiles.Add(refPlane);

        // Get a reference to the lines2d collection.
        lines2d = profile.Lines2d;

        // Draw the Base Profile.
        for (int i = 0; i <= linesArray.GetUpperBound(0); i++)
        {
            line2d = lines2d.AddBy2Points(
                x1: linesArray[i][0],
                y1: linesArray[i][1],
                x2: linesArray[i][2],
                y2: linesArray[i][3]);
        }

        // Define Relations among the Line objects to make the Profile closed.
        relations2d = (SolidEdgeFrameworkSupport.Relations2d)profile.Relations2d;

        // Connect all of the lines.
        for (int i = 1; i <= lines2d.Count; i++)
        {
            int j = i + 1;

            // When we reach the last line, wrap around and connect it to the first line.
            if (j > lines2d.Count)
            {
                j = 1;
            }

            relation2d = relations2d.AddKeypoint(
                Object1: lines2d.Item(i),
                Index1: (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                Object2: lines2d.Item(j),
                Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart,
                guaranteed_ok: true);
        }

        // Close the profile.
        profile.End(SolidEdgePart.ProfileValidationType.igProfileClosed);

        // Hide the profile.
        profile.Visible = false;

        // Create a new array of profile objects.
        aProfiles = Array.CreateInstance(typeof(SolidEdgePart.Profile), 1);
        aProfiles.SetValue(profile, 0);

        // Get a reference to the models collection.
        models = partDocument.Models;

        // Create the extended protrusion.
        model = models.AddFiniteExtrudedProtrusion(
            NumberOfProfiles: aProfiles.Length,
            ProfileArray: ref aProfiles,
            ProfilePlaneSide: profilePlaneSide,
            ExtrusionDistance: extrusionDistance);

        return(model);
    }
示例#27
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application        application  = null;
            SolidEdgeFramework.Documents          documents    = null;
            SolidEdgePart.PartDocument            partDocument = null;
            SolidEdgePart.RefPlanes               refPlanes    = null;
            SolidEdgePart.RefPlane                refPlane     = null;
            SolidEdgePart.ProfileSets             profileSets  = null;
            SolidEdgePart.ProfileSet              profileSet   = null;
            SolidEdgePart.Profiles                profiles     = null;
            SolidEdgePart.Profile                 profile      = null;
            SolidEdgeFrameworkSupport.Lines2d     lines2d      = null;
            SolidEdgeFrameworkSupport.Line2d      line2d       = null;
            SolidEdgeFrameworkSupport.Relations2d relations2d  = null;
            SolidEdgeFrameworkSupport.Relation2d  relation2d   = null;
            SolidEdgePart.Models         models      = null;
            SolidEdgePart.Model          model       = null;
            List <SolidEdgePart.Profile> profileList = new List <SolidEdgePart.Profile>();
            int status = 0;

            SolidEdgePart.ExtrudedProtrusions extrudedProtrusions = null;
            SolidEdgePart.ExtrudedProtrusion  extrudedProtrusion  = null;
            SolidEdgeGeometry.Edges           edges = null;
            List <object> edgeList = new List <object>();

            SolidEdgeGeometry.Faces faces    = null;
            SolidEdgePart.Chamfers  chamfers = null;
            SolidEdgePart.Chamfer   chamfer  = 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);

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

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

                // Create a new part document.
                partDocument = documents.AddPartDocument();

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                refPlanes = partDocument.RefPlanes;
                refPlane  = refPlanes.Item(1);

                profileSets = partDocument.ProfileSets;
                profileSet  = profileSets.Add();

                profiles = profileSet.Profiles;
                profile  = profiles.Add(refPlane);
                profileList.Add(profile);

                lines2d = profile.Lines2d;
                line2d  = lines2d.AddBy2Points(0, 0, 0.06, 0);
                line2d  = lines2d.AddBy2Points(0.06, 0, 0.06, 0.06);
                line2d  = lines2d.AddBy2Points(0.06, 0.06, 0, 0.06);
                line2d  = lines2d.AddBy2Points(0, 0.06, 0, 0);

                relations2d = (SolidEdgeFrameworkSupport.Relations2d)profile.Relations2d;
                relation2d  = relations2d.AddKeypoint(
                    Object1: lines2d.Item(1),
                    Index1: (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    Object2: lines2d.Item(2),
                    Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);

                relation2d = relations2d.AddKeypoint(
                    Object1: lines2d.Item(2),
                    Index1: (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    Object2: lines2d.Item(3),
                    Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);

                relation2d = relations2d.AddKeypoint(
                    Object1: lines2d.Item(3),
                    Index1: (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    Object2: lines2d.Item(4),
                    Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);

                relation2d = relations2d.AddKeypoint(
                    Object1: lines2d.Item(4),
                    Index1: (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd,
                    Object2: lines2d.Item(1),
                    Index2: (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);

                // Make sure profile is closed.
                status = profile.End(SolidEdgePart.ProfileValidationType.igProfileClosed);

                if (status != 0)
                {
                    throw new System.Exception("Profile not closed.");
                }

                models = partDocument.Models;

                model = models.AddFiniteExtrudedProtrusion(
                    NumberOfProfiles: profileList.Count,
                    ProfileArray: profileList.ToArray(),
                    ProfilePlaneSide: SolidEdgePart.FeaturePropertyConstants.igRight,
                    ExtrusionDistance: 0.02);

                profile.Visible = false;

                extrudedProtrusions = model.ExtrudedProtrusions;
                extrudedProtrusion  = extrudedProtrusions.Item(1);

                //edges = (SolidEdgeGeometry.Edges)extrudedProtrusion.get_Edges(
                //    SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll);

                //edgeList.Add(edges.Item(5));
                //edgeList.Add(edges.Item(8));

                faces = (SolidEdgeGeometry.Faces)
                        extrudedProtrusion.get_Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll);

                chamfers = model.Chamfers;

                SolidEdgeGeometry.Face face = (SolidEdgeGeometry.Face)faces.Item(1);
                double setbackDistance1     = 0.009;
                double setbackDistance2     = 0.001;

                edges = (SolidEdgeGeometry.Edges)face.Edges;
                edgeList.Add(edges.Item(1));

                chamfer = chamfers.AddUnequalSetback(
                    ReferenceFace: face,
                    NumberOfEdgeSets: edgeList.Count,
                    EdgeSetArray: edgeList.ToArray(),
                    SetbackDistance1: setbackDistance1,
                    SetbackDistance2: setbackDistance2);

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application        application  = null;
            SolidEdgeFramework.Documents          documents    = null;
            SolidEdgePart.PartDocument            partDocument = null;
            SolidEdgePart.RefPlanes               refPlanes    = null;
            SolidEdgePart.RefPlane                refPlane     = null;
            SolidEdgePart.ProfileSets             profileSets  = null;
            SolidEdgePart.ProfileSet              profileSet   = null;
            SolidEdgePart.Profiles                profiles     = null;
            SolidEdgePart.Profile                 profile      = null;
            SolidEdgePart.Models                  models       = null;
            SolidEdgePart.Model                   model        = null;
            SolidEdgeFrameworkSupport.Lines2d     lines2d      = null;
            SolidEdgeFrameworkSupport.Line2d      axis         = null;
            SolidEdgeFrameworkSupport.Arcs2d      arcs2d       = null;
            SolidEdgeFrameworkSupport.Relations2d relations2d  = null;
            SolidEdgePart.RefAxis                 refaxis      = null;
            Array aProfiles = null;

            SolidEdgeGeometry.Edges           edges  = null;
            SolidEdgeGeometry.Circle          circle = null;
            SolidEdgePart.RevolvedProtrusions revolvedProtrusions = null;
            SolidEdgePart.RevolvedProtrusion  revolvedProtrusion  = null;
            Array center = null;

            SolidEdgePart.Rounds rounds = 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;

                Console.WriteLine("Creating a new part document.");

                // Create a new PartDocument.
                partDocument = (SolidEdgePart.PartDocument)
                               documents.Add("SolidEdge.PartDocument");

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                Console.WriteLine("Drawing part.");

                // Get a reference to the models collection.
                models = (SolidEdgePart.Models)partDocument.Models;


                // D1 to FA are parameters in a form, introduced by the user.
                double D1 = 0.020;
                double D2 = 0.026;
                double D3 = 0.003;
                double D4 = 0.014;
                double L1 = 0.040;
                double L2 = 0.030;
                double L3 = 0.005;
                double FA = 0.0005; // round

                // Get a reference to the ref planes collection.
                refPlanes = partDocument.RefPlanes;

                // Front (xz).
                refPlane = refPlanes.Item(3);

                // Get a reference to the profile sets collection.
                profileSets = (SolidEdgePart.ProfileSets)partDocument.ProfileSets;

                // Create a new profile set.
                profileSet = profileSets.Add();

                // Get a reference to the profiles collection.
                profiles = profileSet.Profiles;

                // Create a new profile.
                profile = profiles.Add(refPlane);

                // Get a reference to the profile lines2d collection.
                lines2d = profile.Lines2d;

                // Get a reference to the profile arcs2d collection.
                arcs2d = profile.Arcs2d;

                double H = L1 - L2;
                double y = L1 - L3 - (D4 - D3) / (2 * Math.Tan((118 / 2) * (Math.PI / 180)));

                lines2d.AddBy2Points(D3 / 2, 0, D2 / 2, 0);        // Line1
                lines2d.AddBy2Points(D2 / 2, 0, D2 / 2, H);        // Line2
                lines2d.AddBy2Points(D2 / 2, H, D1 / 2, H);        // Line3
                lines2d.AddBy2Points(D1 / 2, H, D1 / 2, L1);       // Line4
                lines2d.AddBy2Points(D1 / 2, L1, D4 / 2, L1);      // Line5
                lines2d.AddBy2Points(D4 / 2, L1, D4 / 2, L1 - L3); // Line6
                lines2d.AddBy2Points(D4 / 2, L1 - L3, D3 / 2, y);  // Line7
                lines2d.AddBy2Points(D3 / 2, y, D3 / 2, 0);        // Line8

                axis = lines2d.AddBy2Points(0, 0, 0, L1);
                profile.ToggleConstruction(axis);

                // relations
                relations2d = (SolidEdgeFrameworkSupport.Relations2d)profile.Relations2d;
                relations2d.AddKeypoint(lines2d.Item(1), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(2), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(2), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(3), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(3), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(4), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(4), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(5), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(5), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(6), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(6), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(7), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(7), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(8), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);
                relations2d.AddKeypoint(lines2d.Item(8), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(1), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart, true);

                refaxis = (SolidEdgePart.RefAxis)profile.SetAxisOfRevolution(axis);

                // Close the profile.
                int status = profile.End(SolidEdgePart.ProfileValidationType.igProfileRefAxisRequired);
                profile.Visible = false;

                // Create a new array of profile objects.
                aProfiles = Array.CreateInstance(typeof(SolidEdgePart.Profile), 1);
                aProfiles.SetValue(profile, 0);

                Console.WriteLine("Creating finite revolved protrusion.");

                // add Finite Revolved Protrusion.
                model = models.AddFiniteRevolvedProtrusion(1, ref aProfiles, refaxis, SolidEdgePart.FeaturePropertyConstants.igRight, 2 * Math.PI, null, null);

                Console.WriteLine("Creating adding rounds.");

                SolidEdgeGeometry.Edge[] arrEdges = { null };
                double[] arrRadii = { FA };

                revolvedProtrusions = model.RevolvedProtrusions;
                revolvedProtrusion  = revolvedProtrusions.Item(1);
                edges = (SolidEdgeGeometry.Edges)revolvedProtrusion.Edges[SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll];

                foreach (SolidEdgeGeometry.Edge edge in edges)
                {
                    circle = (SolidEdgeGeometry.Circle)edge.Geometry;
                    if (circle.Radius == D2 / 2)
                    {
                        center = Array.CreateInstance(typeof(double), 3);
                        circle.GetCenterPoint(ref center);
                        if ((double)center.GetValue(0) == 0 && (double)center.GetValue(1) == 0 && (double)center.GetValue(2) == H)
                        {
                            arrEdges[0] = edge;
                            break;
                        }
                    }
                }

                rounds = model.Rounds;
                object optArg = Type.Missing;
                rounds.Add(1, arrEdges, arrRadii, optArg, optArg, optArg, optArg);

                Console.WriteLine("Switching to ISO view.");

                // Switch to ISO view.
                application.StartCommand((SolidEdgeFramework.SolidEdgeCommandConstants)SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                Console.WriteLine(ex.Message);
            }
        }
示例#29
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application      application  = null;
            SolidEdgeFramework.Documents        documents    = null;
            SolidEdgePart.PartDocument          partDocument = null;
            SolidEdgePart.RefPlanes             refPlanes    = null;
            SolidEdgePart.RefPlane              refPlane     = null;
            SolidEdgePart.Sketchs               sketches     = null;
            SolidEdgePart.Sketch                sketch       = null;
            SolidEdgePart.Profiles              profiles     = null;
            SolidEdgePart.Profile               profile      = null;
            SolidEdgeFrameworkSupport.Circles2d circles2d    = null;
            SolidEdgeFrameworkSupport.Circle2d  circle2d     = null;
            SolidEdgeFramework.SelectSet        selectSet    = 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 part document.
                partDocument = documents.AddPartDocument();

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                // Get a reference to the RefPlanes collection.
                refPlanes = partDocument.RefPlanes;

                // Get a reference to front RefPlane.
                refPlane = refPlanes.GetFrontPlane();

                // Get a reference to the Sketches collection.
                sketches = partDocument.Sketches;

                // Create a new sketch.
                sketch = sketches.Add();

                // Get a reference to the Profiles collection.
                profiles = sketch.Profiles;

                // Create a new profile.
                profile = profiles.Add(refPlane);

                circles2d = profile.Circles2d;

                circle2d = circles2d.AddByCenterRadius(0.04, 0.05, 0.02);

                profile.End(SolidEdgePart.ProfileValidationType.igProfileClosed);

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

                // Empty ActiveSelectSet.
                selectSet.RemoveAll();

                // Add new FaceRotate to ActiveSelectSet.
                selectSet.Add(circle2d);

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
示例#30
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application        application  = null;
            SolidEdgeFramework.Documents          documents    = null;
            SolidEdgePart.PartDocument            partDocument = null;
            SolidEdgePart.RefPlanes               refPlanes    = null;
            SolidEdgePart.RefPlane                refPlane     = null;
            SolidEdgePart.ProfileSets             profileSets  = null;
            SolidEdgePart.ProfileSet              profileSet   = null;
            SolidEdgePart.Profiles                profiles     = null;
            SolidEdgePart.Profile                 profile      = null;
            SolidEdgeFrameworkSupport.Lines2d     lines2d      = null;
            SolidEdgeFrameworkSupport.Relations2d relations2d  = null;
            SolidEdgeFramework.SelectSet          selectSet    = 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 part document.
                partDocument = documents.AddPartDocument();

                // Always a good idea to give SE a chance to breathe.
                application.DoIdle();

                // Get a reference to the RefPlanes collection.
                refPlanes = partDocument.RefPlanes;

                // Get a reference to the top RefPlane using extension method.
                refPlane = refPlanes.GetTopPlane();

                // Get a reference to the ProfileSets collection.
                profileSets = partDocument.ProfileSets;

                // Add a new ProfileSet.
                profileSet = profileSets.Add();

                // Get a reference to the Profiles collection.
                profiles = profileSet.Profiles;

                // Add a new Profile.
                profile = profiles.Add(refPlane);

                // Get a reference to the Relations2d collection.
                relations2d = (SolidEdgeFrameworkSupport.Relations2d)profile.Relations2d;

                // Get a reference to the Lines2d collection.
                lines2d = profile.Lines2d;

                int    sides = 8;
                double angle = 360 / sides;
                angle = (angle * Math.PI) / 180;

                double radius     = .05;
                double lineLength = 2 * radius * (Math.Tan(angle) / 2);

                // x1, y1, x2, y2
                double[] points = { 0.0, 0.0, 0.0, 0.0 };

                double x = 0.0;
                double y = 0.0;

                points[2] = -((Math.Cos(angle / 2) * radius) - x);
                points[3] = -((lineLength / 2) - y);

                // Draw each line.
                for (int i = 0; i < sides; i++)
                {
                    points[0] = points[2];
                    points[1] = points[3];
                    points[2] = points[0] + (Math.Sin(angle * i) * lineLength);
                    points[3] = points[1] + (Math.Cos(angle * i) * lineLength);

                    lines2d.AddBy2Points(points[0], points[1], points[2], points[3]);
                }

                // Create endpoint relationships.
                for (int i = 1; i <= lines2d.Count; i++)
                {
                    if (i == lines2d.Count)
                    {
                        relations2d.AddKeypoint(lines2d.Item(i), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(1), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);
                    }
                    else
                    {
                        relations2d.AddKeypoint(lines2d.Item(i), (int)SolidEdgeConstants.KeypointIndexConstants.igLineEnd, lines2d.Item(i + 1), (int)SolidEdgeConstants.KeypointIndexConstants.igLineStart);
                        relations2d.AddEqual(lines2d.Item(i), lines2d.Item(i + 1));
                    }
                }

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

                // Empty ActiveSelectSet.
                selectSet.RemoveAll();

                // Add all lines to ActiveSelectSet.
                for (int i = 1; i <= lines2d.Count; i++)
                {
                    selectSet.Add(lines2d.Item(i));
                }

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
示例#31
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application  = null;
            SolidEdgePart.PartDocument     partDocument = null;
            SolidEdgePart.Models           models       = null;
            SolidEdgePart.Model            model        = null;
            SolidEdgePart.Features         features     = null;
            bool bIgnoreWarnings  = true;
            bool bExtendSelection = true;

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

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

                // Get a reference to the active part document.
                partDocument = application.GetActiveDocument <SolidEdgePart.PartDocument>(false);

                if (partDocument != null)
                {
                    // Get a reference to the Models collection.
                    models = partDocument.Models;

                    // Get a reference to the 1st model.
                    model = models.Item(1);

                    // Get a reference to the Features collection.
                    features = model.Features;

                    // Iterate through the features.
                    foreach (object feature in features.OfType <object>())
                    {
                        var featureEdgeBarName  = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <string>(feature, "EdgeBarName", "Unknown");
                        var featureModelingMode = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <SolidEdgePart.ModelingModeConstants>(feature, "ModelingModeType", (SolidEdgePart.ModelingModeConstants) 0);

                        // Check to see if the feature is ordered.
                        // NOTE: I've found that not all features have a ModelingModeType property. SolidEdgePart.FaceRotate is one of them.
                        // This is a bit of a problem because I see no way to know if the FaceRotate is Ordered or Synchronous...
                        if (featureModelingMode == SolidEdgePart.ModelingModeConstants.seModelingModeOrdered)
                        {
                            int    NumberOfFeaturesCausingError   = 0;
                            Array  ErrorMessageArray              = Array.CreateInstance(typeof(string), 0);
                            int    NumberOfFeaturesCausingWarning = 0;
                            Array  WarningMessageArray            = Array.CreateInstance(typeof(string), 0);
                            double VolumeDifference = 0.0;

                            // Move the ordered feature to synchronous.
                            partDocument.MoveToSynchronous(
                                pFeatureUnk: feature,
                                bIgnoreWarnings: bIgnoreWarnings,
                                bExtendSelection: bExtendSelection,
                                NumberOfFeaturesCausingError: out NumberOfFeaturesCausingError,
                                ErrorMessageArray: out ErrorMessageArray,
                                NumberOfFeaturesCausingWarning: out NumberOfFeaturesCausingWarning,
                                WarningMessageArray: out WarningMessageArray,
                                VolumeDifference: out VolumeDifference);

                            Console.WriteLine("Feature '{0}' results:", featureEdgeBarName);
                            Console.WriteLine("VolumeDifference: '{0}'", VolumeDifference);

                            // Process error messages.
                            for (int i = 0; i < ErrorMessageArray.Length; i++)
                            {
                                Console.WriteLine("Error: '{0}'.", ErrorMessageArray.GetValue(i));
                            }

                            // Process warning messages.
                            for (int i = 0; i < WarningMessageArray.Length; i++)
                            {
                                Console.WriteLine("Warning: '{0}'.", WarningMessageArray.GetValue(i));
                            }

                            // If you get any error or warning messages, it's probably a good idea to stop.
                            if ((ErrorMessageArray.Length > 0) || (WarningMessageArray.Length > 0))
                            {
                                break;
                            }
                            else
                            {
                                Console.WriteLine("Success");
                            }
                        }
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }