创建组合面域
 
 

You can create composite regions by subtracting, combining, or finding the intersection of regions or 3D solids. You can then extrude or revolve composite regions to create complex solids. To create a composite region, use the BooleanOperation method.

可以通过查找面域或三维实体的差集、并集或交集来创建组合面域。然后可以拉伸或旋转组合面域以创建复杂的实体。要创建组合面域,请使用 BooleanOperation 方法。

减去面域

When you subtract one region from another, you call the BooleanOperation method from the first region. This is the region from which you want to subtract. For example, to calculate how much carpeting is needed for a floor plan, call the BooleanOperation method from the outer boundary of the floor space and use the non-carpeted areas, such as pillars and counters, as the object in the Boolean parameter list.

当从某个面域减去另一个面域时,需要从第一个面域调用 BooleanOperation 方法。这是要从中减去其他面域的的面域。例如,要计算地板需要铺多少地毯,需要从地板空间的外部边界调用 BooleanOperation 方法,并将不需要铺地毯的区域如柱子和柜台作为 Boolean 参数列表中的对象。

并集面域

To unite regions, call the BooleanOperation method and use the constant BooleanOperationType.BoolUnite for the operation instead of BooleanOperationType.BoolSubtract. You can combine regions in any order to unite them.

要获得并集面域,可以调用 BooleanOperation 方法并在操作中输入常量 BooleanOperationType.BoolUnite,而不是输入 BooleanOperationType.BoolSubtract。用户可以按任意次序组合面域来形成并集面域。

查找两个面域的交集

To find the intersection of two regions, use the constant BooleanOperationType.BoolIntersect. You can combine regions in any order to intersect them.

要查找两个面域的交集,请使用常量 BooleanOperationType.BoolIntersect。可以按任意次序组合面域来计算这些面域的交集。

创建组合面域

The following example creates two regions from two circles and then subtracts the smaller region from the large one to create a wheel.

本例从两个圆创建两个面域,然后用大的面域减去小的面域以创建一个轮形图。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("CreateCompositeRegions")> _
Public Sub CreateCompositeRegions()
  '' 获得当前文档和数据库   Get the current document and database
  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  Dim acCurDb As Database = acDoc.Database
 
  ''启动一个事务   Start a transaction
  Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
 
      '' 以只读方式打开块表   Open the Block table for read
      Dim acBlkTbl As BlockTable
      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
 
      '' 以写方式打开模型空间块表记录   Open the Block table record Model space for write
      Dim acBlkTblRec As BlockTableRecord
      acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                      OpenMode.ForWrite)
 
      '' 在内存中创建两个圆   Create two in memory circles
      Dim acCirc1 As Circle = New Circle()
      acCirc1.SetDatabaseDefaults()
      acCirc1.Center = New Point3d(4, 4, 0)
      acCirc1.Radius = 2
 
      Dim acCirc2 As Circle = New Circle()
      acCirc2.SetDatabaseDefaults()
      acCirc2.Center = New Point3d(4, 4, 0)
      acCirc2.Radius = 1
 
      '' 添加圆到对象数组中   Adds the circle to an object array
      Dim acDBObjColl As DBObjectCollection = New DBObjectCollection()
      acDBObjColl.Add(acCirc1)
      acDBObjColl.Add(acCirc2)
 
      '' 根据每一个闭合环计算面域   Calculate the regions based on each closed loop
      Dim myRegionColl As DBObjectCollection = New DBObjectCollection()
      myRegionColl = Region.CreateFromCurves(acDBObjColl)
      Dim acRegion1 As Region = myRegionColl(0)
      Dim acRegion2 As Region = myRegionColl(1)
 
      '' 从面域2减去面域1   Subtract region 1 from region 2
      If acRegion1.Area > acRegion2.Area Then
          '' 从大的一个中减去小的面域   Subtract the smaller region from the larger one
          acRegion1.BooleanOperation(BooleanOperationType.BoolSubtract, acRegion2)
          acRegion2.Dispose()
 
          '' 添加遇终的面域到数据库中   Add the final region to the database
          acBlkTblRec.AppendEntity(acRegion1)
          acTrans.AddNewlyCreatedDBObject(acRegion1, True)
      Else
          '' 从大的一个中减去小的面域   Subtract the smaller region from the larger one
          acRegion2.BooleanOperation(BooleanOperationType.BoolSubtract, acRegion1)
          acRegion1.Dispose()
 
          '' 添加遇终的面域到数据库中   Add the final region to the database
          acBlkTblRec.AppendEntity(acRegion2)
          acTrans.AddNewlyCreatedDBObject(acRegion2, True)
      End If
 
      '' 不追加对象到数据库中直接从内存中销毁    Dispose of the in memory objects not appended to the database
      acCirc1.Dispose()
      acCirc2.Dispose()
 
      '' 保存新对象到数据库中   Save the new object to the database
      acTrans.Commit()
  End Using
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
 
