Skip to content

Commit

Permalink
Fix(Revit) : retrieving types for mep elements (#2758) (#2768)
Browse files Browse the repository at this point in the history
* fix retrieving types for mep elements

* check for family match if the speckle object has a family prop

---------

Co-authored-by: connorivy <[email protected]>
Co-authored-by: Connor Ivy <[email protected]>
  • Loading branch information
3 people authored Jul 13, 2023
1 parent f7f6f6e commit a9513f6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions ConnectorRevit/RevitSharedResources/Helpers/Categories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static Categories()
public static RevitCategoryInfo Duct { get; } = new(
nameof(Duct),
typeof(DB.Mechanical.Duct),
typeof(DB.Mechanical.FlexDuctType),
typeof(DB.MEPCurveType),
new List<BuiltInCategory>
{
BuiltInCategory.OST_DuctCurves,
Expand Down Expand Up @@ -217,7 +217,7 @@ static Categories()
public static RevitCategoryInfo Pipe { get; } = new(
nameof(Pipe),
typeof(DB.Plumbing.Pipe),
typeof(DB.Plumbing.FlexPipeType),
typeof(DB.MEPCurveType),
new List<BuiltInCategory>
{
BuiltInCategory.OST_PipeCurves,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ApplicationObject DuctToNative(BuiltElements.Duct speckleDuct)
Element duct = null;
if (speckleDuct.baseCurve == null || speckleDuct.baseCurve is Line)
{
var ductType = GetElementType<FlexDuctType>(speckleDuct, appObj, out bool _);
var ductType = GetElementType<DuctType>(speckleDuct, appObj, out bool _);
if (ductType == null)
{
appObj.Update(status: ApplicationObject.State.Failed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,12 @@ out FamilyPlacementType placementType
IList<DB.Parameter> lvlParams = familyInstance.GetParameters("Schedule Level");
if (cutVoidsParams.ElementAtOrDefault(0) != null && cutVoidsParams[0].AsInteger() == 1)
InstanceVoidCutUtils.AddInstanceVoidCut(Doc, CurrentHostElement, familyInstance);
try

if (lvlParams.ElementAtOrDefault(0) != null && level != null)
{
if (lvlParams.ElementAtOrDefault(0) != null)
lvlParams[0].Set(level.Id); // this can be null
lvlParams[0].Set(level.Id);
}
catch { }

break;

case FamilyPlacementType.OneLevelBased when CurrentHostElement is FootPrintRoof roof: // handle receiving mullions on a curtain roof
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ApplicationObject PipeToNative(BuiltElements.Pipe specklePipe)
return appObj;

// get system info
var pipeType = GetElementType<DB.Plumbing.PipeType>(specklePipe, appObj, out bool _);
var pipeType = GetElementType<DB.MEPCurveType>(specklePipe, appObj, out bool _);
if (pipeType == null)
{
appObj.Update(status: ApplicationObject.State.Failed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Speckle.Core.Models;
using OSG = Objects.Structural.Geometry;
using DB = Autodesk.Revit.DB;
using Speckle.Core.Logging;

namespace Objects.Converter.Revit
{
Expand Down Expand Up @@ -140,15 +141,17 @@ private string GetUniqueTypeName(string category, string type)
private T? GetElementType<T>(Base element, ApplicationObject appObj, out bool isExactMatch)
where T : ElementType
{
isExactMatch = false;

var type = GetElementType(element);
if (type == null)
{
throw new ArgumentException($"Could not find valid type of element of type \"{element.speckle_type}\"");
SpeckleLog.Logger.Warning("Could not find valid incoming type for element of type {speckleType}", element.speckle_type);
appObj.Update(logItem: $"Could not find valid incoming type for element of type \"{element.speckle_type}\"");
}
var typeInfo = Revit.AllRevitCategories.GetRevitCategoryInfoStatic<T>(element);
var types = GetOrAddAvailibleTypes(typeInfo);

isExactMatch = false;
if (!types.Any())
{
var name = typeof(T).Name;
Expand All @@ -160,7 +163,17 @@ private string GetUniqueTypeName(string category, string type)
return default;
}

var exactType = ConversionOperationCache.TryGet<ElementType>(GetUniqueTypeName(typeInfo.CategoryName, type));
var family = GetElementFamily(element);

ElementType exactType = null;
if (!string.IsNullOrWhiteSpace(family))
{
exactType = types
.Where(t => string.Equals(t.FamilyName, family, StringComparison.CurrentCultureIgnoreCase))
.Where(t => string.Equals(t.Name, type, StringComparison.CurrentCultureIgnoreCase))
.FirstOrDefault();
}
exactType ??= ConversionOperationCache.TryGet<ElementType>(GetUniqueTypeName(typeInfo.CategoryName, type));

if (exactType != null)
{
Expand All @@ -170,12 +183,10 @@ private string GetUniqueTypeName(string category, string type)
return (T)exactType;
}

var family = (element["family"] as string)?.ToLower();

return GetElementType<T>(element, family, type, types, appObj, out isExactMatch);
}

private T GetElementType<T>(Base element, string? family, string type, IEnumerable<ElementType> types, ApplicationObject appObj, out bool isExactMatch)
private T GetElementType<T>(Base element, string? family, string? type, IEnumerable<ElementType> types, ApplicationObject appObj, out bool isExactMatch)
{
isExactMatch = false;
ElementType match = null;
Expand All @@ -193,7 +204,7 @@ private T GetElementType<T>(Base element, string? family, string type, IEnumerab
}

if (!isExactMatch)
appObj.Update(logItem: $"Missing type. Family: {family} Type: {type}\nType was replaced with: {match.FamilyName}, {match.Name}");
appObj.Update(logItem: $"Missing type. Family: {family ?? "Unknown"} Type: {type ?? "Unknown"}\nType was replaced with: {match.FamilyName}, {match.Name}");

if (match is FamilySymbol fs && !fs.IsActive)
fs.Activate();
Expand Down

0 comments on commit a9513f6

Please sign in to comment.