FilteredElementCollector

FilteredElementCollector

Ryan
Enthusiast Enthusiast
3,002 Views
3 Replies
Message 1 of 4

FilteredElementCollector

Ryan
Enthusiast
Enthusiast

Hi all, 

 

New to the API(and c# for that matter) but im getting somewhere with it.

 

 

I'm trying to get the FilteredElementCollector to filter sheets by SheetNumber.Contains(//user input//) which works just fine. But i would like it to add 1 sheet that will always be the same number "100-Temp".

 

I've tried everything to get the collector to add this sheet to its collection with the user defiend string (match) but my Sheet Set (which the code creates) never has this sheet added to it.

 

     Document doc = this.ActiveUIDocument.Document;

    // create a new ViewSet - add views to it that match the desired criteria
    ViewSet myViewSet = new ViewSet();

   
    string match = Microsoft.VisualBasic.Interaction.InputBox("Enter Unit Number""Create Sheet Set""");
string temp = "100-Temp";

   if (match =="")
   {
        TaskDialog.Show("Error""Cancelled or no information entered.");
        return;
   }
     
     foreach (ViewSheet vs in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>()
           
            .Where(q =>  q.SheetNumber.Contains(match ) ))
           //  .Where (q => q.SheetNumber.Equals(temp)))
    {
        myViewSet.Insert(vs );
    }

 

 

Thanks!

 

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

Ryan
Enthusiast
Enthusiast
Nevermind,

I solved it right after i posted.

0 Likes
Message 3 of 4

jeremytammik
Autodesk
Autodesk

Dear Ryabn

 

Optimally, you could (1) post your solution as well, and (2) mark it as the solution to the issue, so your whole thread will be classed as solved.

 

Thank you!

 

Cheers, 

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 4 of 4

Ryan
Enthusiast
Enthusiast
Accepted solution

Thanks Jeremy,

 

I was trying to figure out how to delete the post entirely, but i can do as you suggest.

 

To solve it, i just created another FilteredElementCollecter that only finds the single sheet i want, then adds it to the same Collection set.

 

 

 	foreach (ViewSheet vt in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>()
           
                .Where (q => q.SheetNumber.Equals("100-Temp")))
    {
    	myViewSet.Insert(vt );
    	
    }   
   

    	
 	foreach (ViewSheet vs in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>()
           
            .Where(q =>  q.SheetNumber.Contains(match) && q.ViewName !=("11x17")))
            //.OrderBy (x => numeric(x.SheetNumber) ))
 
            
    {
    	myViewSet.Insert(vs );
    }