Exemplo n.º 1
0
        public static DBObjectCollection IntersectSurf(Autodesk.AutoCAD.DatabaseServices.Surface surf1, Autodesk.AutoCAD.DatabaseServices.Surface surf2)
        {
            Brep surfBrep1 = new Brep(surf1);
            Brep surfBrep2 = new Brep(surf2);
            SurfaceSurfaceIntersector ssi = new SurfaceSurfaceIntersector();

            DBObjectCollection dboCol = new DBObjectCollection();

            foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc1 in surfBrep1.Faces)
            {
                ExternalBoundedSurface[]          ebSurfs1 = fc1.GetSurfaceAsTrimmedNurbs();
                Autodesk.AutoCAD.Geometry.Surface sur1     = ebSurfs1[0];
                foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc2 in surfBrep2.Faces)
                {
                    ExternalBoundedSurface[]          ebSurfs2 = fc2.GetSurfaceAsTrimmedNurbs();
                    Autodesk.AutoCAD.Geometry.Surface sur2     = ebSurfs2[0];

                    ssi.Set(sur1, sur2);
                    if (ssi.NumResults < 1)
                    {
                        break;
                    }

                    for (int i = 0; i < ssi.NumResults; i++)
                    {
                        Curve3d c3d = ssi.IntersectCurve(i, true);
                        Curve   crv = GenCurve(c3d);
                        crv.SetDatabaseDefaults();
                        crv.Color = Color.FromRgb(255, 255, 255);
                        dboCol.Add(crv);

                        ////adding for now need instead to conver to single Spline
                        //BlockTableRecord btr = (BlockTableRecord)(trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite));
                        //btr.AppendEntity(crv);
                        //trans.AddNewlyCreatedDBObject(crv, true);
                    }
                }
            }
            return(dboCol);
        }
Exemplo n.º 2
0
        public void SurfInt()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ObjectId ObjID;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    Autodesk.AutoCAD.DatabaseServices.Surface surf1;
                    Autodesk.AutoCAD.DatabaseServices.Surface surf2;

                    SurfGeomConstruct sgc1;
                    SurfGeomConstruct sgc2;

                    PromptEntityOptions peo = new PromptEntityOptions("Select first surface for intersection: ");
                    peo.SetRejectMessage("\nPlease select only a Surface");
                    peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Surface), false);
                    PromptEntityResult per = ed.GetEntity(peo);
                    if (per.Status != PromptStatus.OK)
                    {
                        return;
                    }
                    ObjID = per.ObjectId;
                    surf1 = (Autodesk.AutoCAD.DatabaseServices.Surface)trans.GetObject(ObjID, OpenMode.ForRead, false);
                    surf1.Highlight();

                    peo.Message = "Select intersecting surface: ";
                    per         = ed.GetEntity(peo);
                    if (per.Status != PromptStatus.OK)
                    {
                        return;
                    }
                    surf1.Unhighlight();

                    sgc1  = new SurfGeomConstruct(surf1);
                    ObjID = per.ObjectId;
                    surf2 = (Autodesk.AutoCAD.DatabaseServices.Surface)trans.GetObject(ObjID, OpenMode.ForRead, false);
                    sgc2  = new SurfGeomConstruct(surf2);

                    SurfaceSurfaceIntersector ssi = new SurfaceSurfaceIntersector();
                    //ssi.Set(sgc1.GeomSurf, sgc2.GeomSurf);
                    //int count = ssi.NumResults;
                    //if (count < 1) return;

                    BlockTableRecord btr = (BlockTableRecord)(trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite));

                    //for (int i = 0; i < count; i++)
                    //{
                    //    Curve3d c3d = ssi.IntersectCurve(i, true);
                    //    Curve crv = GenCurve(c3d);
                    //    crv.SetDatabaseDefaults();
                    //    btr.AppendEntity(crv);
                    //    trans.AddNewlyCreatedDBObject(crv, true);
                    //}

                    Brep surfBrep1 = new Brep(surf1);
                    Brep surfBrep2 = new Brep(surf2);
                    foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc1 in surfBrep1.Faces)
                    {
                        ExternalBoundedSurface[]          ebSurfs1 = fc1.GetSurfaceAsTrimmedNurbs();
                        Autodesk.AutoCAD.Geometry.Surface sur1     = ebSurfs1[0];
                        foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc2 in surfBrep2.Faces)
                        {
                            ExternalBoundedSurface[]          ebSurfs2 = fc2.GetSurfaceAsTrimmedNurbs();
                            Autodesk.AutoCAD.Geometry.Surface sur2     = ebSurfs2[0];

                            ssi.Set(sur1, sur2);
                            if (ssi.NumResults < 1)
                            {
                                break;
                            }

                            for (int i = 0; i < ssi.NumResults; i++)
                            {
                                Curve3d c3d = ssi.IntersectCurve(i, true);
                                Curve   crv = GenCurve(c3d);
                                crv.SetDatabaseDefaults();
                                btr.AppendEntity(crv);
                                trans.AddNewlyCreatedDBObject(crv, true);
                            }
                        }
                    }

                    if (ssi != null)
                    {
                        ssi.Dispose();
                    }
                    if (sgc1.GeomSurf != null)
                    {
                        sgc1.GeomSurf.Dispose();
                    }
                    if (sgc2.GeomSurf != null)
                    {
                        sgc2.GeomSurf.Dispose();
                    }
                }
                catch (System.Exception ex)
                {
                    ed.WriteMessage("Error: " + ex.Message);
                }
                finally
                {
                    trans.Commit();
                }
            }
        }