hytos / DTI_PID / APIDConverter / Utils / APIDUtils.cs @ 32954c7f
이력 | 보기 | 이력해설 | 다운로드 (5.14 KB)
1 | 4e320fcb | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | 59184d1b | gaqhf | using System.IO; |
7 | using System.Reflection; |
||
8 | |||
9 | using AVEVA.PID.Components; |
||
10 | using AVEVA.PID.GUI; |
||
11 | using AVEVA.PID.Common; |
||
12 | using AVEVA.PID.DWGSelector; |
||
13 | 4e320fcb | gaqhf | |
14 | 5aec7e24 | gaqhf | using AVEVA.PID.CustomizationUtility.DB; |
15 | using AVEVA.PID.CustomizationUtility.Model; |
||
16 | using AVEVA.PID.CustomizationUtility.Properties; |
||
17 | |||
18 | 4e320fcb | gaqhf | namespace AVEVA.PID.CustomizationUtility |
19 | { |
||
20 | public class APIDUtils |
||
21 | { |
||
22 | 32954c7f | gaqhf | #region APID Converter |
23 | 5aec7e24 | gaqhf | public static object FindObjectByUID(Document document, string UID) |
24 | { |
||
25 | if (!string.IsNullOrEmpty(UID) && UID != "None") |
||
26 | { |
||
27 | foreach (PlantItem item in document.PlantItems) |
||
28 | { |
||
29 | if (item.UID == UID) |
||
30 | return item; |
||
31 | } |
||
32 | } |
||
33 | 4e320fcb | gaqhf | |
34 | 5aec7e24 | gaqhf | return null; |
35 | } |
||
36 | 32954c7f | gaqhf | public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY) |
37 | { |
||
38 | try |
||
39 | { |
||
40 | string[] pointArr = sPoint.Split(new char[] { ',' }); |
||
41 | if (pointArr.Length == 2) |
||
42 | { |
||
43 | dX = Convert.ToDouble(pointArr[0]); |
||
44 | dY = Convert.ToDouble(pointArr[1]); |
||
45 | } |
||
46 | } |
||
47 | catch (Exception) |
||
48 | { |
||
49 | dX = 0; |
||
50 | dY = 0; |
||
51 | return false; |
||
52 | } |
||
53 | |||
54 | return true; |
||
55 | } |
||
56 | #endregion |
||
57 | 88cb9898 | gaqhf | |
58 | 32954c7f | gaqhf | #region Only AVEVA |
59 | 88cb9898 | gaqhf | public static void SetAvevaExplorer() |
60 | { |
||
61 | bool exist = false; |
||
62 | string sName = "APID Converter"; |
||
63 | for (int i = 0; i < Aveva.Command.AvevaCommands.projectExplorer.Count; i++) |
||
64 | { |
||
65 | if (Aveva.Command.AvevaCommands.projectExplorer[i].Name == sName) |
||
66 | { |
||
67 | exist = true; |
||
68 | Aveva.Command.AvevaCommands.projectExplorer.Remove(i); |
||
69 | break; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | if (!exist) |
||
74 | { |
||
75 | Aveva.Command.AvevaCommands.projectExplorer.Add(sName, new APIDConverterExplorer()); |
||
76 | Aveva.Command.AvevaCommands.projectExplorer.Activate(Aveva.Command.AvevaCommands.projectExplorer.Count - 1); |
||
77 | } |
||
78 | 9ee9b61d | gaqhf | } |
79 | public static List<string> GetPipeStyle() |
||
80 | { |
||
81 | List<string> list = new List<string>(); |
||
82 | Autodesk.Windows.RibbonItemCollection items = GUI.RibbonHelper.GetPanelItems("ID_PIPE_PANEL"); |
||
83 | object objPipeStyle = GUIUtils.FindItem(items, "PIPESTYLE"); |
||
84 | if (objPipeStyle != null) |
||
85 | { |
||
86 | Autodesk.Windows.RibbonCombo pipeStyleCombo = objPipeStyle as Autodesk.Windows.RibbonCombo; |
||
87 | foreach (var item in pipeStyleCombo.Items) |
||
88 | { |
||
89 | Autodesk.Windows.RibbonButton loop = item as Autodesk.Windows.RibbonButton; |
||
90 | list.Add(loop.AutomationName); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | return list; |
||
95 | } |
||
96 | public static List<string> GetSignalStyle() |
||
97 | { |
||
98 | List<string> list = new List<string>(); |
||
99 | Autodesk.Windows.RibbonItemCollection items = GUI.RibbonHelper.GetPanelItems("ID_SIGNAL_PANEL"); |
||
100 | object objPipeStyle = GUIUtils.FindItem(items, "SIGNALSTYLE"); |
||
101 | if (objPipeStyle != null) |
||
102 | { |
||
103 | Autodesk.Windows.RibbonCombo pipeStyleCombo = objPipeStyle as Autodesk.Windows.RibbonCombo; |
||
104 | foreach (var item in pipeStyleCombo.Items) |
||
105 | { |
||
106 | Autodesk.Windows.RibbonButton loop = item as Autodesk.Windows.RibbonButton; |
||
107 | list.Add(loop.AutomationName); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | return list; |
||
112 | 88cb9898 | gaqhf | } |
113 | 59184d1b | gaqhf | public static bool CreateDrawingAndOpen(string drawingNumber, string sheetNumber, string templateName, string templateId) |
114 | { |
||
115 | bool result = true; |
||
116 | string outPath = Project_DB.GetDirectiveValue("DRGPTH"); |
||
117 | string tempPath = Path.GetTempPath(); |
||
118 | string selectedFullPath = Path.Combine(tempPath, templateName + ".DWT"); |
||
119 | |||
120 | DWTSelector.strDrawingNumber = drawingNumber; |
||
121 | DWTSelector.strSheetNumber = sheetNumber; |
||
122 | DWTSelector.strCadFileName = drawingNumber + sheetNumber; |
||
123 | DWTSelector.strCadFilePath = outPath; |
||
124 | |||
125 | try |
||
126 | { |
||
127 | string text = ReadWriteDrawingData.ReadTemplateData(templateName, templateId, selectedFullPath, false); |
||
128 | Autodesk.AutoCAD.Interop.AcadApplication acadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as Autodesk.AutoCAD.Interop.AcadApplication; |
||
129 | Autodesk.AutoCAD.Interop.AcadDocument acadDocument = acadApplication.Documents.Add(text); |
||
130 | |||
131 | Commands.addLatestPidvesrionToDictionary(); |
||
132 | AVVPropCmd.ActivateAcad(); |
||
133 | acadApplication.ActiveDocument = acadDocument; |
||
134 | acadDocument.Save(); |
||
135 | } |
||
136 | catch (Exception ex) |
||
137 | { |
||
138 | result = false; |
||
139 | } |
||
140 | |||
141 | GC.Collect(); |
||
142 | |||
143 | return result; |
||
144 | } |
||
145 | 32954c7f | gaqhf | #endregion |
146 | 4e320fcb | gaqhf | } |
147 | } |