How to set check box parameter of an element using python

Hi all, I am trying to set the structural parameter check/uncheck of a structural wall element.

Please let me know how to check and uncheck parameter of an element ? somehow I manage to get the parameter details but getting difficulty in setting the parameter like checkbox.

The code goes as below:

import clr

import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')

import System
from System.Collections.Generic import *

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

#Preparing input from dynamo to revit
ele = UnwrapElement(IN[0])

#Do some action in a Transaction

TransactionManager.Instance.EnsureInTransaction(doc)

floors=FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors).WhereElementIsElementType().ToElements()


struct=ele.LookupParameter("Structural")
Getparam=struct.AsInteger()

setstru=Getparam.Set(0)

TransactionManager.Instance.TransactionTaskDone()

OUT = Getparam

Hello,

you need a for loopto interate thrue your objects.

KR

Andreas

1 Like

Okay Thanks I’ll try

2022-04-12_09h11_11
I have trouble with the lookup… where did you get it.

can you not use just a buildin enumeration?

i am not shure :slight_smile: … maybe some users are more into it.

Hi @shashank.baganeACM,

A couple of things in your initial code:
In your Revit image, you are previewing a wall, but your code says floors. Small detail I guess, since both have the Structural parameter, but just to be consistent :slight_smile:

In your collector, you are using the method WhereElementIsElementType() which will only give you types. It needs to be WhereElementIsNotElementType(), if you are collecting instances.

Whenever it’s possible to use BuiltInParameters, I’d recommend going with that, since it will provide you with a more stable code:

import clr

clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import *

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

#Do some action in a Transaction
walls=FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()

output = []

for i in walls:
	struct= i.get_Parameter(BuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT)
	TransactionManager.Instance.EnsureInTransaction(doc)
	setstru=struct.Set(1)
	TransactionManager.Instance.TransactionTaskDone()
	output.append(setstru)
	
OUT = output

One last detail: To set a Boolean to True, it’s 1 and not 0 :slight_smile:

3 Likes

Use the Snoop Objects tool to find the BIP:

3 Likes

Nice @MartinSpence …og ha en god påske :wink:

Tak Søren, og i lige måde :slight_smile:

Thanks @MartinSpence I really appreciate that. It works

1 Like