hytos / DTI_PID / APIDConverter / AutoModeling.cs @ 1c5bd296
이력 | 보기 | 이력해설 | 다운로드 (6.96 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Configuration; |
4 |
using System.Data; |
5 |
using System.Data.Common; |
6 |
using System.Data.SqlClient; |
7 |
using System.IO; |
8 |
|
9 |
using Autodesk.AutoCAD.ApplicationServices; |
10 |
using Autodesk.AutoCAD.ApplicationServices.Core; |
11 |
using Autodesk.AutoCAD.DatabaseServices; |
12 |
using Autodesk.AutoCAD.EditorInput; |
13 |
using Autodesk.AutoCAD.Geometry; |
14 |
using Autodesk.AutoCAD.Interop; |
15 |
using Autodesk.AutoCAD.Interop.Common; |
16 |
using Autodesk.AutoCAD.Runtime; |
17 |
using Autodesk.AutoCAD.Windows; |
18 |
|
19 |
using AVEVA.PID.Components; |
20 |
using AVEVA.PID.GUI; |
21 |
using AVEVA.PID.Common; |
22 |
using AVEVA.PID.DWGSelector; |
23 |
|
24 |
using AVEVA.PID.CustomizationUtility.DB; |
25 |
using AVEVA.PID.CustomizationUtility.Model; |
26 |
using AVEVA.PID.CustomizationUtility.Properties; |
27 |
|
28 |
namespace AVEVA.PID.CustomizationUtility |
29 |
{ |
30 |
public class AutoModeling |
31 |
{ |
32 |
public static AutoModeling Running { get; set; } |
33 |
Model.Document document; |
34 |
|
35 |
public AutoModeling(Model.Document document) |
36 |
{ |
37 |
this.document = document; |
38 |
} |
39 |
|
40 |
public void CreateDrawing() |
41 |
{ |
42 |
string outPath = Project_DB.GetDirectiveValue("DRGPTH"); |
43 |
string tempPath = Path.GetTempPath(); |
44 |
string selectedFullPath = Path.Combine(tempPath, document.AvevaTemplateName + ".DWT"); |
45 |
|
46 |
DWTSelector.strDrawingNumber = document.AvevaDrawingNumber; |
47 |
DWTSelector.strSheetNumber = document.AvevaSheetNumber; |
48 |
DWTSelector.strCadFileName = document.AvevaDrawingNumber + document.AvevaSheetNumber; |
49 |
DWTSelector.strCadFilePath = outPath; |
50 |
|
51 |
try |
52 |
{ |
53 |
string text = ReadWriteDrawingData.ReadTemplateData(document.AvevaTemplateName, document.AvevaTemplateID, selectedFullPath, false); |
54 |
Autodesk.AutoCAD.Interop.AcadApplication acadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as Autodesk.AutoCAD.Interop.AcadApplication; |
55 |
Autodesk.AutoCAD.Interop.AcadDocument acadDocument = acadApplication.Documents.Add(text); |
56 |
|
57 |
Commands.addLatestPidvesrionToDictionary(); |
58 |
AVVPropCmd.ActivateAcad(); |
59 |
|
60 |
if (acadDocument != null) |
61 |
{ |
62 |
Running = this; |
63 |
acadApplication.ActiveDocument = acadDocument; |
64 |
acadDocument.SendCommand("QSAVE "); |
65 |
acadDocument.SendCommand("APPIDRun "); |
66 |
Running = null; |
67 |
} |
68 |
} |
69 |
catch (System.Exception ex) |
70 |
{ |
71 |
|
72 |
} |
73 |
|
74 |
GC.Collect(); |
75 |
} |
76 |
public void Run() |
77 |
{ |
78 |
test(); |
79 |
} |
80 |
|
81 |
private string ReadDrawingLastLine() |
82 |
{ |
83 |
string sHandle = string.Empty; |
84 |
SqlConnection connection = null; |
85 |
try |
86 |
{ |
87 |
connection = new SqlConnection(); |
88 |
connection.ConnectionString = DB.Project_DB.GetAvevaConnectionString(); |
89 |
connection.Open(); |
90 |
|
91 |
string strQry = string.Format("Select Handle from Pipe Where id = (SELECT MAX(id) FROM Pipe WHERE DrawingId = '{0}')", "Test"); |
92 |
SqlCommand cmd = new SqlCommand(); |
93 |
cmd.Connection = connection; |
94 |
cmd.CommandText = strQry; |
95 |
cmd.CommandType = CommandType.Text; |
96 |
|
97 |
SqlDataAdapter da = new SqlDataAdapter(cmd); |
98 |
System.Data.DataTable dt = new System.Data.DataTable(); |
99 |
da.Fill(dt); |
100 |
if (dt.Rows.Count == 1) |
101 |
sHandle = dt.Rows[0][0].ToString(); |
102 |
|
103 |
dt.Dispose(); |
104 |
da.Dispose(); |
105 |
} |
106 |
catch (System.Exception) |
107 |
{ } |
108 |
finally |
109 |
{ |
110 |
if (connection != null) |
111 |
connection.Close(); |
112 |
} |
113 |
|
114 |
return sHandle; |
115 |
} |
116 |
|
117 |
#region Drawing Method |
118 |
private string DrawPipe(string style, List<string> coordinates) |
119 |
{ |
120 |
GUIUtils.SetPipeStyle(style); |
121 |
|
122 |
string prevHandle = ReadDrawingLastLine(); |
123 |
|
124 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
125 |
Editor editor = acDoc.Editor; |
126 |
List<object> commandParam = new List<object>(); |
127 |
//command name |
128 |
commandParam.Add("DRPIPE"); |
129 |
//coordinate |
130 |
foreach (var item in coordinates) |
131 |
commandParam.Add(item); |
132 |
//enter |
133 |
commandParam.Add(null); |
134 |
//enter |
135 |
commandParam.Add(null); |
136 |
|
137 |
editor.Command(commandParam.ToArray()); |
138 |
|
139 |
string newHandle = ReadDrawingLastLine(); |
140 |
if (prevHandle == newHandle) |
141 |
return string.Empty; |
142 |
|
143 |
return newHandle; |
144 |
} |
145 |
private void DrawPipe(string style, List<string> coordinates, ObjectId objectId) |
146 |
{ |
147 |
GUIUtils.SetPipeStyle(style); |
148 |
|
149 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
150 |
Editor editor = acDoc.Editor; |
151 |
List<object> commandParam = new List<object>(); |
152 |
//command name |
153 |
commandParam.Add("DRPIPE"); |
154 |
//coordinate |
155 |
foreach (var item in coordinates) |
156 |
commandParam.Add(item); |
157 |
//enter |
158 |
commandParam.Add(null); |
159 |
|
160 |
//Input Object ID |
161 |
commandParam.Add(objectId); |
162 |
|
163 |
//enter |
164 |
commandParam.Add(null); |
165 |
|
166 |
editor.Command(commandParam.ToArray()); |
167 |
} |
168 |
private void InsertSymbol(string insertSymbolName, double x, double y) |
169 |
{ |
170 |
try |
171 |
{ |
172 |
AVEVA.PID.Utilities.DrawingData drawingData = new AVEVA.PID.Utilities.DrawingData(); |
173 |
drawingData.InsertSymbolName = insertSymbolName; |
174 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
175 |
Editor editor = acDoc.Editor; |
176 |
List<object> commandParam = new List<object>(); |
177 |
commandParam.Add("INSSYM"); |
178 |
Point3d point = new Point3d(x, y, 0); |
179 |
commandParam.Add(point); |
180 |
commandParam.Add(null); |
181 |
|
182 |
editor.Command(commandParam.ToArray()); |
183 |
} |
184 |
catch (System.Exception ex) |
185 |
{ |
186 |
|
187 |
} |
188 |
} |
189 |
#endregion |
190 |
|
191 |
#region Test Source |
192 |
public void test() |
193 |
{ |
194 |
//InitGUI(); |
195 |
|
196 |
DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" }); |
197 |
|
198 |
DrawPipe("Main Pipe", new List<string>() { "2,200", "100,200" }); |
199 |
|
200 |
DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" }); |
201 |
} |
202 |
|
203 |
public static void TEST() |
204 |
{ |
205 |
AutoModeling auto = new AutoModeling(null); |
206 |
auto.test(); |
207 |
} |
208 |
#endregion |
209 |
} |
210 |
} |