| | | 1 | | using System.Collections.Generic; |
| | | 2 | | |
| | | 3 | | namespace SolidEdgeCommunity.Extensions; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// SolidEdgeDraft.Section extensions. |
| | | 7 | | /// </summary> |
| | | 8 | | public static class SectionExtensions |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Returns an enumerable collection of drawing objects. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <param name="section"></param> |
| | | 14 | | /// <returns></returns> |
| | | 15 | | public static IEnumerable<object> EnumerateDrawingObjects(this SolidEdgeDraft.Section section) |
| | | 16 | | { |
| | 14 | 17 | | foreach (var drawingObject in EnumerateDrawingObjects<object>(section)) |
| | | 18 | | { |
| | 3 | 19 | | yield return drawingObject; |
| | | 20 | | } |
| | 4 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Returns an enumerable collection of drawing objects of the specified type. |
| | | 25 | | /// </summary> |
| | | 26 | | public static IEnumerable<T> EnumerateDrawingObjects<T>(this SolidEdgeDraft.Section section) where T : class |
| | | 27 | | { |
| | 7 | 28 | | var sheets = section.Sheets; |
| | | 29 | | |
| | 34 | 30 | | for (int i = 1; i <= sheets.Count; i++) |
| | | 31 | | { |
| | 10 | 32 | | var sheet = sheets.Item(i); |
| | | 33 | | |
| | | 34 | | // The following section types are hidden and should not be used. |
| | 10 | 35 | | if (sheet.SectionType == SolidEdgeDraft.SheetSectionTypeConstants.igDrawingViewSection) continue; |
| | 9 | 36 | | if (sheet.SectionType == SolidEdgeDraft.SheetSectionTypeConstants.igBlockViewSection) continue; |
| | | 37 | | |
| | | 38 | | // Should work but throws an exception... |
| | | 39 | | //foreach (var drawingObject in sheet.DrawingObjects) |
| | | 40 | | |
| | 8 | 41 | | var drawingObjects = sheet.DrawingObjects; |
| | | 42 | | |
| | 30 | 43 | | for (int j = 1; j <= drawingObjects.Count; j++) |
| | | 44 | | { |
| | 7 | 45 | | var drawingObject = drawingObjects.Item(j); |
| | | 46 | | |
| | 7 | 47 | | if (drawingObject is T t) |
| | | 48 | | { |
| | 6 | 49 | | yield return t; |
| | | 50 | | } |
| | | 51 | | } |
| | 8 | 52 | | } |
| | 7 | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Returns an enumerable collection of drawing views. |
| | | 57 | | /// </summary> |
| | | 58 | | /// <param name="section"></param> |
| | | 59 | | /// <returns></returns> |
| | | 60 | | public static IEnumerable<SolidEdgeDraft.DrawingView> EnumerateDrawingViews(this SolidEdgeDraft.Section section) |
| | | 61 | | { |
| | 2 | 62 | | var sheets = section.Sheets; |
| | | 63 | | |
| | 8 | 64 | | for (int i = 1; i <= sheets.Count; i++) |
| | | 65 | | { |
| | 2 | 66 | | var sheet = sheets.Item(i); |
| | 2 | 67 | | var drawingViews = sheet.DrawingViews; |
| | | 68 | | |
| | 8 | 69 | | for (int j = 1; j <= drawingViews.Count; j++) |
| | | 70 | | { |
| | 2 | 71 | | yield return drawingViews.Item(j); |
| | | 72 | | } |
| | 2 | 73 | | } |
| | 2 | 74 | | } |
| | | 75 | | } |