| | | 1 | | using System; |
| | | 2 | | using System.Linq; |
| | | 3 | | |
| | | 4 | | namespace SolidEdgeCommunity.Extensions; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// SolidEdgePart.WeldmentDocument extension methods. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class OccurrenceExtensions |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Returns the version of Solid Edge that was used to create the referenced document. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="occurrence"></param> |
| | | 15 | | public static SolidEdgeDocument GetOccurrenceDocument(this SolidEdgeAssembly.Occurrence occurrence) |
| | 1 | 16 | | => occurrence as SolidEdgeDocument; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Returns a strongly typed occurrence document. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <typeparam name="T">The type to return.</typeparam> |
| | 2 | 22 | | public static T GetOccurrenceDocument<T>(this SolidEdgeAssembly.Occurrence occurrence) where T : class => occurrence |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Returns a strongly typed occurrence document. |
| | | 26 | | /// </summary> |
| | | 27 | | /// <typeparam name="T">The type to return.</typeparam> |
| | | 28 | | public static T GetOccurrenceDocument<T>(this SolidEdgeAssembly.Occurrence occurrence, bool throwOnError) where T : |
| | | 29 | | { |
| | | 30 | | try |
| | | 31 | | { |
| | 3 | 32 | | return (T)occurrence.OccurrenceDocument; |
| | | 33 | | } |
| | 1 | 34 | | catch when (!throwOnError) |
| | | 35 | | { |
| | 1 | 36 | | } |
| | | 37 | | |
| | 1 | 38 | | return null; |
| | 2 | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Converts Array from GetBodyInversionMatrix() to double[]. |
| | | 43 | | /// </summary> |
| | | 44 | | public static double[] GetBodyInversionMatrix(this SolidEdgeAssembly.Occurrence occurrence) |
| | | 45 | | { |
| | 2 | 46 | | Array matrix = Array.CreateInstance(typeof(double), 0); |
| | 2 | 47 | | occurrence.GetBodyInversionMatrix(ref matrix); |
| | 2 | 48 | | return [.. matrix.OfType<double>()]; |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Converts Array from GetExplodeMatrix() to double[]. |
| | | 53 | | /// </summary> |
| | | 54 | | public static double[] GetExplodeMatrix(this SolidEdgeAssembly.Occurrence occurrence) |
| | | 55 | | { |
| | 1 | 56 | | Array matrix = Array.CreateInstance(typeof(double), 0); |
| | 1 | 57 | | occurrence.GetExplodeMatrix(ref matrix); |
| | 1 | 58 | | return [.. matrix.OfType<double>()]; |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | /// <summary> |
| | | 62 | | /// Converts Array from GetMatrix() to double[]. |
| | | 63 | | /// </summary> |
| | | 64 | | public static double[] GetMatrix(this SolidEdgeAssembly.Occurrence occurrence) |
| | | 65 | | { |
| | 2 | 66 | | Array matrix = Array.CreateInstance(typeof(double), 0); |
| | 2 | 67 | | occurrence.GetMatrix(ref matrix); |
| | 2 | 68 | | return [.. matrix.OfType<double>()]; |
| | | 69 | | } |
| | | 70 | | } |