trouble getting a list of WallType objects that are usable

trouble getting a list of WallType objects that are usable

Anonymous
Not applicable
1,081 Views
12 Replies
Message 1 of 13

trouble getting a list of WallType objects that are usable

Anonymous
Not applicable

Im really thrashing about attempting to get a collection of WallTypes in the revit api. I dont want a list of WallTypes that are currently in the document (assume that the document is a blank template) im trying to use the Wall.Create(Document, Curve, ElementId, ElementId, Double, Double, Boolean, Boolean) method to place a wall of a given WallType (which of course has an ElementId) and I cannot seem to get a proper container of the things. FilteredElementCollector does not return anything useful! assistance appreciated.

0 Likes
1,082 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable
0 Likes
Message 3 of 13

dantartaglia8696
Advocate
Advocate

It's been a while since I've extracted wall types. The below came from an older app:

 

FilteredElementCollector collector = new FilteredElementCollector(Command.doc);

FilteredElementIterator itor = collector.OfClass(typeof(Autodesk.Revit.DB.HostObjAttributes)).GetElementIterator();

// Reset the iterator

itor.Reset();

// Iterate through each family

while (itor.MoveNext())

{

intCntr++;

// Get the current family

Autodesk.Revit.DB.HostObjAttributes oSysFamilySymbol = itor.Current as Autodesk.Revit.DB.HostObjAttributes;

if (oSysFamilySymbol != null)

{

 

}

}

 

0 Likes
Message 4 of 13

Anonymous
Not applicable

neither of these works in revit 2016.

here's a snippet:

UIApplication uiApp = commandData.Application;
var doc = uiApp.ActiveUIDocument.Document;
var collector = new FilteredElementCollector( doc );
var familyCollector = collector
    //.OfClass( typeof( HostObjAttributes ) )
    .OfCategory( BuiltInCategory.OST_Walls )
    .ToElementIds()
    .Where( x => x != ElementId.InvalidElementId );

if ( familyCollector.Count == 0 ) {
message = "no family loaded!";
return Result.Failed;
}

 

both of these examples have this snippet only error out.

0 Likes
Message 5 of 13

Anonymous
Not applicable

I should probably mention that i need the elementIds of valid walls are needed as I'm using

Wall.Create(Document, Curve, ElementId, ElementId, Double, Double, Boolean, Boolean)

method

 

0 Likes
Message 6 of 13

dantartaglia8696
Advocate
Advocate

The below retrieves WallType objects in my Revit 2016 model:

 

private List<WallType> WallTypesGet(Document doc)

{

List<WallType> oWallTypes = new List<WallType>();

try

{

FilteredElementCollector collector = new FilteredElementCollector(doc);

FilteredElementIterator itor = collector.OfClass(typeof(Autodesk.Revit.DB.HostObjAttributes)).GetElementIterator();

// Reset the iterator

itor.Reset();

// Iterate through each family

while (itor.MoveNext())

{

Autodesk.Revit.DB.HostObjAttributes oSystemFamilies =

itor.Current as Autodesk.Revit.DB.HostObjAttributes;

if (oSystemFamilies == null)

continue;

// Get the family's category

Category oCategory = oSystemFamilies.Category;

// Process if the category is found

if (oCategory != null)

{

if (oCategory.Name == "Walls")

{

WallType oWallType = oSystemFamilies as WallType;

if (oWallType != null)

oWallTypes.Add(oWallType);

}

}

}

return oWallTypes;

}

catch(Exception ex)

{

MessageBox.Show(ex.Message);

return oWallTypes = new List<WallType>();

}

}

 

0 Likes
Message 7 of 13

Anonymous
Not applicable

testing that oWallTypes isn't empty (using the Count property of collections) fails. so this method doesn't work either.

0 Likes
Message 8 of 13

Anonymous
Not applicable

you know it would probably help if i mention that I'm using revit 2016 R2 😛 sorry if that caused any confusion.

0 Likes
Message 9 of 13

dantartaglia8696
Advocate
Advocate

Hi James,

 

The method I sent you works correctly for me in R2. What error(s) are you getting in the catch()? Can you send a simple example of one of your RVTs that you have the error in?

0 Likes
Message 10 of 13

dantartaglia8696
Advocate
Advocate

Here is a recording of my code working for me.

0 Likes
Message 11 of 13

Anonymous
Not applicable

odd, I'm essentailly embedding your code into a loop that should put up walls from baked values.

 

var collector = new FilteredElementCollector();
List<WallType> oWallTypes = new List<WallType>();
try {
var itor = collector
    .OfClass( typeof( HostObjAttributes ) )
    .GetElementIterator();

    // Reset the iterator
    itor.Reset();

    // Iterate through each family
    while ( itor.MoveNext() ) {
        HostObjAttributes oSystemFamilies
            = itor.Current as HostObjAttributes;

        if ( oSystemFamilies == null ) {
            continue;
        }

        // Get the family's category
        Category oCategory = oSystemFamilies.Category;

        // Process if the category is found
        if ( oCategory != null ) {
            if ( oCategory.Name == "Walls" ) {
                WallType oWallType = oSystemFamilies as WallType;
                if ( oWallType != null ) {
                    oWallTypes.Add( oWallType );
                }
            }
        }
    }
} catch ( Exception ex ) {
    message = ex.Message;
    return Result.Failed;
}

if ( oWallTypes.Count == 0 ) {
    message = "no wall families loaded!";
    return Result.Failed;
}
0 Likes
Message 12 of 13

dantartaglia8696
Advocate
Advocate

Does my code work for you unaltered?

0 Likes
Message 13 of 13

Anonymous
Not applicable

yes, but I'm not sure why my code doesn't work. let me get back to you in a bit.

0 Likes