- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello !! I am working on transferring Project Parameters from a source document to a target document, it worked and showed me in the log that they have been successfully transferred but in the target document when I looked up Manage > project parameters none of these parameters were shown there, so what it could be the problem. and here is a part of the code. Thanks
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
namespace TransferProjectParameter
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
Document sourceDoc = uiapp.ActiveUIDocument.Document;
// Collect all project parameters from the source document
BindingMap sourceBindingMap = sourceDoc.ParameterBindings;
DefinitionBindingMapIterator iter = sourceBindingMap.ForwardIterator();
iter.Reset();
List<Definition> projectParameters = new List<Definition>();
while (iter.MoveNext())
{
Definition def = iter.Key;
projectParameters.Add(def);
}
Document targetDoc = null;
foreach (Document doc in uiapp.Application.Documents)
{
if (!doc.Equals(sourceDoc))
{
targetDoc = doc;
break;
}
}
using (Transaction trans = new Transaction(targetDoc, "Copy Project Parameters"))
{
trans.Start();
BindingMap targetBindingMap = targetDoc.ParameterBindings;
foreach (var def in projectParameters)
{
Binding binding = sourceBindingMap.get_Item(def);
if (binding != null)
{
// Get the parameter group
BuiltInParameterGroup paramGroup = (def as InternalDefinition)?.ParameterGroup ?? BuiltInParameterGroup.INVALID;
// Add the definition with the same binding to the target document
targetBindingMap.Insert(def, binding, paramGroup);
}
}
trans.Commit();
}
List<string> projectParameterNames = projectParameters.Select(p => p.Name).ToList();
TaskDialog.Show("Transfer Project Parameters", $"{projectParameters.Count} project parameters transferred successfully.");
return Result.Succeeded;
}
}
}
Solved! Go to Solution.
Link copied