-
Notifications
You must be signed in to change notification settings - Fork 0
/
aaa.cs
107 lines (76 loc) · 3.35 KB
/
aaa.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using MicroStationDGN;
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
using Application = System.Windows.Forms.Application;
namespace WindowsFormsApp1
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
buttonRozdziel.Text = @"Rozdziel";
textBoxFileName.Text = @"c:\karty_map.dgn";
}
private void ButtonRozdziel_Click(object sender, EventArgs e)
{
string iFileName = textBoxFileName.Text;
StreamWriter logFile = new StreamWriter(new FileStream(iFileName.Substring(0, iFileName.LastIndexOf(".", StringComparison.Ordinal)) + ".log", FileMode.Create), Encoding.UTF8);
logFile.WriteLine("Rozdielanie pliku: {0}\n", iFileName);
MicroStationDGN.Application oMstn = new MicroStationDGN.Application();
DesignFile iFile = oMstn.OpenDesignFile(iFileName, true);
if (iFile.Models.Count > 1)
{
MessageBox.Show(@"Ilość modeli w pliku większa niż 1 !");
Application.Exit();
}
ModelReference modelIn = iFile.Models[1];
foreach (Level levelIn in iFile.Levels)
{
string levelInName = levelIn.Name;
if (levelIn.IsInUse)
{
logFile.WriteLine("warstwa {0}: uzywana", levelInName);
File.Copy(iFileName, @"C:\temp\" + levelIn.Name + ".dgn", true);
DesignFile oFile = oMstn.OpenDesignFileForProgram(@"C:\temp\" + levelIn.Name + ".dgn", false);
ModelReference modelOut = oFile.Models[1];
foreach (Level levelOut in oFile.Levels)
{
string levelOutName = levelOut.Name;
if (levelOutName != levelInName)
{
if (levelOut.IsInUseWithinModel(modelOut))
{
ElementScanCriteria elementScanCriteriaOut = new ElementScanCriteriaClass();
elementScanCriteriaOut.ExcludeAllLevels();
elementScanCriteriaOut.IncludeLevel(levelOut);
ElementEnumerator elementEnumeratorOut = modelOut.Scan(elementScanCriteriaOut);
//Array elementOut = elementEnumeratorOut.BuildArrayFromContents();
while (elementEnumeratorOut.MoveNext())
{
modelOut.RemoveElement(elementEnumeratorOut.Current);
}
}
if (!levelOut.IsInUse && levelOut.Number != 0) oFile.DeleteLevel(levelOut);
}
}
oFile.RewriteLevels();
oFile.Save();
oFile.Close();
}
else
{
logFile.WriteLine("warstwa {0}: brak", levelInName);
}
}
logFile.Close();
iFile.Close();
oMstn.Quit();
}
}
}