프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / APIDConverter / AutoModeling.cs @ 14540282

이력 | 보기 | 이력해설 | 다운로드 (5.43 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.CustomizationUtility.DB;
20
using AVEVA.PID.CustomizationUtility.Model;
21
using AVEVA.PID.CustomizationUtility.Properties;
22

    
23
namespace AVEVA.PID.CustomizationUtility
24
{
25
    public class AutoModeling
26
    {
27
        Model.Document document;
28

    
29
        public AutoModeling(Model.Document document)
30
        {
31
            this.document = document;
32
        }
33

    
34
        public void Run()
35
        {
36
            if (APIDUtils.CreateDrawingAndOpen(document.AvevaDrawingNumber, document.AvevaSheetNumber, document.AvevaTemplateName, document.AvevaTemplateID))
37
            {
38
                test();
39
            }
40
        }
41

    
42
        private string ReadDrawingLastLine()
43
        {
44
            string sHandle = string.Empty;
45
            SqlConnection connection = null;
46
            try
47
            {
48
                connection = new SqlConnection();
49
                connection.ConnectionString = DB.Project_DB.GetAvevaConnectionString();
50
                connection.Open();
51

    
52
                string strQry = string.Format("Select Handle from Pipe Where id = (SELECT MAX(id) FROM Pipe WHERE DrawingId = '{0}')", "Test");
53
                SqlCommand cmd = new SqlCommand();
54
                cmd.Connection = connection;
55
                cmd.CommandText = strQry;
56
                cmd.CommandType = CommandType.Text;
57

    
58
                SqlDataAdapter da = new SqlDataAdapter(cmd);
59
                System.Data.DataTable dt = new System.Data.DataTable();
60
                da.Fill(dt);
61
                if (dt.Rows.Count == 1)
62
                    sHandle = dt.Rows[0][0].ToString();
63

    
64
                dt.Dispose();
65
                da.Dispose();
66
            }
67
            catch (System.Exception)
68
            { }
69
            finally
70
            {
71
                if (connection != null)
72
                    connection.Close();
73
            }
74

    
75
            return sHandle;
76
        }
77

    
78
        #region Drawing Method
79
        private string DrawPipe(string style, List<string> coordinates)
80
        {
81
            GUIUtils.SetPipeStyle(style);
82

    
83
            string prevHandle = ReadDrawingLastLine();
84

    
85
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
86
            Editor editor = acDoc.Editor;
87
            List<object> commandParam = new List<object>();
88
            //command name
89
            commandParam.Add("DRPIPE");
90
            //coordinate
91
            foreach (var item in coordinates)
92
                commandParam.Add(item);
93
            //enter
94
            commandParam.Add(null);
95
            //enter
96
            commandParam.Add(null);
97

    
98
            editor.Command(commandParam.ToArray());
99

    
100
            string newHandle = ReadDrawingLastLine();
101
            if (prevHandle == newHandle)
102
                return string.Empty;
103

    
104
            return newHandle;
105
        }
106
        private void DrawPipe(string style, List<string> coordinates, ObjectId objectId)
107
        {
108
            GUIUtils.SetPipeStyle(style);
109

    
110
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
111
            Editor editor = acDoc.Editor;
112
            List<object> commandParam = new List<object>();
113
            //command name
114
            commandParam.Add("DRPIPE");
115
            //coordinate
116
            foreach (var item in coordinates)
117
                commandParam.Add(item);
118
            //enter
119
            commandParam.Add(null);
120

    
121
            //Input Object ID
122
            commandParam.Add(objectId);
123

    
124
            //enter
125
            commandParam.Add(null);
126

    
127
            editor.Command(commandParam.ToArray());
128
        }
129
        private void InsertSymbol(string insertSymbolName, double x, double y)
130
        {
131
            try
132
            {
133
                AVEVA.PID.Utilities.DrawingData drawingData = new AVEVA.PID.Utilities.DrawingData();
134
                drawingData.InsertSymbolName = insertSymbolName;
135
                Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
136
                Editor editor = acDoc.Editor;
137
                List<object> commandParam = new List<object>();
138
                commandParam.Add("INSSYM");
139
                Point3d point = new Point3d(x, y, 0);
140
                commandParam.Add(point);
141
                commandParam.Add(null);
142

    
143
                editor.Command(commandParam.ToArray());
144
            }
145
            catch (System.Exception ex)
146
            {
147

    
148
            }
149
        }
150
        #endregion
151

    
152
        #region Test Source
153
        public void test()
154
        {
155
            //InitGUI();
156

    
157
            DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" });
158

    
159
            DrawPipe("Main Pipe", new List<string>() { "2,200", "100,200" });
160

    
161
            DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" });
162
        }
163

    
164
        public static void TEST()
165
        {
166
            AutoModeling auto = new AutoModeling(null);
167
            auto.test();
168
        }
169
        #endregion
170
    }
171
}
클립보드 이미지 추가 (최대 크기: 500 MB)