| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | |
| | | 4 | | namespace SolidEdgeCommunity.Extensions; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// SolidEdgeDraft.DraftDocument extensions. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class DraftDocumentExtensions |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Returns an enumerable collection of drawing objects. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="document"></param> |
| | | 15 | | /// <returns></returns> |
| | | 16 | | public static IEnumerable<object> EnumerateDrawingObjects(this SolidEdgeDraft.DraftDocument document) |
| | | 17 | | { |
| | 1 | 18 | | var sections = document.Sections; |
| | | 19 | | |
| | 4 | 20 | | for (int i = 1; i <= sections.Count; i++) |
| | | 21 | | { |
| | 1 | 22 | | var section = sections.Item(i); |
| | 4 | 23 | | foreach (var drawingObject in section.EnumerateDrawingObjects()) |
| | | 24 | | { |
| | 1 | 25 | | yield return drawingObject; |
| | | 26 | | } |
| | | 27 | | } |
| | 1 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Returns an enumerable collection of drawing objects of the specified type. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <param name="document"></param> |
| | | 34 | | /// <returns></returns> |
| | | 35 | | public static IEnumerable<T> EnumerateDrawingObjects<T>(this SolidEdgeDraft.DraftDocument document) where T : class |
| | | 36 | | { |
| | 1 | 37 | | var sections = document.Sections; |
| | | 38 | | |
| | 4 | 39 | | for (int i = 1; i <= sections.Count; i++) |
| | | 40 | | { |
| | 1 | 41 | | var section = sections.Item(i); |
| | 4 | 42 | | foreach (var drawingObject in section.EnumerateDrawingObjects<T>()) |
| | | 43 | | { |
| | 1 | 44 | | yield return drawingObject; |
| | | 45 | | } |
| | | 46 | | } |
| | 1 | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Returns an enumerable collection of drawing objects in the specified section. |
| | | 51 | | /// </summary> |
| | | 52 | | /// <param name="document"></param> |
| | | 53 | | /// <param name="sectionType"></param> |
| | | 54 | | /// <returns></returns> |
| | | 55 | | public static IEnumerable<object> EnumerateDrawingObjects(this SolidEdgeDraft.DraftDocument document, SolidEdgeDraft |
| | | 56 | | { |
| | 1 | 57 | | var sections = document.Sections; |
| | | 58 | | |
| | 4 | 59 | | for (int i = 1; i <= sections.Count; i++) |
| | | 60 | | { |
| | 1 | 61 | | var section = sections.Item(i); |
| | | 62 | | |
| | 1 | 63 | | if (section.Type == sectionType) |
| | | 64 | | { |
| | 4 | 65 | | foreach (var drawingObject in section.EnumerateDrawingObjects()) |
| | | 66 | | { |
| | 1 | 67 | | yield return drawingObject; |
| | | 68 | | } |
| | | 69 | | } |
| | | 70 | | } |
| | 1 | 71 | | } |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Returns an enumerable collection of drawing objects of the specified type in the specified section. |
| | | 75 | | /// </summary> |
| | | 76 | | /// <param name="document"></param> |
| | | 77 | | /// <param name="sectionType"></param> |
| | | 78 | | /// <returns></returns> |
| | | 79 | | public static IEnumerable<object> EnumerateDrawingObjects<T>(this SolidEdgeDraft.DraftDocument document, SolidEdgeDr |
| | | 80 | | { |
| | 1 | 81 | | var sections = document.Sections; |
| | | 82 | | |
| | 4 | 83 | | for (int i = 1; i <= sections.Count; i++) |
| | | 84 | | { |
| | 1 | 85 | | var section = sections.Item(i); |
| | | 86 | | |
| | 1 | 87 | | if (section.Type == sectionType) |
| | | 88 | | { |
| | 4 | 89 | | foreach (var drawingObject in section.EnumerateDrawingObjects<T>()) |
| | | 90 | | { |
| | 1 | 91 | | yield return drawingObject; |
| | | 92 | | } |
| | | 93 | | } |
| | | 94 | | } |
| | 1 | 95 | | } |
| | | 96 | | |
| | | 97 | | /// <summary> |
| | | 98 | | /// Returns an enumerable collection of drawing views. |
| | | 99 | | /// </summary> |
| | | 100 | | /// <param name="document"></param> |
| | | 101 | | /// <returns></returns> |
| | | 102 | | public static IEnumerable<SolidEdgeDraft.DrawingView> EnumerateDrawingViews(this SolidEdgeDraft.DraftDocument docume |
| | | 103 | | { |
| | 1 | 104 | | var sheets = document.Sheets; |
| | | 105 | | |
| | 4 | 106 | | for (int i = 1; i <= sheets.Count; i++) |
| | | 107 | | { |
| | 1 | 108 | | var sheet = sheets.Item(i); |
| | 1 | 109 | | var drawingViews = sheet.DrawingViews; |
| | | 110 | | |
| | 4 | 111 | | for (int j = 1; j <= drawingViews.Count; j++) |
| | | 112 | | { |
| | 1 | 113 | | yield return drawingViews.Item(j); |
| | | 114 | | } |
| | 1 | 115 | | } |
| | 1 | 116 | | } |
| | | 117 | | |
| | | 118 | | /// <summary> |
| | | 119 | | /// Returns an enumerable collection of drawing views in the specified section. |
| | | 120 | | /// </summary> |
| | | 121 | | /// <param name="document"></param> |
| | | 122 | | /// <param name="sectionType"></param> |
| | | 123 | | /// <returns></returns> |
| | | 124 | | public static IEnumerable<SolidEdgeDraft.DrawingView> EnumerateDrawingViews(this SolidEdgeDraft.DraftDocument docume |
| | | 125 | | { |
| | 1 | 126 | | var sections = document.Sections; |
| | | 127 | | |
| | 4 | 128 | | for (int i = 1; i <= sections.Count; i++) |
| | | 129 | | { |
| | 1 | 130 | | var section = sections.Item(i); |
| | | 131 | | |
| | 1 | 132 | | if (section.Type == sectionType) |
| | | 133 | | { |
| | 4 | 134 | | foreach (SolidEdgeDraft.DrawingView drawingView in section.EnumerateDrawingViews()) |
| | | 135 | | { |
| | 1 | 136 | | yield return drawingView; |
| | | 137 | | } |
| | | 138 | | } |
| | | 139 | | } |
| | 1 | 140 | | } |
| | | 141 | | |
| | | 142 | | /// <summary> |
| | | 143 | | /// Returns the version of Solid Edge that was used to create the referenced document. |
| | | 144 | | /// </summary> |
| | | 145 | | /// <param name="document"></param> |
| | | 146 | | /// <returns></returns> |
| | 1 | 147 | | public static Version GetCreatedVersion(this SolidEdgeDraft.DraftDocument document) => new(document.CreatedVersion); |
| | | 148 | | |
| | | 149 | | /// <summary> |
| | | 150 | | /// Returns the version of Solid Edge that was used the last time the referenced document was saved. |
| | | 151 | | /// </summary> |
| | | 152 | | /// <param name="document"></param> |
| | | 153 | | /// <returns></returns> |
| | 1 | 154 | | public static Version GetLastSavedVersion(this SolidEdgeDraft.DraftDocument document) => new(document.LastSavedVersi |
| | | 155 | | |
| | | 156 | | /// <summary> |
| | | 157 | | /// Returns the properties for the referenced document. |
| | | 158 | | /// </summary> |
| | | 159 | | /// <param name="document"></param> |
| | | 160 | | /// <returns></returns> |
| | 2 | 161 | | public static PropertySets GetProperties(this SolidEdgeDraft.DraftDocument document) => document.Properties as Prope |
| | | 162 | | |
| | | 163 | | /// <summary> |
| | | 164 | | /// Returns the summary information property set for the referenced document. |
| | | 165 | | /// </summary> |
| | | 166 | | /// <param name="document"></param> |
| | | 167 | | /// <returns></returns> |
| | 1 | 168 | | public static SummaryInfo GetSummaryInfo(this SolidEdgeDraft.DraftDocument document) => document.SummaryInfo as Summ |
| | | 169 | | |
| | | 170 | | /// <summary> |
| | | 171 | | /// Returns a collection of variables for the referenced document. |
| | | 172 | | /// </summary> |
| | | 173 | | /// <param name="document"></param> |
| | | 174 | | /// <returns></returns> |
| | 1 | 175 | | public static Variables GetVariables(this SolidEdgeDraft.DraftDocument document) => document.Variables as Variables; |
| | | 176 | | } |