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