Select element and check solid does Intersect then Join

Select element and check solid does Intersect then Join

manhgt214
Enthusiast Enthusiast
178 Views
0 Replies
Message 1 of 1

Select element and check solid does Intersect then Join

manhgt214
Enthusiast
Enthusiast

I tried use menthod JoinGeometryUtils but show that error,
Please help me. Thank you in advance.

manhgt214_0-1708827074900.png

 

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();
            }

 

0 Likes
179 Views
0 Replies
Replies (0)