Loop through elements and set parameter

Loop through elements and set parameter

Anonymous
Not applicable
1,678 Views
2 Replies
Message 1 of 3

Loop through elements and set parameter

Anonymous
Not applicable

Hello,

 

 

i wanna loop through elements of a chosen Family and set parameters

i have following code, but i get error i can't explain. 

Can please somebody help? Thank in advanced. 

 

//Get application and document objects
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;

//Create collector with the filter Family
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector = collector.OfClass(typeof(Family));

//Get ID from te family with linq-code
var query = from element in collector where element.Name.StartsWith("300_32_ISR_wandopening_houten_binnenkozijn_60WBDBO") select element;
List<Element> fams = query.ToList<Element>();
ElementId famId = fams[0].Id;

//Create FamilySymbolFilter by FamilyID
FamilySymbolFilter filter = new FamilySymbolFilter(famId);

//Create collector filtered by FamilyID and put familysymbols in ICollection : dus alle familytypen in collector plaatsen.
collector = new FilteredElementCollector(doc);
ICollection<Element> Familysymbols = collector.WherePasses(filter).ToElements();

//Create string for testing results
string prompt = "alle deurtypes van familiy 300_32_ISR_wandopening_houten_binnenkozijn_60WBDBO: ";

//Create list to put in FamilySymbol-ID's : dus lijst creeren om alle ID's van de familytypen erin te plaatsen.
List<ElementId> lstFamilySymbolIDs = new List<ElementId>();


//---> Get all FamilySymbol-ID's and put them in a list. : dus alle ID's in de lijst stoppen.
foreach (Element el in Familysymbols)
{
prompt += "\n";
prompt += el.Name + "\n";
prompt += el.Id + "\n";
lstFamilySymbolIDs.Add(el.Id);

Parameter p = el.LookupParameter("Finish");
p.Set("test-waarde");
//el.LookupParameter("MyParam").Set("TestValu​e");
el.get_Parameter("Finish").Set("test-waarde");

0 Likes
1,679 Views
2 Replies
Replies (2)
Message 2 of 3

augusto.goncalves
Alumni
Alumni

Can you point what's the error message and which line of code is happening?

Are you debugging the code?

 

This seems like duplicated of this: http://forums.autodesk.com/t5/revit-api/loop-trough-elements-and-set-parameter/m-p/5919860

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 3 of 3

Revitalizer
Advisor
Advisor

Hi,

 

you try to set a parameter of a FamilySymbol, not of an Element or FamilyInstance.

This means you set a type parameter, not an instance parameter.

 

Are you sure the parameter is really existing with that object ?

 

You may test if p is null before adressing it.

 

 

Revitalizer

 

Edit: I see that ollikat has already explained the context in the duplicated thread.




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes