Applying a number value to a parameter based on Text parameter

Applying a number value to a parameter based on Text parameter

Anonymous
Not applicable
584 Views
5 Replies
Message 1 of 6

Applying a number value to a parameter based on Text parameter

Anonymous
Not applicable

I wrote a code for 2015 that should apply a number based on the discipline that is applied to the sheet, and i want to have a version that applies to  sheets only or to sheets and placeholders. I cant get the place holder filter to work correctly. If i remove the placeholder and just run the build it builds a solution but causes an error when running within revit. Any suggestions would be appreciated
  

public void Ranking()
		{
				Document doc = this.Document;
				
				FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).WhereElementIsNotElementType(ViewSheet.IsPlaceholder);
					
					using(Transaction trans = new Transaction(doc, "DrawinglistRank"))
					{
						trans.Start();
						int sheetRank = 1;
							foreach (Element Sheet in collector){
								
								Parameter paramDisc = Sheet.LookupParameter("SHEET DISCIPLINE");
								string sheetDiscipline = paramDisc.AsString();
								
								sheetRank+=1;
								
							
								if(sheetDiscipline == "GENERAL"){
							      sheetRank=1;
							     }else if(sheetDiscipline == "ARCHITECTURAL"){
							      sheetRank=2;
							     }else if(sheetDiscipline == "MECHANICAL"){
							       sheetRank=3;
							     }else if(sheetDiscipline == "ELECTRICAL"){
							       sheetRank=4;
							     }else if(sheetDiscipline == "PLUMBING"){
							        sheetRank=5;
							     }else if(sheetDiscipline == "FIREPROTECTION"){
									sheetRank=6;}
								
								Parameter paramRank = Sheet.LookupParameter("DISCIPLINE_RANK");
								paramRank.Set(sheetRank);
								

					trans.Commit(); 
				}
			
				TaskDialog.Show("Drawing List", "Drawing List Has Been Updated");
				}
		}

 

0 Likes
585 Views
5 Replies
Replies (5)
Message 2 of 6

Aaron.Lu
Autodesk
Autodesk

Dear William,

 

I could not find a overload of method WhereElementIsNotElementType takes any argument, its signature is:

    public FilteredElementCollector WhereElementIsNotElementType()

 

So how can you call it like that?

 

and a second question is: what is the error message of it?

 

It will help if you can provide some simple rvt file, so I can try it quickly from my side.

 

thanks.

 



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 6

Anonymous
Not applicable

I am new to programming and have been struggling with the filtering. If you look at the attached model you will see where i have been looking at trying to filter out the placeholders. You will also see another attempt that i am trying to filter out place holders that i deleted.

 

Also attached is a screen shot of the error message that I am recieving when the placeholder part of ranking has been eliminated and a build has been created and run

 

 

Thanks

0 Likes
Message 4 of 6

Aaron.Lu
Autodesk
Autodesk

Ok, I see,

 

You need to using transaction, and put your code between transaction.Start() and transaction.Commit()

 

Transaction transaction = new Transaction(doc, "Ranking");
transaction.Start();
try
{
    //Put your code in here
    transaction.Commit();
}
catch (Exception ex)
{
    transaction.RollBack();
}

 



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 5 of 6

Anonymous
Not applicable

I performed the update that you  suggested. I am getting the following error, which doesn't make any sense because i have not done anything to the namespace definition. I attached the file.

 

 

Type or namespace definition, or end-of-file expected (CS1022) - C:\Users\wwydock\AppData\Local\Temp\{1EE1541D-793D-471D-8EA2-3BA5F3B6D61B}\Revit\DocHookups6656\2123717888\Concatenate\Source\Concatenate\ThisDocument.cs:180

 

0 Likes
Message 6 of 6

Aaron.Lu
Autodesk
Autodesk

Dear William,

 

This is more like a programming problem rather than RevitAPI's. I highly recommend you using Visual studio to create test projects and using AddInManager to load the dll which is the compiled output. Because Visual studio will give you more tips and better editing features. I looked carefully in your code, there are some places missing the brackets "}" while some places have too many. also finaly clause can't follow with Exception, but "catch" does.

 

Your code:

 

        TaskDialog.Show("Drawing List", "Drawing List Has Been Updated");
        }
          finally (Exception ex)
          {
            transaction.RollBack();
          }
        }
      }
    }
  }
}

 

The correct code should be:

 

        TaskDialog.Show("Drawing List", "Drawing List Has Been Updated");
        }}
          finally
          {
            transaction.RollBack();
          }
        }
      } 
}

 

 



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes