Macro stopped working

Macro stopped working

Anonymous
Not applicable
464 Views
1 Reply
Message 1 of 2

Macro stopped working

Anonymous
Not applicable

I created this macro for ordering Architecture sheets in Revit 2015. When I first created it there was no errors when i built it, and I was able to use the macro on a project. Now it is no longer working. The error is that 'i' does not exist in the current context. I have used the same structure for another macro for sheets, the only difference is that i am now using .StartsWith() instead of the string equaling a value. Can anyone help?

 

 

   

	using(Transaction trans = new Transaction(doc, "Rename Sheets"))
				{
					FilteredElementCollector sheetView = new  FilteredElementCollector(doc).OfClass(typeof(ViewSheet));
					                                                                    
					trans.Start();
					
					foreach (Element e in sheetView)
					{
						try
						{
							ViewSheet Sheet = e as ViewSheet;
							
							{
								int i=0;
								i++;
									
								Parameter paramsheetlist = Sheet.LookupParameter("Sheet Number");
								string sheetOrders = paramsheetlist.AsString();
								
								if(sheetOrders.StartsWith("AD")){
									i=1;
								}else {
									i=2;}
								}
								Parameter paramArch = Sheet.LookupParameter("Sheet Order");
								paramArch.Set(i);
								
							}
						catch(Exception)
						{
						}
					}
					trans.Commit();

 

0 Likes
Accepted solutions (1)
465 Views
1 Reply
Reply (1)
Message 2 of 2

arnostlobel
Alumni
Alumni
Accepted solution

Oh, how I wish you did not use tabulators in your code 😉

 

Somehow you ended up withn an extra curly bracket between the statements i=2 and paramArch.Set(i) . The latter statement is outside of the scope of the i variable.  (by the way, I suggest yo do not name your variables "i"). paramValue woud read a lot nicer.

Arnošt Löbel
0 Likes