-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleCreateSharedParameter.cs
194 lines (151 loc) · 8.63 KB
/
SampleCreateSharedParameter.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
namespace TestWorks
{
internal class SampleCreateSharedParameter
{
public void CreateSampleSharedParameters(Document doc, Application app)
{
Category category = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Walls);
CategorySet categorySet = app.Create.NewCategorySet();
categorySet.Insert(category);
string originalFile = app.SharedParametersFilename;
//********ABSOLUTE FILE PATHS*************
//string tempFile = @"C:\Program Files\Autodesk\Revit 2022\IFC Shared Parameters-RevitIFCBuiltIn_ALL Copy.txt";
//string tempFile = @"C:\Users\MILA\source\repos\TestWorks\Resources\IFC Shared Parameters-RevitIFCBuiltIn_ALL Copy.txt";
//***********EXAMPLE FORMAT FOR RELATIVE FILE PATH*********
//var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
//var iconPath = Path.Combine(outPutDirectory, "Folder\\Img.jpg");
//string icon_path = new Uri(iconPath).LocalPath;
//*******SETTING A RELETIVE FILE PATH**********
var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
var tempFilePath = Path.Combine(outPutDirectory, "Resources\\IFC Shared Parameters-RevitIFCBuiltIn_ALL Copy.txt");
string tempFile = new Uri(tempFilePath).LocalPath;
try
{
app.SharedParametersFilename = tempFile;
DefinitionFile sharedParameterFile = app.OpenSharedParameterFile();
foreach (DefinitionGroup dg in sharedParameterFile.Groups)
{
if (dg.Name == "IFC Properties")
{
ExternalDefinition externalDefinition1 = dg.Definitions.get_Item(
"FunctionalUnitReference") as ExternalDefinition;
using (Transaction t = new Transaction(doc))
{
t.Start("Add Shared Parameter");
//parameter binding
InstanceBinding newIB = app.Create.NewInstanceBinding(categorySet);
//parameter group to IFC properties
doc.ParameterBindings.Insert(externalDefinition1, newIB, BuiltInParameterGroup.PG_IFC);
t.Commit();
}
ExternalDefinition externalDefinition2 = dg.Definitions.get_Item(
"LifeCyclePhase") as ExternalDefinition;
using (Transaction t = new Transaction(doc))
{
t.Start("Add Shared Parameter");
//parameter binding
InstanceBinding newIB = app.Create.NewInstanceBinding(categorySet);
//parameter group to IFC properties
doc.ParameterBindings.Insert(externalDefinition2, newIB, BuiltInParameterGroup.PG_IFC);
t.Commit();
}
ExternalDefinition externalDefinition3 = dg.Definitions.get_Item(
"ExpectedServiceLife") as ExternalDefinition;
using (Transaction t = new Transaction(doc))
{
t.Start("Add Shared Parameter");
//parameter binding
InstanceBinding newIB = app.Create.NewInstanceBinding(categorySet);
//parameter group to IFC properties
doc.ParameterBindings.Insert(externalDefinition3, newIB, BuiltInParameterGroup.PG_IFC);
t.Commit();
}
ExternalDefinition externalDefinition4 = dg.Definitions.get_Item("ClimateChangePerUnit") as ExternalDefinition;
using (Transaction t = new Transaction(doc))
{
t.Start("Add Shared Parameter");
//parameter binding
InstanceBinding newIB = app.Create.NewInstanceBinding(categorySet);
//parameter group to IFC properties
doc.ParameterBindings.Insert(externalDefinition4, newIB, BuiltInParameterGroup.PG_IFC);
t.Commit();
}
ExternalDefinition externalDefinition5 = dg.Definitions.get_Item(
"AtmosphericAcidificationPerUnit") as ExternalDefinition;
using (Transaction t = new Transaction(doc))
{
t.Start("Add Shared Parameter");
//parameter binding
InstanceBinding newIB = app.Create.NewInstanceBinding(categorySet);
//parameter group to IFC properties
doc.ParameterBindings.Insert(externalDefinition5, newIB, BuiltInParameterGroup.PG_IFC);
t.Commit();
}
ExternalDefinition externalDefinition6 = dg.Definitions.get_Item(
"ResourceDepletionPerUnit") as ExternalDefinition;
using (Transaction t = new Transaction(doc))
{
t.Start("Add Shared Parameter");
//parameter binding
InstanceBinding newIB = app.Create.NewInstanceBinding(categorySet);
//parameter group to IFC properties
doc.ParameterBindings.Insert(externalDefinition6, newIB, BuiltInParameterGroup.PG_IFC);
t.Commit();
}
ExternalDefinition externalDefinition7 = dg.Definitions.get_Item(
"StratosphericOzoneLayerDestructionPerUnit") as ExternalDefinition;
using (Transaction t = new Transaction(doc))
{
t.Start("Add Shared Parameter");
//parameter binding
InstanceBinding newIB = app.Create.NewInstanceBinding(categorySet);
//parameter group to IFC properties
doc.ParameterBindings.Insert(externalDefinition7, newIB, BuiltInParameterGroup.PG_IFC);
t.Commit();
}
ExternalDefinition externalDefinition8 = dg.Definitions.get_Item(
"PhotochemicalOzoneFormationPerUnit") as ExternalDefinition;
using (Transaction t = new Transaction(doc))
{
t.Start("Add Shared Parameter");
//parameter binding
InstanceBinding newIB = app.Create.NewInstanceBinding(categorySet);
//parameter group to IFC properties
doc.ParameterBindings.Insert(externalDefinition8, newIB, BuiltInParameterGroup.PG_IFC);
t.Commit();
}
ExternalDefinition externalDefinition9 = dg.Definitions.get_Item(
"EutrophicationPerUnit") as ExternalDefinition;
using (Transaction t = new Transaction(doc))
{
t.Start("Add Shared Parameter");
//parameter binding
InstanceBinding newIB = app.Create.NewInstanceBinding(categorySet);
//parameter group to IFC properties
doc.ParameterBindings.Insert(externalDefinition9, newIB, BuiltInParameterGroup.PG_IFC);
t.Commit();
}
}
}
}
catch { }
finally
{
//reset to original file
app.SharedParametersFilename = originalFile;
}
}
}
}