Exception: "Input type is not a recognized Revit API type"

Exception: "Input type is not a recognized Revit API type"

Anonymous
Not applicable
1,615 Views
5 Replies
Message 1 of 6

Exception: "Input type is not a recognized Revit API type"

Anonymous
Not applicable

I'm trying to fetch all walls/floors/ceiling/etc using the following code:

Assembly DLL = Assembly.LoadFile("C:/Program Files/Autodesk/Revit 2019/RevitAPI.dll");
Type type = DLL.GetType("Autodesk.Revit.DB." + typeName);
FilteredElementCollector hostObjects = new FilteredElementCollector(Document).OfClass(type);

But i get an exception:

Autodesk.Revit.Exceptions.ArgumentException
  HResult=0x80131500
  Message=Input type(Autodesk.Revit.DB.Wall) is not a recognized Revit API type
Parameter name: type

Any idea why this code doesn't work?

1,616 Views
5 Replies
Replies (5)
Message 2 of 6

atis.sed
Advocate
Advocate

I have stumbled upon same error, did you find out what was the cause ? 

0 Likes
Message 3 of 6

ricaun
Advisor
Advisor

This is a very old post and a quick answer should be used typeof(Wall) to get the type you want:

 

var allWalls = new FilteredElementCollector(Document).OfClass(typeof(Wall));

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 4 of 6

atis.sed
Advocate
Advocate

Hi, 

In my case I want to get Types from StringCollention, add to List, then feed that List into ElementMulticlassFilter:

List<Type> types = new List<Type>();
string message = null;
Assembly DLL = Assembly.LoadFile("C:/Program Files/Autodesk/Revit 2023/RevitAPI.dll");
foreach (string i in Settings1.Default.Family_Types)
{
 Type type = DLL.GetType("Autodesk.Revit.DB." + i);
 message = message + type.ToString() + "\n";
 types.Add(type);
}
TaskDialog.Show("types", message);
ElementMulticlassFilter TypeFilter = new ElementMulticlassFilter(types);

Interestingly, when I print the message, the names for the Types are correct.

In my case they are: 

atissed_0-1667750195366.png

Yet, the ElementMulticlassFilter throws an error:

Autodesk.Revit.Exceptions.ArgumentException: 'Input type(Autodesk.Revit.DB.WallType) is not a recognized Revit API type
Parameter name: type'

 

0 Likes
Message 5 of 6

ricaun
Advisor
Advisor

First, you should never use Assembly.LoadFile if you don't know the consequences.

 

Use this to get the assembly that is already loaded in Revit.exe instead of loading a new one.

Assembly DLL = typeof(Autodesk.Revit.DB.Document).Assembly;

 

or like your example:

 

[Transaction(TransactionMode.Manual)]
public class CommandTypeByName : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elementSet)
    {
        UIApplication uiapp = commandData.Application;
            
        List<Type> types = new List<Type>();
        var Family_Types = new string[] { "WallType", "FloorType", "RoofType", "CeilingType" };
        string message = null;
        Assembly DLL = typeof(Autodesk.Revit.DB.Document).Assembly;
        foreach (string i in Family_Types)
        {
            Type type = DLL.GetType("Autodesk.Revit.DB." + i);
            message = message + type.ToString() + "\n";
            types.Add(type);
        }
        TaskDialog.Show("types", message);
        ElementMulticlassFilter TypeFilter = new ElementMulticlassFilter(types);

        return Result.Succeeded;
    }
}

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 6 of 6

atis.sed
Advocate
Advocate
Thank you, this works perfectly!
0 Likes