Message 1 of 1
Select element and check solid does Intersect then Join
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I tried use menthod JoinGeometryUtils but show that error,
Please help me. Thank you in advance.
using (Transaction t = new Transaction(doc,"join"))
{
t.Start();
foreach (Element i in pic)
{
foreach (Element j in pic)
{
List<Solid> s10 = new List<Solid>();
List<Solid> s20 = new List<Solid>();
if (i.Id.ToString() != j.Id.ToString())
{
GeometryElement geomElem = i.get_Geometry(options);
foreach (GeometryObject geomObj in geomElem)
{
if (geomObj is Solid)
{
Solid solid = (Solid)geomObj;
if (solid.Faces.Size > 0 && solid.Volume > 0.0)
{
s10.Add(solid);
}
}
else if (geomObj is GeometryInstance)
{
GeometryInstance geomInst = (GeometryInstance)geomObj;
GeometryElement instGeomElem = geomInst.GetInstanceGeometry();
foreach (GeometryObject instGeomObj in instGeomElem)
{
if (instGeomObj is Solid)
{
s10.Add((Solid)instGeomObj);
//Solid s1 = (Solid)instGeomObj;
}
}
}
}
GeometryElement geomElem2 = j.get_Geometry(options);
foreach (GeometryObject geomObj in geomElem2)
{
if (geomObj is Solid)
{
Solid solid2 = (Solid)geomObj;
if (solid2.Faces.Size > 0 && solid2.Volume > 0.0)
{
s20.Add(solid2);
}
}
else if (geomObj is GeometryInstance)
{
GeometryInstance geomInst = (GeometryInstance)geomObj;
GeometryElement instGeomElem = geomInst.GetInstanceGeometry();
foreach (GeometryObject instGeomObj in instGeomElem)
{
if (instGeomObj is Solid)
{
s20.Add((Solid)instGeomObj);
//Solid s2 = (Solid)instGeomObj;
}
}
}
}
Solid s1 = s10[0];
Solid s2 = s20[0];
Solid unionSolid = BooleanOperationsUtils.ExecuteBooleanOperation(s1, s2, BooleanOperationsType.Union);
Solid interSolid = BooleanOperationsUtils.ExecuteBooleanOperation(s1, s2, BooleanOperationsType.Intersect);
double sumArea = Math.Round(Math.Abs(s1.SurfaceArea + s2.SurfaceArea), 5);
double sumFaces = Math.Abs(s1.Faces.Size + s2.Faces.Size);
double unionArea = Math.Round(Math.Abs(unionSolid.SurfaceArea), 5);
double unionFaces = Math.Abs(unionSolid.Faces.Size);
if (sumArea > unionArea && sumFaces > unionFaces && interSolid.Volume > 0.00001)
{
//TaskDialog.Show("debug", "intersecting");
Autodesk.Revit.DB.JoinGeometryUtils.JoinGeometry(doc, i, j);
}
else if (sumArea > unionArea && sumFaces > unionFaces && interSolid.Volume < 0.00001)
{
//TaskDialog.Show("debug", "touching");
Autodesk.Revit.DB.JoinGeometryUtils.JoinGeometry(doc, i, j);
}
}
}
}
t.Commit();
}