/
DMT_addScaleToDrawingTitle3.cs
86 lines (70 loc) · 2.59 KB
/
DMT_addScaleToDrawingTitle3.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
using System;
using System.Collections;
using System.Diagnostics;
using System.Windows.Forms;
using Tekla.Structures.Drawing;
using TSD = Tekla.Structures.Drawing;
using Tekla.Structures.Drawing.UI;
using Tekla.Structures.Model;
using Tekla.Structures.Geometry3d;
namespace Tekla.Technology.Akit.UserScript
{
public class Script
{
public static void Run(Tekla.Technology.Akit.IScript akit)
{
Model myModel = new Model();
ScaleToDrawingTitle3.main();
myModel.CommitChanges();
}
}
public static class ScaleToDrawingTitle3
{
public static void main()
{
DrawingEnumerator selectedDrawings = getSelectedDrawings();
foreach (Drawing currentDrawing in selectedDrawings)
{
double highestScale = getHighestScale(currentDrawing);
setScaleToTitle3(currentDrawing, highestScale);
}
MessageBox.Show("Valitud " + selectedDrawings.GetSize() + " joonist." + Environment.NewLine +
"Muudetud " + selectedDrawings.GetSize() + " joonise title3");
}
private static DrawingEnumerator getSelectedDrawings()
{
DrawingHandler myDrawingHandler = new DrawingHandler();
DrawingEnumerator selectedDrawings = myDrawingHandler.GetDrawingSelector().GetSelected();
return selectedDrawings;
}
private static double getHighestScale(Drawing currentDrawing)
{
double highestScale = 0;
DrawingObjectEnumerator ViewEnum = currentDrawing.GetSheet().GetViews();
foreach (TSD.View currentView in ViewEnum)
{
if (isView2D(currentView))
{
double currentScale = currentView.Attributes.Scale;
highestScale = Math.Max(currentScale, highestScale);
}
}
return highestScale;
}
private static bool isView2D(TSD.View currentView)
{
CoordinateSystem disp = currentView.DisplayCoordinateSystem as CoordinateSystem;
CoordinateSystem viewp = currentView.ViewCoordinateSystem as CoordinateSystem;
if (disp.AxisX.Z != viewp.AxisX.Z || disp.AxisY.Z != viewp.AxisY.Z)
{
return false;
}
return true;
}
private static void setScaleToTitle3(Drawing currentDrawing, double highestScale)
{
currentDrawing.Title3 = "1:" + highestScale.ToString();
currentDrawing.Modify();
}
}
}