프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / APIDConverter / APIDConverterExplorer.cs @ dfb760ef

이력 | 보기 | 이력해설 | 다운로드 (4.55 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Drawing;
5
using System.Data;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows.Forms;
10

    
11
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
12

    
13
using Autodesk.AutoCAD.ApplicationServices;
14
using Autodesk.AutoCAD.ApplicationServices.Core;
15
using Autodesk.AutoCAD.DatabaseServices;
16
using Autodesk.AutoCAD.EditorInput;
17

    
18
using AVEVA.PID.CustomizationUtility.DB;
19
using AVEVA.PID.CustomizationUtility.Model;
20
using AVEVA.PID.CustomizationUtility.Properties;
21

    
22
namespace AVEVA.PID.CustomizationUtility
23
{
24
    public partial class APIDConverterExplorer : UserControl
25
    {
26
        public APIDConverterExplorer()
27
        {
28
            InitializeComponent();
29

    
30
            textDrawingX.Text = Settings.Default.DrawingX.ToString();
31
            textDrawingY.Text = Settings.Default.DrawingY.ToString();
32
        }
33

    
34
        private void btnOpenConverter_Click(object sender, EventArgs e)
35
        {
36
            
37
            APIDConverter form = new APIDConverter();
38
            if (AcadApp.ShowModalDialog(form) == DialogResult.OK)
39
            {
40
                try
41
                {
42
                    AccessPropertyForm.Run();
43

    
44
                    foreach (var item in form.Documents)
45
                    {
46
                        AutoModeling autoModeling = new AutoModeling(item);
47
                        autoModeling.CreateDrawing();
48
                    }
49

    
50
                    MessageBox.Show("End Conversion", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
51
                }
52
                catch (Exception ex)
53
                {
54

    
55
                }
56
                finally
57
                {
58
                    AccessPropertyForm.Stop();
59
                }
60
                
61
            }
62
        }
63

    
64
        private void btnDrawingSize_Click(object sender, EventArgs e)
65
        {
66
            // Get the current document and database, and start a transaction
67
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
68
            Database acCurDb = acDoc.Database;
69
            Editor acDocEd = acDoc.Editor;
70

    
71
            // Request for objects to be selected in the drawing area
72
            PromptSelectionResult acSSPrompt = acDocEd.GetSelection();
73

    
74
            // If the prompt status is OK, objects were selected
75
            if (acSSPrompt.Status == PromptStatus.OK)
76
            {
77
                ObjectId[] selectedObjectIds = acSSPrompt.Value.GetObjectIds();
78
                // Get the last selected entity
79

    
80
                if (selectedObjectIds.Length > 0)
81
                {
82
                    ObjectId objectId = selectedObjectIds[0];
83
                    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
84
                    {
85
                        Entity entity = acTrans.GetObject(objectId, OpenMode.ForRead, true) as Entity;
86
                        if (entity != null)
87
                        {
88
                            Extents3d extents = entity.GeometricExtents;
89
                            double width = extents.MaxPoint.X - extents.MinPoint.X;
90
                            double height = extents.MaxPoint.Y - extents.MinPoint.Y;
91

    
92
                            if (width == 0 || height == 0)
93
                            {
94
                                MessageBox.Show("Please select one rectangle", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
95
                                return;
96
                            }
97

    
98
                            Settings.Default.DrawingX = width;
99
                            Settings.Default.DrawingY = height;
100
                            Settings.Default.Save();
101
                            textDrawingX.Text = Settings.Default.DrawingX.ToString();
102
                            textDrawingY.Text = Settings.Default.DrawingY.ToString();
103

    
104
                            MessageBox.Show("End Drawing Size Setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
105
                        }
106
                        else
107
                        {
108
                            MessageBox.Show("Please select one rectangle", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
109
                        }
110
                        acTrans.Commit();
111
                    }
112
                }
113
                else
114
                {
115
                    MessageBox.Show("Please select one rectangle", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
116
                }
117
            }
118
        }
119
    }
120
}
클립보드 이미지 추가 (최대 크기: 500 MB)