-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopyParameters
160 lines (131 loc) · 6.08 KB
/
CopyParameters
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
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;
using (Transaction t = new Transaction(doc, "sop_CopyParameters"))
{
t.Start("sop_Wand_CopyParameters");
try
{
//*****************Select Element*************************
Reference pickedref = null;
Selection sel = uiapp.ActiveUIDocument.Selection;
pickedref = sel.PickObject(ObjectType.Element, "Please select an element");
Element elem = uidoc.Document.GetElement(pickedref);
// pick target elements
IList<Reference> refSet = sel.PickObjects(ObjectType.Element, "Wählen Sie Elementen");
//Get and Set Parameter
string Dialogmessage = "";
IList<Parameter> paramSet = elem.GetOrderedParameters();
foreach (Parameter param in paramSet)
{
if (param.Definition.Name.Contains("sop_"))
{
string name = param.Definition.Name;
string val = GetParameterValue(param);
double DoubleVal = GetParameterDoubleValue(param);
int id = param.Id.IntegerValue;
//int Count = 0;
try
{
foreach (Reference r in refSet)
{
Element elemSet = uidoc.Document.GetElement(r);
Parameter targetParam = elemSet.get_Parameter((BuiltInParameter)id);
string targetname = targetParam.Definition.Name;
string targetval = GetParameterValue(targetParam);
targetParam.Set(val);
targetParam.Set(DoubleVal);
//Count++;
//Dialogmessage += Count + ".Element - " + targetname + " = " + val + "\n";
}
Dialogmessage += name+"\n";
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
continue;
}
catch(Exception ex)
{
continue;
}
}
}
TaskDialog.Show("Neue Werte", Dialogmessage);
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
return Result.Cancelled;
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
t.Commit();
}
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 "";
}
}
public double GetParameterDoubleValue(Parameter parameter)
{
switch (parameter.StorageType)
{
case StorageType.Double:
//get value with unit, AsDouble() can got vale without unit
return parameter.AsDouble();
case StorageType.ElementId:
return parameter.AsElementId().IntegerValue;
case StorageType.Integer:
//get value with unit, AsInteger() can got value without unit
return parameter.AsInteger();
case StorageType.None:
return parameter.AsDouble();
case StorageType.String:
return parameter.AsDouble();
default:
return 0;
}
}
}
}