Set default setting for YES/NO (project parameter)

Set default setting for YES/NO (project parameter)

benschilders
Advocate Advocate
2,270 Views
8 Replies
Message 1 of 9

Set default setting for YES/NO (project parameter)

benschilders
Advocate
Advocate

I was wondering if it is possible to set a yes/no parameter (used as a area parameter) 
to a default setting when creating new area's.

We use it to define or certain values in a schedule show a parametric calculated or a manual given value. 

Right now when adding a new area, the YES/NO parameters are not defined as YES or NO (greyed out),
i would like to have them as NO by default. 

benschilders_0-1669891763072.png

 



Thanks ! 

pyRevitHave a look at my idea: Material priority Revit quick start guide ┃Please accept soulution if my anwser solved your problem
0 Likes
2,271 Views
8 Replies
Replies (8)
Message 2 of 9

esk0r
Advocate
Advocate

Unfortunately, there isn't a way to set the default state, as far as I know. You can read more about it on this thread: how to project parameters defaulted off - Autodesk Community - Revit Products

 

The only way you could achieve what you want would be to have a custom addin that listens for new area creation events and set the parameter value to No as soon as the new area is created.
It shouldn't be too complicated to code for a decent addin developer.




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.

EESignature


Message 3 of 9

benschilders
Advocate
Advocate

Thanks for your anwser!  

Sadly that is what i feared... 


pyRevitHave a look at my idea: Material priority Revit quick start guide ┃Please accept soulution if my anwser solved your problem
Message 4 of 9

esk0r
Advocate
Advocate

We actually have a similar issue with a Boolean parameter (y/n) we apply to Walls but we just learned to live with it. I have just asked a colleague how tricky it'd be to code a solution to set it to false (no) as soon as a new wall is instanced in the model and he said it should be easy.
I will update this thread if I can get some sample code I can share, so that you can modify for your case (new areas).




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.

EESignature


Message 5 of 9

benschilders
Advocate
Advocate

That would be aswesome ! 

I am allready expirimenting with Python and dynamo so with an example code 
i should be able to impliment it. 

This could also help a lot of other people, 
found quite a lot of diffrent older formums of people asking similar questions like mine. 

But for now i tell my co-workers to just deal with it. 

Again thanks !

pyRevitHave a look at my idea: Material priority Revit quick start guide ┃Please accept soulution if my anwser solved your problem
Message 6 of 9

esk0r
Advocate
Advocate
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.

EESignature


Message 7 of 9

benschilders
Advocate
Advocate

That's so helpfull ! 

Ill try to test this when i have time. 
(wich will probably be a while since i am renovating my home,
and do reasearch in BIM managment mainly as a hobby , because we are a 
pretty small firm.) 

But really thanks for helping ! 
When i test this ill make sure to give an update ! 

Mind to share the ai chatbot , curious to test that as well ?

pyRevitHave a look at my idea: Material priority Revit quick start guide ┃Please accept soulution if my anwser solved your problem
Message 8 of 9

esk0r
Advocate
Advocate

Glad you found it helpful 🙂
The chatbot is chatGPT (https://chat.openai.com/).

 




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.

EESignature


Message 9 of 9

Andreasdraxl
Advocate
Advocate

actually i tested with "-1"  and it works


import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import ElementId

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

def tolist(x):
	if hasattr(x,'__iter__'): return x
	else : return [x]

inv = ElementId.InvalidElementId

items = tolist(IN[0])
param = IN[1]
OUT = []

TransactionManager.Instance.EnsureInTransaction(doc)
for i in items:
	itm = None
	par = i.InternalElement.LookupParameter(param)
	
	if par is not None:
		try:
			par.Set(-1)
			itm = i
		except:
			import traceback
			OUT.append(traceback.format_exc())
	OUT.append(itm)
TransactionManager.Instance.TransactionTaskDone()
Mit freundlichen Grüßen

Andreas
Revit 2022
Dynamo 2.12.0.
Navisworks 2022>IFC4
0 Likes