Quick update: I tried that new AI chatbot to autogenerate some code for this issue and showed the results to one of our addin developers. He said: "not bad"
🙂 I have not tested this but it should be a good start to create the custom addin you need.
"Here is some example code for a Revit add-in that automatically sets a boolean project parameter to be True when a new instance of an object with that parameter is created in the model, using an event listener:
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace MyRevitAddin
{
public class SetBooleanParameterToTrue : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// Get the current document
Document doc = commandData.Application.ActiveUIDocument.Document;
// Define the name of the boolean project parameter that we want to set to True
string parameterName = "MyBooleanParameter";
// Create an event handler for the "Elements Created" event
EventHandler<ElementsCreatedEventArgs> onElementsCreated = (sender, args) =>
{
// Iterate over the newly created elements
foreach (ElementId elementId in args.GetAddedElementIds())
{
Element element = doc.GetElement(elementId);
// Check if the element has the parameter we are looking for
if (element.HasParameter(parameterName))
{
// Get the parameter
Parameter parameter = element.get_Parameter(parameterName);
// Check if the parameter is a boolean
if (parameter.StorageType == StorageType.Integer && parameter.Definition.ParameterType == ParameterType.YesNo)
{
// Set the parameter to True
parameter.Set(1);
}
}
}
};
// Register the event handler with the "Elements Created" event
doc.Application.DocumentChanged += onElementsCreated;
// Return a success result
return Result.Succeeded;
}
}
}
This code defines an event handler for the Elements Created event, which is triggered whenever new elements are created in the document. The event handler iterates over the newly created elements and sets the boolean parameter to True if it is found on the element. The event handler is then registered with the Elements Created event so that it is called whenever the event is triggered."
Rene Pellicer Garcia
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
