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