I’m simply trying to create a list of elements that have the same value of a given parameter (i.e. the “SOFiSTiK_Assignment” parameter).
I was able with the LookupParameter method to get the parameter values of all the elements in a certain category (structural rebar); but when I add the “if” condition to create the list of elements that have the parameter value equal to “101-1”, the Python block returns an empty list.
Now that I’m reflecting on my code, I realize that I probably made a conceptual error: with the line
if value == sofistikAssignment:
I am running a list (“value”) against a single String. I am providing a similar simpler example of what I want to get asap. Thank you for your help tho!
I made another script with a similar purpose: to create a list of rebars with the same value of the parameter “Mark”.
I made another “for” loop which should compare each value of the list “value” (list of the parameter values) against the String “mark”. If the test succeeds, the loop should then append the element with the same index to the list “rebars”.
I don’t know how to make that last loop working tho… How do I tell python that I want the element with the same index of the corresponding value’s index? Anyway I will keep trying, suggestions are welcome! Here’s the code:
#Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitApi")
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices import *
from RevitServices.Transactions import TransactionManager as TM
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
TM.Instance.EnsureInTransaction(doc)
allRebars = IN[0]
mark = [1]
elements = UnwrapElement(allRebars)
rebars = []
name = []
value = []
#fa il get del valore del parametro "SOFiSTiK_Assignment" per ogni istanza di rebars
for element in elements:
parametro = element.LookupParameter("Mark")
name.append(parametro.Definition.Name)
value.append(parametro.AsString())
#se è uguale al valore dell'IN[1],crea la lista di rebar con quel sofistik Assignment
for val in value:
if val == mark:
rebars.append(elements)
TM.Instance.TransactionTaskDone()
OUT = name, value, parametro, rebars
You re getting 4 lists as outputs, but ONLY filtering the rebar list. Is that what you want or do you just want the outputs for each list that are in the rebar list with matching parameter value?
Actually I just want a list of rebars whose parameter value (of a certain parameter) matches a specific value. The other outputs are just a test to control what I was doing
Try this. It just puts everything into a single loop and should get you rebar with your value. It only needs the value as an input it get all rebar internally.
rebars = []
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for rebar in FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rebar).WhereElementIsNotElementType().ToElements():
if rebar.LookupParameter("SOFiSTiK_Assignment").AsString() == IN[0]:
rebars.append(rebar)
TransactionManager.Instance.TransactionTaskDone()
OUT = rebars
I don’t have rebar in my project, here is what it would look like in the graph.
Anyway, I tried changing the script in a way more similar to the original one, and I realized the error was in the if condition… Of course your syntax is way more efficient!
FilteredElementCollector(doc) - Using the indicated (current) document / model to get a collection of elements
.OfCategory(BuiltInCategory.OST_Rebar) - This filters the collector to only get things that are of category Rebar. Essentially this is what takes care of the other two nodes you had in the graph.
WhereElementIsNotElementType() - Another filter to make sure you are collecting only instances and not any Rebar Types. The “All Elements of Category” nodes does this internally as well
ToElements() - This just returns all of the elements that pass those filters as Revit Elements. This is what we are using the “for rebar in” loop on
if rebar.LookupParameter(“Mark”).AsString() == IN[0]: - This is just combining what you were already doing over several lines. Gets the parameter values as a string, then compares it to the input. If the input matches it adds it to the rebar list.
outList = [ ]
#familyType = []
for i in UnwrapElement(elements):
for j in i.Parameters:
if j.IsShared and j.Definition.Name == 'Item Number':
parameterValue = i.get_Parameter(j.GUID)
outList.append(parameterValue.AsString())
OUT = outList