-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopy Ebene
234 lines (171 loc) · 9.35 KB
/
Copy Ebene
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
namespace CopyParameters
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class sop_CopyParameters : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Get application and documetn objects
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
Application app = uiapp.Application;
/* Element a = SelectElement(uidoc, doc);
Element e = SelectElement(uidoc, doc);
Parameter parameter = a.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
Parameter parameter1 = a.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT);
Parameter parameter2 = e.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
Parameter parameter3 = e.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT);
string test = parameter1.AsValueString();
string test1 = parameter.AsValueString();
string test2 = test +" Versatz unten - "+ test1;
*/
using (Transaction t = new Transaction(doc, "sop_Wand_CopyEbene"))
{
t.Start("sop_Wand_CopyEbene");
try
{
//*****************Select Element*************************
Reference pickedref = null;
Selection sel = uiapp.ActiveUIDocument.Selection;
WallPickFilter selFilter = new WallPickFilter();
pickedref = sel.PickObject(ObjectType.Element, selFilter, "Please select a wall");
Element elem = uidoc.Document.GetElement(pickedref);
// Ask the user to pick target rooms
WallPickFilter wallPickFilter = new WallPickFilter();
IList<Reference> walls = sel.PickObjects(ObjectType.Element, wallPickFilter, "Wählen Sie Wände die Sie anpassen wollen");
//Reference Targetwall = sel.PickObject(ObjectType.Element, wallPickFilter, "Wählen Sie Wände die Sie anpassen wollen");
//Element TarWall = uidoc.Document.GetElement(Targetwall);
//Get Parameter
Parameter wallBaseOffset = elem.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
Parameter wallTopOffset = elem.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET);
Parameter wallLevelBaseOffset = elem.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT);
Parameter wallLevelTopOffset = elem.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE);
Parameter wallManuellOffset = elem.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
//Get Parameter Target Object
/*
Parameter targetBaseOffset = TarWall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
Parameter targetTopOffset = TarWall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET);
Parameter targetLevelBaseOffset = TarWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT);
Parameter targetLevelTopOffset = TarWall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE);
Parameter targetManuellOffset = TarWall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
*/
//Get Parameter by multiple Object
foreach (Reference w in walls)
{
Element TarWall = uidoc.Document.GetElement(w);
Parameter targetBaseOffset = TarWall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
Parameter targetTopOffset = TarWall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET);
Parameter targetLevelBaseOffset = TarWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT);
Parameter targetLevelTopOffset = TarWall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE);
Parameter targetManuellOffset = TarWall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
targetBaseOffset.SetValueString(GetParameterValue(wallBaseOffset));
targetLevelBaseOffset.Set(wallLevelBaseOffset.AsElementId());
targetLevelTopOffset.Set(wallLevelTopOffset.AsElementId());
if (targetManuellOffset.UserModifiable == false)
{
targetManuellOffset.SetValueString(GetParameterValue(wallManuellOffset));
}
else
{
targetTopOffset.SetValueString(GetParameterValue(wallTopOffset));
}
}
//Set parameter
/*
targetBaseOffset.SetValueString(GetParameterValue(wallBaseOffset));
targetLevelBaseOffset.Set(wallLevelBaseOffset.AsElementId());
targetLevelTopOffset.Set(wallLevelTopOffset.AsElementId());
if (targetManuellOffset.UserModifiable == false)
{
targetManuellOffset.SetValueString(GetParameterValue(wallManuellOffset));
}
else
{
targetTopOffset.SetValueString(GetParameterValue(wallTopOffset));
}
*/
/*
string result = "Neue Werte : " + "\n";
result += "Versatz Unten - " + targetBaseOffset.AsValueString() + "\n";
result += "Versatz Unten - " + targetBaseOffset.AsValueString() + "\n";
result += "Versatz Oben - " + targetTopOffset.AsValueString() + "\n";
result += "Abhängigkeit unten - " + targetLevelBaseOffset.AsValueString() + "\n";
result += "Abhängigkeit Oben - " + targetLevelTopOffset.AsValueString() + "\n";
result += "Nicht verknüpfte Höhe - " + targetManuellOffset.AsValueString() + "\n";
*/
//parameter.Set(GetParameterValue(parameter));
//parameter3.SetValueString(GetParameterValue(parameter1));
//ShowBasicElementInfo(TarWall);
//TaskDialog.Show("New Value", result);
}
catch ( Autodesk.Revit.Exceptions.OperationCanceledException )
{
return Result.Cancelled;
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
t.Commit();
//TaskDialog.Show("New Value", GetParameterValue();
//TaskDialog.Show("New Value", GetParameterValue(parameter2));
//TaskDialog.Show("New Value", GetParameterValue(parameter3));
}
return Result.Succeeded;
}
//*****************GetParameterValue*************************
public string GetParameterValue(Parameter parameter)
{
switch (parameter.StorageType)
{
case StorageType.Double:
//get value with unit, AsDouble() can got vale without unit
return parameter.AsValueString();
case StorageType.ElementId:
return parameter.AsElementId().IntegerValue.ToString();
case StorageType.Integer:
//get value with unit, AsInteger() can got value without unit
return parameter.AsValueString();
case StorageType.None:
return parameter.AsValueString();
case StorageType.String:
return parameter.AsString();
default:
return "";
}
}
// **********************Selection Filter***************************
public class WallPickFilter : ISelectionFilter
{
public bool AllowElement(Element e)
{
return e.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_Walls);
}
public bool AllowReference(Reference r, XYZ p)
{
return false;
}
}
public void PickObj(Document doc, IList<Reference> walls)
{
foreach (Reference w in walls)
{
Element wall = doc.GetElement(w);
}
}
}
}