[CommandMethod("CreateCompositeRegions")]
public static void CreateCompositeRegions()
{
  // 获得当前文档和数据库   Get the current document and database
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
  Database acCurDb = acDoc.Database;
 
  // 启动一个事务  Start a transaction
  using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  {
      // 以只读方式打开块表   Open the Block table for read
      BlockTable acBlkTbl;
      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                   OpenMode.ForRead) as BlockTable;
 
      // 以写方式打开模型空间块表记录   Open the Block table record Model space for write
      BlockTableRecord acBlkTblRec;
      acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                      OpenMode.ForWrite) as BlockTableRecord;
 
      // 在内存中创建两个圆   Create two in memory circles
      Circle acCirc1 = new Circle();
      acCirc1.SetDatabaseDefaults();
      acCirc1.Center = new Point3d(4, 4, 0);
      acCirc1.Radius = 2;
 
      Circle acCirc2 = new Circle();
      acCirc2.SetDatabaseDefaults();
      acCirc2.Center = new Point3d(4, 4, 0);
      acCirc2.Radius = 1;
 
      // 添加圆到对象数组中   Adds the circle to an object array
      DBObjectCollection acDBObjColl = new DBObjectCollection();
      acDBObjColl.Add(acCirc1);
      acDBObjColl.Add(acCirc2);
 
      // 根据每一个闭合环计算面域   Calculate the regions based on each closed loop
      DBObjectCollection myRegionColl = new DBObjectCollection();
      myRegionColl = Region.CreateFromCurves(acDBObjColl);
      Region acRegion1 = myRegionColl[0] as Region;
      Region acRegion2 = myRegionColl[1] as Region;
 
      // 从面域2减去面域1   Subtract region 1 from region 2
      if (acRegion1.Area > acRegion2.Area)
      {
          // 从大的一个中减去小的面域   Subtract the smaller region from the larger one
          acRegion1.BooleanOperation(BooleanOperationType.BoolSubtract, acRegion2);
          acRegion2.Dispose();
 
          // 添加遇终的面域到数据库中   Add the final region to the database
          acBlkTblRec.AppendEntity(acRegion1);
          acTrans.AddNewlyCreatedDBObject(acRegion1, true);
      }
      else
      {
          // 从大的一个中减去小的面域   Subtract the smaller region from the larger one
          acRegion2.BooleanOperation(BooleanOperationType.BoolSubtract, acRegion1);
          acRegion1.Dispose();
 
          // 添加遇终的面域到数据库中   Add the final region to the database
          acBlkTblRec.AppendEntity(acRegion2);
          acTrans.AddNewlyCreatedDBObject(acRegion2, true);
      }
 
      // 不追加对象到数据库中直接从内存中销毁    Dispose of the in memory objects not appended to the database
      acCirc1.Dispose();
      acCirc2.Dispose();
 
      // 保存新对象到数据库中   Save the new object to the database
      acTrans.Commit();
  }
}
VBA/ActiveX 代码参考