Message 1 of 8
Copy Parameters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I need to copy the content from the source parameters to the target parameters. I've written the following code, but it doesn't seem to work correctly. Can anyone help me figure out what's wrong?
[Transaction(TransactionMode.Manual)]
public class CopyParameterCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Autodesk.Revit.DB.Document doc = uiApp.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<Element> allElements = collector.WhereElementIsNotElementType().ToElements();
using (Transaction trans = new Transaction(doc, "Copiar parámetro "))
{
trans.Start();
foreach (Element element in allElements)
{
Parameter sourceParam = element.LookupParameter("Source-parameter");
Parameter targetParam = element.LookupParameter("Target-parameter");
if (sourceParam != null && sourceParam.HasValue)
{
string sourceValue = sourceParam.AsString();
if (targetParam != null && targetParam.StorageType == StorageType.String)
{
targetParam.Set(sourceValue);
sourceParam.Set(string.Empty);
}
}
}
trans.Commit();
}
return Result.Succeeded;
}
}
Developer Advocacy and Support +