Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FilteredElementCollector - Modelled in Place elements

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
BrentBurgess1980
1899 Views, 15 Replies

FilteredElementCollector - Modelled in Place elements

Hi All,

 

Trying to get all walls, including any modelled in place walls to perform actions over them.

 

I have the below code

 FilteredElementCollector allWalls = new FilteredElementCollector(document).OfClass(typeof(Wall));
                    foreach (Wall w in allWalls)
                        {
                        //Do Stuff
                        }

 

This only seems to pick up the "native walls" and not any modelled in place walls.

 

Have I missed something or not understood  the FilteredElementCollector?

 

Thanks,

 

Brent 

15 REPLIES 15
Message 2 of 16

In-place walls are actually of class FamilyInstance.

 

To identify if it is in-place you'll have to get it's FamilySymbol via Element.GetTypeId then from that get it's Family via FamilySymbol.Family. On the Family class there is then the property .IsInPlace.

 

It is probably easier to go in the other direction i.e. filter for the Family class of category Wall with IsInPlace = True. Then from each of those you can get the FamilySymbols via Family.GetFamilySymbolIds. Finally from that list you can filter for FamilyInstances in the document with a TypeId contained in that list looking at FamilyInstance.GetTypeId.

 

Note there is no context for editing in-place within the API so you can only move/look at or delete it etc.

 

Message 3 of 16

Thanks for the info @RPTHOMAS108 

 

I have tried to take a look at this and have got this far

 

 foreach (Family family in new FilteredElementCollector(document ).OfClass(typeof(Family)).Cast<Family>())
                        {
                        if(family.IsInPlace)
                            {
                            ISet<ElementId> elem =  family.GetFamilySymbolIds();
                            foreach(ElementId id in elem)
                                {
                                Element el = document.GetElement(id);
                                //Not sure what to do here
                                }

                            }
                        }

 

 

On the line //Not sure what to do here, I can see the below when I put a watch on el, however I can't access it in the intellisense to get Familiy Category and Name ("Walls"). 

BrentBurgess1980_2-1608037687839.png

 

Is this on the right track?

 

Thanks

 

 

 

Message 4 of 16

It's an awkward connection to make because you are looking for instances and the property you are after is on the Family class. There are likely other ways but the below represents one way.

 

Important to note that the ElementCategoryFilter doesn't appear to work with Family class. I suspect because the Family class has Family.FamilyCategory property and it's .Category property appears to be null.

 

 

public Result TObj136(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
		{

			if (commandData.Application.ActiveUIDocument == null)
				return Result.Cancelled;
			Document IntDoc = commandData.Application.ActiveUIDocument.Document;

			ElementClassFilter ECF1 = new ElementClassFilter(typeof(Family));
			//Dim ECF2 As New ElementCategoryFilter(BuiltInCategory.OST_Walls)
			//Category filter not working with family class
			//Likely because Family has Family.FamilyCategory property and category property is null
			//Dim LandF As New LogicalAndFilter(ECF1, ECF2)
			Category WallsCat = Category.GetCategory(IntDoc, BuiltInCategory.OST_Walls);
			FilteredElementCollector FEC = new FilteredElementCollector(IntDoc);
			List<Family> Els = FEC.WherePasses(ECF1).ToElements().Cast<Family>().Where(j => j.FamilyCategory.Id == WallsCat.Id && j.IsInPlace).ToList();

			List<ElementId> SymbIds = new List<ElementId>();
			for (int i = 0; i <= Els.Count - 1; i++)
			{
				SymbIds.AddRange(Els[i].GetFamilySymbolIds());
			}
			FilteredElementCollector FEC2 = new FilteredElementCollector(IntDoc);
			ElementClassFilter ECF = new ElementClassFilter(typeof(FamilyInstance));
			List<Element> FInstInPlace = FEC2.WherePasses(ECF).ToElements().Where(j => SymbIds.Contains(j.GetTypeId())).ToList();

			for (int i = 0; i <= FInstInPlace.Count - 1; i++)
			{
				Debug.WriteLine(FInstInPlace[i].Name);
			}

			return Result.Succeeded;

		}

 

 

 

Message 5 of 16

hi

 

i tried to collect by Class, but it dont collect Model Inplace instances.  But then, if you try to collect by Category, it will work.

 

 

Message 6 of 16
RPTHOMAS108
in reply to: Yien_Chao

I found them with ElementClassFilter but they are not of a Wall class (for this example).

Message 7 of 16
Yien_Chao
in reply to: RPTHOMAS108

I believe the models inplace are NOT based on the builtIn Classes (which are host object for most), but under Category class (which is an APIobject).

Message 8 of 16
RPTHOMAS108
in reply to: Yien_Chao

No, they are FamilyInstances and they have a category from BuiltInCategory (similar to all objects deriving from Element).

 

The code I used above with ElementClassFilter finds them because I use it to look for FamilyInstance.

 

Category derives from APIObject because it is not an Element (Element inherits directly from Object).

Message 9 of 16
Yien_Chao
in reply to: RPTHOMAS108

ok. here a sample of 2 floors. one with model in place. collecting with

Class won't work. but with Category, yes.

 

2020-12-16_11-38-58.jpg

Message 10 of 16
RPTHOMAS108
in reply to: Yien_Chao

It doesn't work because you are probably looking for Floor class and it is a FamilyInstance!!! So to say you can't find an in-place family with an ElementClassFilter is not correct.

 

Respectfully, you don't have to argue with me you just have to see for yourself what it is with RevitLookup.

 

The ElementClassFilter works perfectly fine with in-place families (so long as you use it correctly i.e. to find the class type it is). I can see where your confusion may be coming from but Dynamo is not the RevitAPI. Dynamo sometimes (likely not in this case however) has similarly named but dissimilar objects built over the API. Your Python code block likely would work if the ElementClassFilter is from DB namespace and you use it to find FamilyInstances.

 

Message 11 of 16
RPTHOMAS108
in reply to: RPTHOMAS108

To put it a slightly better way:

 

If you use ElementClassFilter(GetType(FamilyInstance)) coupled with ElementCategoryFilter(OST_Floors) then likely that is the best way of finding only Floors modelled in-pace.

 

If you use ElementClassFilter(GetType(FamilyInstance)) coupled with ElementCategoryFilter(OST_Walls) then likely that is the best way of finding only Walls modelled in-pace.

 

If however you use just the category filter you will get both the in-place ones and the non in-place ones. So perhaps this conversation is useful to OP.

Message 12 of 16


My point was just if you cant collect with wall or floor classes, try with builtin category.
I see you show a way to do it with class and familyinstance. Good!

 

No need to argue here.

Message 13 of 16

Thanks again @RPTHOMAS108 . Still trying the get my head around it all, however when I try FInstInPlace[i].Pinned = true, it throws an error. Now I am assuming that this is because we are trying to pin the family instance and not the modelled in place element?

Message 14 of 16

The FamilyInstance is the modelled in-place element. You have to describe the exception you get, perhaps you've not started a transaction etc. You can pin them in the UI so should be able to with the API.

 

@Yien_Chao understood, thanks.

Message 15 of 16

@RPTHOMAS108 Yeah I do have it in a transaction, and the error I get doesn't seem to be overly helpful

Element cannot be pinned or unpinned.

BrentBurgess1980_0-1608166498708.png

 

Message 16 of 16

@RPTHOMAS108 Ignore that..... The walls were part of a model group. It seems to work when I ungroup

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community