Message 1 of 1
Getting Error - "There is circular chain of references among the Highlighted element"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Everyone,
I am copying the elements from DocA to DocC and also from DocB to DocC.
// 1️ Copy elements from docA (no offset)
XYZ offsetA = new XYZ(0, 0, 0);
CopyElementsWithOffset(docA, docC, offsetA, comparisonRows);
// 2️ Copy elements from docB (with offset)
BoundingBoxXYZ bboxA = ElementComparer.GetTotalBoundingBox(docA);
double offsetX = bboxA.Max.X - bboxA.Min.X + 10;
//double offsetX = 10000;
XYZ offsetB = new XYZ(offsetX, 0, 0);
CopyElementsWithOffset(docB, docC, offsetB, comparisonRows, highlightMap, newColor, modColor, activeView);
and using below code line of code I am copying
private static void CopyElementsWithOffset(
Document srcDoc,
Document targetDoc,
XYZ offset,
List<ComparisonRow> comparisonRows,
Dictionary<string, string> highlightMap = null,
OverrideGraphicSettings newColor = null,
OverrideGraphicSettings modColor = null,
View activeView = null)
{
using (Transaction tx = new Transaction(targetDoc, "Copy Elements With Offset"))
{
tx.Start();
var elems = new FilteredElementCollector(srcDoc)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.Where(e => e.Category != null && e.Category.CategoryType == CategoryType.Model);
foreach (Element elem in elems)
{
try
{
GeometryElement geo = elem.get_Geometry(new Options());
if (geo == null) continue;
List<GeometryObject> transformed = new List<GeometryObject>();
foreach (GeometryObject g in geo)
{
if (g is Solid solid && solid.Volume > 0)
transformed.Add(SolidUtils.CreateTransformed(solid, Transform.CreateTranslation(offset)));
else if (g is Mesh mesh)
transformed.Add(mesh.get_Transformed(Transform.CreateTranslation(offset)));
else if (g is GeometryInstance gi)
{
foreach (GeometryObject ig in gi.GetInstanceGeometry())
{
if (ig is Solid s2 && s2.Volume > 0)
transformed.Add(SolidUtils.CreateTransformed(s2, Transform.CreateTranslation(offset)));
else if (ig is Mesh m2)
transformed.Add(m2.get_Transformed(Transform.CreateTranslation(offset)));
}
}
}
if (transformed.Count == 0) continue;
// ✅ Use same category as source
//ElementId catId = elem.Category != null ? elem.Category.Id : new ElementId(BuiltInCategory.OST_GenericModel);
ElementId catId = new ElementId(BuiltInCategory.OST_GenericModel);
DirectShape ds = DirectShape.CreateElement(targetDoc, catId);
ds.SetShape(transformed);
// ✅ Find corresponding comparison row
ComparisonRow row = comparisonRows
.FirstOrDefault(r =>
r.Host?.ElementId == elem.Id ||
r.Linked?.ElementId == elem.Id);
if (row != null)
{
// If element comes from docA → use host parameters
if (row.Host != null && row.Host.ElementId == elem.Id)
ApplyStoredParameters(ds, row.Host.Parameters);
// If element comes from docB → use linked parameters
if (row.Linked != null && row.Linked.ElementId == elem.Id)
ApplyStoredParameters(ds, row.Linked.Parameters);
}
// ✅ Highlight only for linked (docB) new/modified
if (highlightMap != null && activeView != null && row?.Linked != null)
{
if (!string.IsNullOrEmpty(row.Linked.IFCGuid) &&
highlightMap.TryGetValue(row.Linked.IFCGuid, out string status))
{
activeView.SetElementOverrides(ds.Id, status == "New" ? newColor : modColor);
CopyAndHighlightHelper.LastCopiedElementStatusMap[ds.Id] = (row.Linked.IFCGuid, status);
}
}
}
catch
{
continue;
}
}
tx.Commit();
}
}
Does some elements are linked/constraint to old document i.e. (DocA and DocB).
or the issue is different?