/
DMT_exportSelectedAssemblysToIFC.cs
154 lines (124 loc) · 5.2 KB
/
DMT_exportSelectedAssemblysToIFC.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using Tekla.Structures.Model;
using TSM = Tekla.Structures.Model;
using Tekla.Structures.Model.UI;
using Tekla.Structures.Geometry3d;
namespace Tekla.Technology.Akit.UserScript
{
public class Script
{
public static void Run(Tekla.Technology.Akit.IScript akit)
{
SelectedAssemblysToIFC.main();
}
public static class SelectedAssemblysToIFC
{
private static bool exportIFC(string outputFileName)
{
ComponentInput ComponentInput = new ComponentInput();
ComponentInput.AddOneInputPosition(new Point(0, 0, 0));
Component Comp = new Component(ComponentInput);
Comp.Name = "ExportIFC";
Comp.Number = BaseComponent.PLUGIN_OBJECT_NUMBER;
// Parameters
Comp.SetAttribute("OutputFile", outputFileName);
Comp.SetAttribute("Format", 0);
Comp.SetAttribute("ExportType", 1);
Comp.SetAttribute("AdditionalPSets", "BMcDIFCConfig");
Comp.SetAttribute("CreateAll", 0); // 0 to export only selected objects
// Advanced
Comp.SetAttribute("Assemblies", 1);
Comp.SetAttribute("Bolts", 1);
Comp.SetAttribute("Welds", 0);
Comp.SetAttribute("SurfaceTreatments", 1);
Comp.SetAttribute("BaseQuantities", 1);
Comp.SetAttribute("GridExport", 1);
Comp.SetAttribute("ReinforcingBars", 1);
Comp.SetAttribute("PourObjects", 1);
Comp.SetAttribute("LayersNameAsPart", 1);
Comp.SetAttribute("PLprofileToPlate", 0);
Comp.SetAttribute("ExcludeSnglPrtAsmb", 0);
//Comp.SetAttribute("LocsFromOrganizer", 0); // dafuq
return Comp.Insert();
}
public static void main()
{
ModelObjectEnumerator selectedObjects = getSelectedObjects();
List<Assembly> selectedAssemblys = getSelectedAssemblys(selectedObjects);
foreach (Assembly currentAssembly in selectedAssemblys)
{
exportCurrentAssembly(currentAssembly);
}
selectInitialObjects(selectedAssemblys);
MessageBox.Show("done");
}
private static ModelObjectEnumerator getSelectedObjects()
{
var selector = new TSM.UI.ModelObjectSelector();
ModelObjectEnumerator selectionEnum = selector.GetSelectedObjects();
return selectionEnum;
}
private static List<Assembly> getSelectedAssemblys(ModelObjectEnumerator selectedObjects)
{
List<Assembly> selectedAssemblys = new List<Assembly>();
while (selectedObjects.MoveNext())
{
if (selectedObjects.Current is Assembly)
{
selectedAssemblys.Add(selectedObjects.Current as Assembly);
}
}
return selectedAssemblys;
}
private static void exportCurrentAssembly(Assembly assembly)
{
ArrayList currentAssemblySelect = new ArrayList();
currentAssemblySelect.Add(assembly);
var selector = new TSM.UI.ModelObjectSelector();
selector.Select(currentAssemblySelect);
try
{
string name = getFileName(assembly);
exportIFC(name);
}
catch
{
MessageBox.Show("Element sisaldab keelatuid märke");
}
}
private static string getFileName(Assembly assembly)
{
string position = null;
assembly.GetReportProperty("ASSEMBLY_POS", ref position);
position = position.Replace("/", "_");
position = position.Replace("?", "_");
if (position.Contains("/") || position.Contains("?"))
{
throw new System.Exception();
}
int addon = 1;
while (System.IO.File.Exists(position + ".ifc"))
{
if (position.EndsWith(@"(" + (addon - 1).ToString() + @")"))
{
int removeIndex = position.Length - 3;
position = position.Remove(removeIndex);
}
position = position + @"(" + addon.ToString() + @")";
addon++;
}
return position;
}
private static void selectInitialObjects(List<Assembly> selectedAssemblys)
{
ArrayList initialSelectedAssemblys = new ArrayList(selectedAssemblys);
var selector = new TSM.UI.ModelObjectSelector();
selector.Select(initialSelectedAssemblys);
}
}
}
}