Problem with parameter value change

Problem with parameter value change

Anonymous
Not applicable
1,218 Views
3 Replies
Message 1 of 4

Problem with parameter value change

Anonymous
Not applicable

I am using Revit 2015. I wanted to create a simple macro which would change the value of 3 parameters in every family type. Unfortunately it is not working as it should, and instead only changes the value of the first parameter on the list. The while loop of the code iterates through all the types in the set, but changes only the values of the first one.

 

I am quite new to the Revit API, so I ask for your kind help in resolving my problem or guiding me to possible solution. Thank you very much in advance.

 

 

		public void ParameterChange()
		{

			Document doc = this.Document;
			using(Transaction tr = new Transaction (doc, "RenameParameter")){
			tr.Start();
			string types = "Types:";
			FamilyManager familyManager = doc.FamilyManager;
			FamilyTypeSet familyTypes = familyManager.Types;
			FamilyTypeSetIterator familyTypesItor = familyTypes.ForwardIterator();
			familyTypesItor.Reset();
			
				while(familyTypesItor.MoveNext()){
				FamilyType familyType = familyTypesItor.Current as FamilyType;
				FamilyParameter par1 = familyManager.get_Parameter("Param1");
				FamilyParameter par2 = familyManager.get_Parameter("Param2");
				FamilyParameter par3 = familyManager.get_Parameter("Param3");
				familyManager.Set(par1, "value1");
				familyManager.Set(par2, "value2");
				familyManager.Set(par3, 10);
				types += "\n" + familyType.Name;
				}
				tr.Commit();
			TaskDialog.Show("Revit",types);
			}
		}

 

0 Likes
Accepted solutions (1)
1,219 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Hi,

 

Try to run the loop in try catch block and run the code in debug mode so as to know the cause.

 

Thanks & Regards

Sanjay Pandey

0 Likes
Message 3 of 4

FAIR59
Advisor
Advisor
Accepted solution

You need to make every familytype the active type, before you can change values.

						FamilyType familyType = familyTypesItor.Current as FamilyType;
						doc.FamilyManager.CurrentType = familyType;
Message 4 of 4

deyannWXBAT
Participant
Participant

God bless you, kind Sir!

0 Likes