
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello.
In the process, an exception was thrown.
Autodesk.Revit.Exceptions.InternalException:
'A managed exception was thrown by Revit or by one of its external applications.'
Whenever the combo box item is changed, the source below is processed.
var rooms = new System.Collections.Concurrent.ConcurrentBag<RevitRoomModel>();
new FilteredElementCollector(Document).WhereElementIsNotElementType()
.WherePasses(new ElementCategoryFilter(BuiltInCategory.OST_Rooms))
.Cast<Room>()
.Where(x => x.Area > 0 && x.LevelId.ToString().Equals(selectedLevel.LevelId))
.AsParallel()
.ForAll(x =>
{
if (x.GetParameters($"RoomProperty").FirstOrDefault() is Parameter parameter)
{
var value = parameter.StorageType.Equals(StorageType.String) ? parameter.AsString() : parameter.AsValueString();
if (string.IsNullOrWhiteSpace(value) == false || string.IsNullOrEmpty(value) == false)
{
rooms.Add(new RevitRoomModel { Element = x, RoomProperty = value });
}
else
{
rooms.Add(new RevitRoomModel { Element = x, RoomProperty = value });
}
}
else
{
rooms.Add(new RevitRoomModel { Element = x, RoomProperty = "x" });
}
});
var wallsRun = new System.Collections.Concurrent.ConcurrentBag<RevitWallModel>();
new FilteredElementCollector(Document).WhereElementIsNotElementType()
.WherePasses(new ElementClassFilter(typeof(Wall)))
.Cast<Wall>()
.Where(x => x.LevelId.ToString().Equals(selectedLevel.LevelId))
.AsParallel()
.ForAll(x => wallsRun.Add(new RevitWallModel { Element = x }));
foreach (var wall in wallsRun)
{
if (wall.Element.GetParameters($"WallProperty").FirstOrDefault() is Parameter parameter)
{
var value = parameter.StorageType.Equals(StorageType.String) ? parameter.AsString() : parameter.AsValueString();
if (string.IsNullOrWhiteSpace(value) == false || string.IsNullOrEmpty(value) == false)
{
wall.WallProperty = value;
}
else
{
wall.WallProperty = value;
}
}
else
{
wall.WallProperty = "x";
}
}
var wallsWrong = new System.Collections.Concurrent.ConcurrentBag<RevitWallModel>();
new FilteredElementCollector(Document).WhereElementIsNotElementType()
.WherePasses(new ElementClassFilter(typeof(Wall)))
.Cast<Wall>()
.Where(x => x.LevelId.ToString().Equals(selectedLevel.LevelId))
.AsParallel()
.ForAll(x =>
{
if (x.GetParameters($"WallProperty").FirstOrDefault() is Parameter parameter) // ◀ ※ InternalException ※
{
var value = parameter.StorageType.Equals(StorageType.String) ? parameter.AsString() : parameter.AsValueString();
if (string.IsNullOrWhiteSpace(value) == false || string.IsNullOrEmpty(value) == false)
{
wallsWrong.Add(new RevitWallModel { Element = x, WallProperty = value });
}
else
{
wallsWrong.Add(new RevitWallModel { Element = x, WallProperty = value });
}
}
else
{
wallsWrong.Add(new RevitWallModel { Element = x, WallProperty = "x" });
}
});
The first 'Room' works fine.
In the case of Room and 'wallWrong', the logic is the same, but an exception was thrown.
(The room works fine and the wall fails. Why!?)
Please take a look at the second 'wallRun' and the third 'wallWrong' case.
It is subtly different and works fine in the case of 'wallsRun', but an exception was throws in the case of 'wallsWrong'.
Here I don't think I need a transaction. It just loads the parameters and checks them.
Why is this exception was thrown and is there a solution?
Thanks.
Solved! Go to Solution.