Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts Array from GetMatrix() to double[].
        /// </summary>
        public static double[] GetMatrix(this SolidEdgeAssembly.Occurrence occurrence)
        {
            Array matrix = Array.CreateInstance(typeof(double), 0);

            occurrence.GetMatrix(ref matrix);
            return(matrix.OfType <double>().ToArray());
        }
        static void AddWithTransform(SolidEdgeAssembly.Occurrences occurrences)
        {
            SolidEdgeAssembly.Occurrence occurrence = null;

            // Get path to Solid Edge program directory.  Typically, 'C:\Program Files\Solid Edge XXX\Program'.
            DirectoryInfo programDirectory = new DirectoryInfo(GetSolidEdgeInstallPath());

            // Get path to Solid Edge training directory.  Typically, 'C:\Program Files\Solid Edge XXX\Training'.
            DirectoryInfo trainingDirectory = new DirectoryInfo(Path.Combine(programDirectory.FullName, "Training"));

            string[] filenames =
            {
                "strainer.asm",
                "handle.par",
            };

            // {OriginX, OriginY, OriginZ, AngleX, AngleY, AngleZ}
            // Origin in meters.
            // Angle in radians.
            double[,] transforms = new double[, ]
            {
                { 0, 0, 0.02062, 0, 0, 0 },                 // strainer.asm
                { -0.06943, -0.00996, 0.05697, 0, 0, 0 },   // handle.par
            };

            // Add each occurrence in array.
            for (int i = 0; i <= transforms.GetUpperBound(0); i++)
            {
                FileInfo fileInfo = new FileInfo(Path.Combine(trainingDirectory.FullName, filenames[i]));

                if (fileInfo.Exists)
                {
                    // Add the new occurrence using a transform.
                    occurrence = occurrences.AddWithTransform(
                        OccurrenceFileName: fileInfo.FullName,
                        OriginX: transforms[i, 0],
                        OriginY: transforms[i, 1],
                        OriginZ: transforms[i, 2],
                        AngleX: transforms[i, 3],
                        AngleY: transforms[i, 4],
                        AngleZ: transforms[i, 5]);

                    Console.WriteLine("Added '{0}' using AddWithTransform().", fileInfo.FullName);
                }
                else
                {
                    throw new FileNotFoundException("File not found.", fileInfo.FullName);
                }
            }
        }
        static void AddWithMatrix(SolidEdgeAssembly.Occurrences occurrences)
        {
            SolidEdgeAssembly.Occurrence occurrence = null;

            // Get path to Solid Edge program directory.  Typically, 'C:\Program Files\Solid Edge XXX\Program'.
            DirectoryInfo programDirectory = new DirectoryInfo(GetSolidEdgeInstallPath());

            // Get path to Solid Edge training directory.  Typically, 'C:\Program Files\Solid Edge XXX\Training'.
            DirectoryInfo trainingDirectory = new DirectoryInfo(Path.Combine(programDirectory.FullName, "Training"));

            FileInfo fileInfo = new FileInfo(Path.Combine(trainingDirectory.FullName, "Strap Handle.par"));

            // A single-dimension array that defines a valid transformation matrix.
            double[] m =
            {
                1.0,
                0.0,
                0.0,
                0.0,
                0.0,
                1.0,
                0.0,
                0.0,
                0.0,
                0.0,
                1.0,
                0.0,
                0.0,
                0.0,
                0.07913,
                1.0
            };

            // Convert from double[] to System.Array.
            Array matrix = m;

            if (fileInfo.Exists)
            {
                // Add the new occurrence using a matrix.
                occurrence = occurrences.AddWithMatrix(
                    OccurrenceFileName: fileInfo.FullName,
                    Matrix: ref matrix);

                Console.WriteLine("Added '{0}' using AddWithMatrix().", fileInfo.FullName);
            }
            else
            {
                throw new FileNotFoundException("File not found.", fileInfo.FullName);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns a strongly typed occurrence document.
        /// </summary>
        /// <typeparam name="T">The type to return.</typeparam>
        public static T GetOccurrenceDocument <T>(this SolidEdgeAssembly.Occurrence occurrence, bool throwOnError) where T : class
        {
            try
            {
                return((T)occurrence.OccurrenceDocument);
            }
            catch
            {
                if (throwOnError)
                {
                    throw;
                }
            }

            return(null);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application     application      = null;
            SolidEdgeFramework.Documents       documents        = null;
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;
            SolidEdgeAssembly.Occurrences      occurrences      = null;
            SolidEdgeAssembly.Occurrence       occurrence       = 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 assembly document.
                assemblyDocument = documents.AddAssemblyDocument();

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

                // Get a reference to the Occurrences collection.
                occurrences = assemblyDocument.Occurrences;

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

                // Add the base feature at 0 (X), 0 (Y), 0 (Z).
                occurrence = occurrences.AddByFilename(filename);

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.AssemblyCommandConstants.AssemblyViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Exemplo n.º 7
0
        public BomItem(SolidEdgeAssembly.Occurrence occurrence, int level)
        {
            Level         = level;
            FileName      = System.IO.Path.GetFullPath(occurrence.OccurrenceFileName);
            IsMissing     = occurrence.FileMissing();
            Quantity      = occurrence.Quantity;
            IsSubassembly = occurrence.Subassembly;

            // If the file exists, extract file properties.
            if (IsMissing == false)
            {
                var document    = (SolidEdgeFramework.SolidEdgeDocument)occurrence.OccurrenceDocument;
                var summaryInfo = (SolidEdgeFramework.SummaryInfo)document.SummaryInfo;

                DocumentNumber = summaryInfo.DocumentNumber;
                Title          = summaryInfo.Title;
                Revision       = summaryInfo.RevisionNumber;
            }
        }
        static void AddOccurrenceByFilename(SolidEdgeAssembly.Occurrences occurrences)
        {
            SolidEdgeAssembly.Occurrence occurrence = null;

            // Get path to Solid Edge program directory.  Typically, 'C:\Program Files\Solid Edge XXX\Program'.
            DirectoryInfo programDirectory = new DirectoryInfo(GetSolidEdgeInstallPath());

            // Get path to Solid Edge training directory.  Typically, 'C:\Program Files\Solid Edge XXX\Training'.
            DirectoryInfo trainingDirectory = new DirectoryInfo(Path.Combine(programDirectory.FullName, "Training"));

            FileInfo fileInfo = new FileInfo(Path.Combine(trainingDirectory.FullName, "Coffee Pot.par"));

            if (fileInfo.Exists)
            {
                // Add the base feature at 0 (X), 0 (Y), 0 (Z).
                occurrence = occurrences.AddByFilename(fileInfo.FullName);

                Console.WriteLine("Added '{0}' using AddByFilename().", fileInfo.FullName);
            }
            else
            {
                throw new FileNotFoundException("File not found.", fileInfo.FullName);
            }
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application     application      = null;
            SolidEdgeFramework.Documents       documents        = null;
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;
            SolidEdgeAssembly.Occurrences      occurrences      = null;
            SolidEdgeAssembly.Occurrence       occurrence       = null;
            string[] filenames = { "strainer.asm", "handle.par" };

            // Jagged array
            // {OriginX, OriginY, OriginZ, AngleX, AngleY, AngleZ}
            // Origin in meters.
            // Angle in radians.
            double[][] transforms = new double[][]
            {
                new double[] { 0, 0, 0.02062, 0, 0, 0 },
                new double[] { -0.06943, -0.00996, 0.05697, 0, 0, 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 documents collection.
                documents = application.Documents;

                // Create a new assembly document.
                assemblyDocument = documents.AddAssemblyDocument();

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

                // Get a reference to the Occurrences collection.
                occurrences = assemblyDocument.Occurrences;

                // Get path to Solid Edge training directory.  Typically, 'C:\Program Files\Solid Edge XXX\Training'.
                DirectoryInfo trainingDirectory = new DirectoryInfo(SolidEdgeCommunity.SolidEdgeUtils.GetTrainingFolderPath());

                // Add each occurrence in array.
                for (int i = 0; i < transforms.Length; i++)
                {
                    // Build path to file.
                    string filename = Path.Combine(trainingDirectory.FullName, filenames[i]);

                    // Add the new occurrence using a transform.
                    occurrence = occurrences.AddWithTransform(
                        OccurrenceFileName: filename,
                        OriginX: transforms[i][0],
                        OriginY: transforms[i][1],
                        OriginZ: transforms[i][2],
                        AngleX: transforms[i][3],
                        AngleY: transforms[i][4],
                        AngleZ: transforms[i][5]);
                }

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.AssemblyCommandConstants.AssemblyViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Returns a strongly typed occurrence document.
 /// </summary>
 /// <typeparam name="T">The type to return.</typeparam>
 public static T GetOccurrenceDocument <T>(this SolidEdgeAssembly.Occurrence occurrence) where T : class
 {
     return(occurrence.GetOccurrenceDocument <T>(true));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Returns the version of Solid Edge that was used to create the referenced document.
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 public static SolidEdgeFramework.SolidEdgeDocument GetOccurrenceDocument(this SolidEdgeAssembly.Occurrence occurrence)
 {
     return(occurrence as SolidEdgeFramework.SolidEdgeDocument);
 }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application     application      = null;
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;
            SolidEdgeAssembly.Relations3d      relations3d      = null;
            SolidEdgeAssembly.GroundRelation3d groundRelation3d = null;
            SolidEdgeAssembly.AxialRelation3d  axialRelation3d  = null;
            SolidEdgeAssembly.PlanarRelation3d planarRelation3d = null;
            SolidEdgeAssembly.Occurrence       occurrence1      = null;
            SolidEdgeAssembly.Occurrence       occurrence2      = null;
            SolidEdgeAssembly.Relation3dDetailedStatusConstants detailedStatus;
            SolidEdgeAssembly.Relation3dStatusConstants         status;

            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.
                assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                // Get a reference to the Relations3d collection.
                relations3d = assemblyDocument.Relations3d;

                foreach (var relation3d in relations3d.OfType <object>())
                {
                    try
                    {
                        // Not used in this sample but a good example of how to get the runtime type.
                        var relationType = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetType(relation3d);

                        // Use helper class to get the object type.
                        var relationObjectType = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <SolidEdgeFramework.ObjectType>(relation3d, "Type", (SolidEdgeFramework.ObjectType) 0);

                        // Reset statuses.
                        detailedStatus = (SolidEdgeAssembly.Relation3dDetailedStatusConstants) 0;
                        status         = (SolidEdgeAssembly.Relation3dStatusConstants) 0;

                        // Handle specific object type. There are other possible relation types...
                        switch (relationObjectType)
                        {
                        case SolidEdgeFramework.ObjectType.igGroundRelation3d:
                            // Cast relation3d object to GroundRelation3d type.
                            groundRelation3d = (SolidEdgeAssembly.GroundRelation3d)relation3d;

                            // Get a reference to the grounded occurrence.
                            occurrence1 = groundRelation3d.Occurrence;

                            // Get the detailed status.
                            detailedStatus = groundRelation3d.DetailedStatus;

                            // Get the status.
                            status = groundRelation3d.Status;

                            break;

                        case SolidEdgeFramework.ObjectType.igAxialRelation3d:
                            // Cast relation3d object to AxialRelation3d type.
                            axialRelation3d = (SolidEdgeAssembly.AxialRelation3d)relation3d;

                            // Get a reference to the related occurrences.
                            occurrence1 = axialRelation3d.Occurrence1;
                            occurrence2 = axialRelation3d.Occurrence2;

                            // Get the detailed status.
                            detailedStatus = axialRelation3d.DetailedStatus;

                            // Get the status.
                            status = axialRelation3d.Status;

                            break;

                        case SolidEdgeFramework.ObjectType.igPlanarRelation3d:
                            // Cast relation3d object to PlanarRelation3d type.
                            planarRelation3d = (SolidEdgeAssembly.PlanarRelation3d)relation3d;

                            // Get a reference to the related occurrences.
                            occurrence1 = planarRelation3d.Occurrence1;
                            occurrence2 = planarRelation3d.Occurrence2;

                            // Get the detailed status.
                            detailedStatus = planarRelation3d.DetailedStatus;

                            // Get the status.
                            status = planarRelation3d.Status;
                            break;

                        default:
                            break;
                        }

                        // Analyze the detailed status.
                        switch (detailedStatus)
                        {
                        case SolidEdgeAssembly.Relation3dDetailedStatusConstants.igRelation3dDetailedStatusBetweenFixed:
                            break;

                        case SolidEdgeAssembly.Relation3dDetailedStatusConstants.igRelation3dDetailedStatusBetweenSetMembers:
                            break;

                        case SolidEdgeAssembly.Relation3dDetailedStatusConstants.igRelation3dDetailedStatusMissingGeometry:
                            break;

                        case SolidEdgeAssembly.Relation3dDetailedStatusConstants.igRelation3dDetailedStatusSolved:
                            break;

                        case SolidEdgeAssembly.Relation3dDetailedStatusConstants.igRelation3dDetailedStatusSuppressed:
                            break;

                        case SolidEdgeAssembly.Relation3dDetailedStatusConstants.igRelation3dDetailedStatusUnknown:
                            break;

                        case SolidEdgeAssembly.Relation3dDetailedStatusConstants.igRelation3dDetailedStatusUnsatisfied:
                            break;
                        }

                        // Analyze the status.
                        switch (status)
                        {
                        case SolidEdgeAssembly.Relation3dStatusConstants.igRelation3dStatusSolved:
                            break;

                        case SolidEdgeAssembly.Relation3dStatusConstants.igRelation3dStatusUnsolved:
                            break;
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
        static void ReportOccurrences(SolidEdgeAssembly.Occurrences occurrences)
        {
            SolidEdgeAssembly.Occurrence occurrence = null;

            Console.WriteLine();

            for (int i = 1; i <= occurrences.Count; i++)
            {
                occurrence = occurrences.Item(i);

                // Allocate a new array to hold transform.
                double[] transform = new double[6];

                // Allocate a new array to hold matrix.
                Array matrix = Array.CreateInstance(typeof(double), 16);

                // Get the occurrence transform.
                occurrence.GetTransform(
                    OriginX: out transform[0],
                    OriginY: out transform[1],
                    OriginZ: out transform[2],
                    AngleX: out transform[3],
                    AngleY: out transform[4],
                    AngleZ: out transform[5]);

                // Get the occurrence matrix.
                occurrence.GetMatrix(ref matrix);

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

                // Report the occurrence transform.
                Console.WriteLine("{0} transform:", occurrence.Name);
                Console.WriteLine("OriginX: {0} (meters)", transform[0]);
                Console.WriteLine("OriginY: {0} (meters)", transform[1]);
                Console.WriteLine("OriginZ: {0} (meters)", transform[2]);
                Console.WriteLine("AngleX: {0} (radians)", transform[3]);
                Console.WriteLine("AngleY: {0} (radians)", transform[4]);
                Console.WriteLine("AngleZ: {0} (radians)", transform[5]);
                Console.WriteLine();

                // Report the occurrence matrix.
                Console.WriteLine("{0} matrix:", occurrence.Name);
                Console.WriteLine("|{0}, {1}, {2}, {3}|",
                                  m[0],
                                  m[1],
                                  m[2],
                                  m[3]);
                Console.WriteLine("|{0}, {1}, {2}, {3}|",
                                  m[4],
                                  m[5],
                                  m[6],
                                  m[7]);
                Console.WriteLine("|{0}, {1}, {2}, {3}|",
                                  m[8],
                                  m[9],
                                  m[10],
                                  m[11]);
                Console.WriteLine("|{0}, {1}, {2}, {3}|",
                                  m[12],
                                  m[13],
                                  m[14],
                                  m[15]);

                Console.WriteLine();
            }
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;
            SolidEdgeFramework.Documents documents = null;
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;
            SolidEdgeAssembly.Occurrences occurrences = null;
            SolidEdgeAssembly.Occurrence occurrence = null;

            // A single-dimension array that defines a valid transformation matrix. 
            double[] matrix = 
                {
                    1.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    1.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    1.0,
                    0.0,
                    0.0,
                    0.0,
                    0.07913,
                    1.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 documents collection.
                documents = application.Documents;

                // Create a new assembly document.
                assemblyDocument = documents.AddAssemblyDocument();

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

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

                // Get a reference to the Occurrences collection.
                occurrences = assemblyDocument.Occurrences;

                // Convert from double[] to System.Array.
                Array matrixArray = matrix;

                // Add the new occurrence using a matrix.
                occurrence = occurrences.AddWithMatrix(
                    OccurrenceFileName: filename,
                    Matrix: ref matrixArray);

                // Switch to ISO view.
                application.StartCommand(SolidEdgeConstants.AssemblyCommandConstants.AssemblyViewISOView);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application                     application      = null;
            SolidEdgeAssembly.AssemblyDocument                 assemblyDocument = null;
            SolidEdgeAssembly.Occurrences                      occurrences      = null;
            SolidEdgeAssembly.InterferenceStatusConstants      interferenceStatus;
            SolidEdgeConstants.InterferenceComparisonConstants compare    = SolidEdgeConstants.InterferenceComparisonConstants.seInterferenceComparisonSet1vsAllOther;
            SolidEdgeConstants.InterferenceReportConstants     reportType = SolidEdgeConstants.InterferenceReportConstants.seInterferenceReportPartNames;

            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 assembly document.
                assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                if (assemblyDocument != null)
                {
                    // Get a reference to the Occurrences collection.
                    occurrences = assemblyDocument.Occurrences;

                    foreach (var occurrence in occurrences.OfType <SolidEdgeAssembly.Occurrence>())
                    {
                        Array  set1                   = Array.CreateInstance(occurrence.GetType(), 1);
                        object numInterferences       = 0;
                        object retSet1                = Array.CreateInstance(typeof(SolidEdgeAssembly.Occurrence), 0);
                        object retSet2                = Array.CreateInstance(typeof(SolidEdgeAssembly.Occurrence), 0);
                        object confirmedInterference  = null;
                        object interferenceOccurrence = null;

                        set1.SetValue(occurrence, 0);

                        // Check interference.
                        assemblyDocument.CheckInterference(
                            NumElementsSet1: set1.Length,
                            Set1: ref set1,
                            Status: out interferenceStatus,
                            ComparisonMethod: compare,
                            NumElementsSet2: 0,
                            Set2: Missing.Value,
                            AddInterferenceAsOccurrence: false,
                            ReportFilename: Missing.Value,
                            ReportType: reportType,
                            NumInterferences: out numInterferences,
                            InterferingPartsSet1: ref retSet1,
                            InterferingPartsOtherSet: ref retSet2,
                            ConfirmedInterference: ref confirmedInterference,
                            InterferenceOccurrence: out interferenceOccurrence,
                            IgnoreThreadInterferences: Missing.Value
                            );

                        // Process status.
                        switch (interferenceStatus)
                        {
                        case SolidEdgeAssembly.InterferenceStatusConstants.seInterferenceStatusNoInterference:
                            break;

                        case SolidEdgeAssembly.InterferenceStatusConstants.seInterferenceStatusConfirmedAndProbableInterference:
                        case SolidEdgeAssembly.InterferenceStatusConstants.seInterferenceStatusConfirmedInterference:
                        case SolidEdgeAssembly.InterferenceStatusConstants.seInterferenceStatusIncompleteAnalysis:
                        case SolidEdgeAssembly.InterferenceStatusConstants.seInterferenceStatusProbableInterference:
                            if (retSet2 != null)
                            {
                                for (int j = 0; j < (int)numInterferences; j++)
                                {
                                    object obj1 = ((Array)retSet1).GetValue(j);
                                    object obj2 = ((Array)retSet2).GetValue(j);

                                    // Use helper class to get the object type.
                                    var objectType1 = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <SolidEdgeFramework.ObjectType>(obj1, "Type", (SolidEdgeFramework.ObjectType) 0);
                                    var objectType2 = SolidEdgeCommunity.Runtime.InteropServices.ComObject.GetPropertyValue <SolidEdgeFramework.ObjectType>(obj2, "Type", (SolidEdgeFramework.ObjectType) 0);

                                    SolidEdgeFramework.Reference reference1  = null;
                                    SolidEdgeFramework.Reference reference2  = null;
                                    SolidEdgeAssembly.Occurrence occurrence1 = null;
                                    SolidEdgeAssembly.Occurrence occurrence2 = null;

                                    switch (objectType1)
                                    {
                                    case SolidEdgeFramework.ObjectType.igReference:
                                        reference1 = (SolidEdgeFramework.Reference)obj1;
                                        break;

                                    case SolidEdgeFramework.ObjectType.igPart:
                                    case SolidEdgeFramework.ObjectType.igOccurrence:
                                        occurrence1 = (SolidEdgeAssembly.Occurrence)obj1;
                                        break;
                                    }

                                    switch (objectType2)
                                    {
                                    case SolidEdgeFramework.ObjectType.igReference:
                                        reference2 = (SolidEdgeFramework.Reference)obj2;
                                        break;

                                    case SolidEdgeFramework.ObjectType.igPart:
                                    case SolidEdgeFramework.ObjectType.igOccurrence:
                                        occurrence2 = (SolidEdgeAssembly.Occurrence)obj2;
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                else
                {
                    throw new System.Exception("No active document.");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Exemplo n.º 16
0
 static void ReportItem(SolidEdgeAssembly.Occurrence occurrence)
 {
     Console.WriteLine("Name: {0}", occurrence.Name);
     Console.WriteLine("OccurrenceFileName: {0}", occurrence.OccurrenceFileName);
 }
Exemplo n.º 17
0
 public DocumentItem(SolidEdgeAssembly.Occurrence occurrence)
     : this()
 {
     FileName = occurrence.OccurrenceFileName;
 }
        private void OkButton_Click(object sender, EventArgs e)
        {
            Log.Debug("assemblyDocument: " + this.Document.Name + " path: " + this.Document.Path);
            if (string.IsNullOrEmpty(this.Document.Path))
            {
                MessageBox.Show("You must save the current assembly before adding parts");
            }
            else
            {
                SolidEdgePart.PartDocument partDocument = (SolidEdgePart.PartDocument) this.Document.Application.Documents.Open(this._filePath, 0x00000008);//, "8");
                this.Document.Application.DoIdle();
                Log.Debug("partDocument: " + partDocument.Name);
                // Get file properties of the partDocument
                SolidEdgeFramework.Properties objProperties = ((SolidEdgeFramework.PropertySets)partDocument.Properties).Item("Custom");
                // Handles naming convention when it is not followed
                int length = partDocument.Name.IndexOf(".par");
                if (length <= 0)
                {
                    Log.Warn("selected file is not a Part Document");
                    length = partDocument.Name.Length;
                }
                string   fileName            = partDocument.Name.Substring(0, length);
                string[] variableValuesArray = new string[this._settings.getNumberOfVariables()];
                foreach (PartProperty partProperty in this.partPropertyBindingSource)
                {
                    if (this._settings.isVariableDefined(partProperty.Name))
                    {
                        // 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(partProperty.Name, SolidEdgeConstants.VariableNameBy.seVariableNameByBoth, SolidEdgeConstants.VariableVarType.SeVariableVarTypeBoth, false);
                        foreach (var property in variableList)
                        {
                            try {
                                Type type = property.GetType();
                                SolidEdgeFramework.ObjectType objectType = (SolidEdgeFramework.ObjectType)type.InvokeMember("Type", System.Reflection.BindingFlags.GetProperty, null, property, null);
                                switch (objectType)
                                {
                                case SolidEdgeFramework.ObjectType.igDimension:
                                    SolidEdgeFrameworkSupport.Dimension dimension = (SolidEdgeFrameworkSupport.Dimension)property;
                                    dimension.Value = partProperty.GetSolidEdgeStoredValue(partDocument.UnitsOfMeasure);
                                    Marshal.FinalReleaseComObject(dimension);
                                    break;

                                case SolidEdgeFramework.ObjectType.igVariable:
                                    SolidEdgeFramework.variable variable = (SolidEdgeFramework.variable)property;
                                    variable.Value = partProperty.GetSolidEdgeStoredValue(partDocument.UnitsOfMeasure);
                                    Marshal.FinalReleaseComObject(variable);
                                    break;
                                }
                                Log.Debug(this._settings.getVariableIndex(partProperty.Name) + " >= " + variableValuesArray.Length);
                                if (this._settings.getVariableIndex(partProperty.Name) >= variableValuesArray.Length)
                                {
                                    Array.Resize <string>(ref variableValuesArray, this._settings.getVariableIndex(partProperty.Name) + 1);
                                }
                                variableValuesArray[this._settings.getVariableIndex(partProperty.Name)] = partProperty.Value + " " + partProperty.Units;
                                // Update file property
                                try {
                                    // TODO: Fix exception when partProperty.Name is not defined in objProperties.Item
                                    SolidEdgeFramework.Property objProperty = objProperties.Item(partProperty.Name);
                                    objProperty.set_Value(partProperty.Value.ToString());
                                    Marshal.FinalReleaseComObject(objProperty);
                                } catch (Exception ex) {
                                    Log.Warn("no file property exists for " + partProperty.Name + " | " + ex.Message);
                                }
                            } catch (Exception ex) {
                                Log.Error(ex.Message);
                            }
                        }
                        Marshal.FinalReleaseComObject(variables);
                        Marshal.FinalReleaseComObject(variableList);
                    }
                }
                objProperties.Save();
                Marshal.FinalReleaseComObject(objProperties);
                // Remove invalid fileName characters
                fileName            = string.Join("", fileName.Split(Path.GetInvalidFileNameChars()));
                variableValuesArray = variableValuesArray.Where(c => c != null).ToArray();
                fileName           += "-" + string.Join(this._settings.getFileNameSeparator(), variableValuesArray);
                Log.Debug("fileName: " + fileName);
                string fullPathName           = this.Document.Path;
                string assemblyPartFolderName = _settings.getAssemblyPartFolderName();
                if (assemblyPartFolderName != null & assemblyPartFolderName != "")
                {
                    assemblyPartFolderName = string.Join("", assemblyPartFolderName.Split(Path.GetInvalidFileNameChars()));
                    fullPathName          += "\\" + assemblyPartFolderName;
                    Directory.CreateDirectory(fullPathName);
                }
                fullPathName += "\\" + fileName + ".par";
                Log.Debug("fullPathName: " + fullPathName);

                if (!File.Exists(fullPathName))
                {
                    partDocument.SaveCopyAs(fullPathName);
                }

                this.Document.Application.DoIdle();
                partDocument.Close(false);
                this.Document.Application.DoIdle();
                Marshal.FinalReleaseComObject(partDocument);
                this.HideConfigurationContainer();
                int count = ((SolidEdgeAssembly.AssemblyDocument) this.Document).Occurrences.Count;
                if (count > 0)
                {
                    SolidEdgeAssembly.Occurrence occurrence = ((SolidEdgeAssembly.AssemblyDocument) this.Document).Occurrences.Item(count);
                    occurrence.GetTransform(out double OriginX, out double OriginY, out double OriginZ, out double AngleX, out double AngleY, out double AngleZ);
                    Marshal.ReleaseComObject(occurrence);
                    double offset = 0.05;
                    occurrence = ((SolidEdgeAssembly.AssemblyDocument) this.Document).Occurrences.AddWithTransform(fullPathName, OriginX + offset, OriginY + offset, OriginZ + offset, AngleX, AngleY, AngleZ);
                    // delete grounded relationship from occurrence.Relations3d
                    SolidEdgeAssembly.Relations3d relation3d = (SolidEdgeAssembly.Relations3d)occurrence.Relations3d;
                    foreach (var relation in relation3d)
                    {
                        Type type = relation.GetType();
                        // Get the value of the Type proprety via Reflection
                        SolidEdgeFramework.ObjectType objectType = (SolidEdgeFramework.ObjectType)type.InvokeMember("Type", BindingFlags.GetProperty, null, relation, null);
                        // Determine the relation type
                        switch (objectType)
                        {
                        case SolidEdgeFramework.ObjectType.igGroundRelation3d:
                            SolidEdgeAssembly.GroundRelation3d groundRelation3d = (SolidEdgeAssembly.GroundRelation3d)relation;
                            groundRelation3d.Delete();
                            break;
                        }
                    }
                    Marshal.FinalReleaseComObject(relation3d);
                    Marshal.FinalReleaseComObject(occurrence);
                }
                else
                {
                    ((SolidEdgeAssembly.AssemblyDocument) this.Document).Occurrences.AddWithTransform(fullPathName, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
                }
            }
        }