Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revit_Engine: Improve error message when diffing with duplicate elementIds #1247

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions Revit_Engine/Compute/RevitDiffing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,56 @@ private static Diff Diffing(IEnumerable<object> pastObjects, IEnumerable<object>
}
DiffingConfig diffConfigClone = GetRevitDiffingConfig(rcc);

// Check if input objects all have RevitIdentifiers assigned.
IEnumerable<IBHoMObject> revitBHoMObjects_past = pastObjects.OfType<IBHoMObject>().Where(obj => obj.GetRevitIdentifiers() != null);
IEnumerable<IBHoMObject> revitBHoMObjects_following = followingObjects.OfType<IBHoMObject>().Where(obj => obj.GetRevitIdentifiers() != null);
// Get the past and following RevitIdentifiers fragments.
IEnumerable<RevitIdentifiers> pastIdFragments = pastObjects.OfType<IBHoMObject>().Select(obj => obj.GetRevitIdentifiers()).Where(x => x != null);
pawelbaran marked this conversation as resolved.
Show resolved Hide resolved
IEnumerable<RevitIdentifiers> followingIdFragments = followingObjects.OfType<IBHoMObject>().Select(obj => obj.GetRevitIdentifiers()).Where(x => x != null);

if (revitBHoMObjects_past.Count() != pastObjects.Count())
if (pastIdFragments.Count() != pastObjects.Count())
{
BH.Engine.Base.Compute.RecordError($"Some of the {nameof(pastObjects)} do not have a {nameof(RevitIdentifiers)} fragment attached.");
return null;
}

if (revitBHoMObjects_following.Count() != followingObjects.Count())
if (followingIdFragments.Count() != followingObjects.Count())
{
BH.Engine.Base.Compute.RecordError($"Some of the {nameof(followingObjects)} do not have a {nameof(RevitIdentifiers)} fragment attached.");
return null;
}

// Compute the diffing through DiffWithFragmentId(), which allows us to specify a Fragment and FragmentIdProperty where to find an ID to fragment by.
Diff revitDiff = BH.Engine.Diffing.Compute.DiffWithFragmentId(revitBHoMObjects_past, revitBHoMObjects_following, typeof(RevitIdentifiers), revitIdName, diffConfigClone);
List<string> pastIds, followingIds;

if (revitIdName == nameof(RevitIdentifiers.ElementId))
{
pastIds = pastIdFragments.Select(x => x.ElementId.ToString()).ToList();
followingIds = followingIdFragments.Select(x => x.ElementId.ToString()).ToList();
}
else
{
pastIds = pastIdFragments.Select(x => x.PersistentId.ToString()).ToList();
followingIds = followingIdFragments.Select(x => x.PersistentId.ToString()).ToList();
}

//Check for duplicate ids
bool dupsInPastIds = pastIds.Count != pastIds.Distinct().Count();
bool dupsInFollIds = followingIds.Count != followingIds.Distinct().Count();

if (dupsInPastIds || dupsInFollIds)
{
List<string> messageSubjects = new List<string>();
if (dupsInPastIds) messageSubjects.Add(nameof(pastObjects));
if (dupsInFollIds) messageSubjects.Add(nameof(followingObjects));
string message = $"Some of the {string.Join(" and ", messageSubjects)} contain duplicate {revitIdName}s. ";

if((dupsInPastIds && pastObjects.Any(x => x.GetType().Namespace.Contains("Structure"))) ||
(dupsInFollIds && followingObjects.Any(x => x.GetType().Namespace.Contains("Structure"))))
message += "\nIf trying to diff structural objects, try pulling using the Phsyical discipline rather than Structural discipline, as models containing disjointed floors and walls and/or curved beams lead to one Revit element being converted into multiple structural BHoM elements.";

BH.Engine.Base.Compute.RecordError(message);
return null;
}

//Compute the diffing through DiffWithCustomIds making use of the ids extracted from the objects
Diff revitDiff = BH.Engine.Diffing.Compute.DiffWithCustomIds(pastObjects.ToList(), pastIds, followingObjects.ToList(), followingIds, diffConfigClone);
return revitDiff;
}

Expand Down