-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy to another beam by end point.cs
78 lines (60 loc) · 2.59 KB
/
Copy to another beam by end point.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
using System.Collections;
using Tekla.Structures.Geometry3d;
using Tekla.Structures.Model;
using Tekla.Structures.Model.UI;
using TSM = Tekla.Structures.Model;
using TSMUI = Tekla.Structures.Model.UI;
namespace Tekla.Technology.Akit.UserScript
{
static class Script
{
public static void Run(Tekla.Technology.Akit.IScript akit)
{
try
{
Model model = new Model();
TSMUI.ModelObjectSelector modelObjectSelector = new TSMUI.ModelObjectSelector();
ModelObjectEnumerator objectsToCopyEnum = modelObjectSelector.GetSelectedObjects();
ArrayList objectsToCopyArray = new ArrayList();
while (objectsToCopyEnum.MoveNext())
objectsToCopyArray.Add(objectsToCopyEnum.Current);
Beam sourceBeam = PickBeam();
ArrayList modelObjectSelectorArray = new ArrayList();
modelObjectSelectorArray.Add(sourceBeam);
modelObjectSelector.Select(modelObjectSelectorArray);
modelObjectSelectorArray.Clear();
CopyToAnotherBeamByEndPoint(objectsToCopyArray, sourceBeam);
}
catch { }
}
public static Beam PickBeam()
{
Picker picker = new Picker();
Beam pickedBeam = null;
while (pickedBeam is null)
{
Part pickedPart = (Part)picker.PickObject(Picker.PickObjectEnum.PICK_ONE_PART, "Please pick a beam");
if (pickedPart is Beam)
pickedBeam = (Beam)pickedPart;
}
return pickedBeam;
}
public static void CopyToAnotherBeamByEndPoint(ArrayList objectsToCopyArray, Beam sourceBeam)
{
try
{
Model model = new Model();
Beam destinationBeam = PickBeam();
CoordinateSystem sourceCoordinateSystem = sourceBeam.GetCoordinateSystem();
sourceCoordinateSystem.Origin = sourceBeam.EndPoint;
CoordinateSystem destinationCoordinateSystem = destinationBeam.GetCoordinateSystem();
destinationCoordinateSystem.Origin = destinationBeam.EndPoint;
foreach (ModelObject objectToCopy in objectsToCopyArray)
TSM.Operations.Operation.CopyObject(objectToCopy, sourceCoordinateSystem, destinationCoordinateSystem);
model.CommitChanges();
CopyToAnotherBeamByEndPoint(objectsToCopyArray, sourceBeam);
}
catch { }
}
}
}