hytos / DTI_PID / APIDConverter / AutoModeling.cs @ 534ca9c5
이력 | 보기 | 이력해설 | 다운로드 (6.81 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 |
|
20 |
namespace AVEVA.PID.CustomizationUtility |
21 |
{ |
22 |
public class AutoModeling |
23 |
{ |
24 |
Autodesk.Windows.RibbonCombo pipeStyleCombo = null; |
25 |
Autodesk.Windows.RibbonChecklistButton autoLabelCheckListButton = null; |
26 |
|
27 |
private void InitGUI() |
28 |
{ |
29 |
Autodesk.Windows.RibbonItemCollection items = GUI.RibbonHelper.GetPanelItems("ID_PIPE_PANEL"); |
30 |
object objPipeStyle = GUIUtils.FindItem(items, "PIPESTYLE"); |
31 |
if (objPipeStyle != null) |
32 |
pipeStyleCombo = objPipeStyle as Autodesk.Windows.RibbonCombo; |
33 |
object objAutoLabel = GUIUtils.FindItem(items, "Auto Label"); |
34 |
if (objAutoLabel != null) |
35 |
autoLabelCheckListButton = objAutoLabel as Autodesk.Windows.RibbonChecklistButton; |
36 |
|
37 |
|
38 |
} |
39 |
private void SetAutoLabelUnCehck() |
40 |
{ |
41 |
if (autoLabelCheckListButton != null) |
42 |
{ |
43 |
foreach (var item in autoLabelCheckListButton.Items) |
44 |
{ |
45 |
if (item.GetType() == typeof(Autodesk.Windows.RibbonButton)) |
46 |
{ |
47 |
Autodesk.Windows.RibbonButton ribbonButton = item as Autodesk.Windows.RibbonButton; |
48 |
if (ribbonButton.IsChecked) |
49 |
ribbonButton.IsChecked = false; |
50 |
} |
51 |
} |
52 |
} |
53 |
} |
54 |
|
55 |
private void SetPipeStyle(string style) |
56 |
{ |
57 |
if (pipeStyleCombo.Current != null) |
58 |
{ |
59 |
Autodesk.Windows.RibbonButton button = pipeStyleCombo.Current as Autodesk.Windows.RibbonButton; |
60 |
if (button.AutomationName != style) |
61 |
{ |
62 |
foreach (var item in pipeStyleCombo.Items) |
63 |
{ |
64 |
Autodesk.Windows.RibbonButton loop = item as Autodesk.Windows.RibbonButton; |
65 |
if (loop.AutomationName == style) |
66 |
{ |
67 |
pipeStyleCombo.Current = loop; |
68 |
break; |
69 |
} |
70 |
} |
71 |
} |
72 |
} |
73 |
} |
74 |
|
75 |
private string ReadDrawingLastLine() |
76 |
{ |
77 |
string sHandle = string.Empty; |
78 |
SqlConnection connection = null; |
79 |
try |
80 |
{ |
81 |
connection = new SqlConnection(); |
82 |
connection.ConnectionString = DB.Project_DB.GetAvevaConnectionString(); |
83 |
connection.Open(); |
84 |
|
85 |
string strQry = string.Format("Select Handle from Pipe Where id = (SELECT MAX(id) FROM Pipe WHERE DrawingId = '{0}')", "Test"); |
86 |
SqlCommand cmd = new SqlCommand(); |
87 |
cmd.Connection = connection; |
88 |
cmd.CommandText = strQry; |
89 |
cmd.CommandType = CommandType.Text; |
90 |
|
91 |
SqlDataAdapter da = new SqlDataAdapter(cmd); |
92 |
System.Data.DataTable dt = new System.Data.DataTable(); |
93 |
da.Fill(dt); |
94 |
if (dt.Rows.Count == 1) |
95 |
sHandle = dt.Rows[0][0].ToString(); |
96 |
|
97 |
dt.Dispose(); |
98 |
da.Dispose(); |
99 |
} |
100 |
catch (System.Exception) |
101 |
{ } |
102 |
finally |
103 |
{ |
104 |
if (connection != null) |
105 |
connection.Close(); |
106 |
} |
107 |
|
108 |
return sHandle; |
109 |
} |
110 |
|
111 |
#region Drawing Method |
112 |
private string DrawPipe(string style, List<string> coordinates) |
113 |
{ |
114 |
SetPipeStyle(style); |
115 |
|
116 |
string prevHandle = ReadDrawingLastLine(); |
117 |
|
118 |
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
119 |
Editor editor = acDoc.Editor; |
120 |
List<object> commandParam = new List<object>(); |
121 |
//command name |
122 |
commandParam.Add("DRPIPE"); |
123 |
//coordinate |
124 |
foreach (var item in coordinates) |
125 |
commandParam.Add(item); |
126 |
//enter |
127 |
commandParam.Add(null); |
128 |
//enter |
129 |
commandParam.Add(null); |
130 |
|
131 |
editor.Command(commandParam.ToArray()); |
132 |
|
133 |
string newHandle = ReadDrawingLastLine(); |
134 |
if (prevHandle == newHandle) |
135 |
return string.Empty; |
136 |
|
137 |
return newHandle; |
138 |
} |
139 |
private void DrawPipe(string style, List<string> coordinates, ObjectId objectId) |
140 |
{ |
141 |
SetPipeStyle(style); |
142 |
|
143 |
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
144 |
Editor editor = acDoc.Editor; |
145 |
List<object> commandParam = new List<object>(); |
146 |
//command name |
147 |
commandParam.Add("DRPIPE"); |
148 |
//coordinate |
149 |
foreach (var item in coordinates) |
150 |
commandParam.Add(item); |
151 |
//enter |
152 |
commandParam.Add(null); |
153 |
|
154 |
//Input Object ID |
155 |
commandParam.Add(objectId); |
156 |
|
157 |
//enter |
158 |
commandParam.Add(null); |
159 |
|
160 |
editor.Command(commandParam.ToArray()); |
161 |
} |
162 |
private void InsertSymbol(string insertSymbolName, double x, double y) |
163 |
{ |
164 |
try |
165 |
{ |
166 |
AVEVA.PID.Utilities.DrawingData drawingData = new AVEVA.PID.Utilities.DrawingData(); |
167 |
drawingData.InsertSymbolName = insertSymbolName; |
168 |
Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; |
169 |
Editor editor = acDoc.Editor; |
170 |
List<object> commandParam = new List<object>(); |
171 |
commandParam.Add("INSSYM"); |
172 |
Point3d point = new Point3d(x, y, 0); |
173 |
commandParam.Add(point); |
174 |
commandParam.Add(null); |
175 |
|
176 |
editor.Command(commandParam.ToArray()); |
177 |
} |
178 |
catch (System.Exception ex) |
179 |
{ |
180 |
|
181 |
} |
182 |
} |
183 |
#endregion |
184 |
|
185 |
#region Test Source |
186 |
|
187 |
public void test() |
188 |
{ |
189 |
InitGUI(); |
190 |
|
191 |
DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" }); |
192 |
|
193 |
DrawPipe("Main Pipe", new List<string>() { "2,200", "100,200" }); |
194 |
|
195 |
DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" }); |
196 |
} |
197 |
|
198 |
public static void TEST() |
199 |
{ |
200 |
AutoModeling auto = new AutoModeling(); |
201 |
auto.test(); |
202 |
} |
203 |
#endregion |
204 |
} |
205 |
} |