创建形位公差
 
 

You create a geometric tolerance by creating an instance of a FeatureControlFrame object. When you create an instance of a FeatureControlFrame object, its constructor can accept an optional set of parameters. The following parameters can be supplied when you create a new FeatureControlFrame object:

用户可以通过创建一个 FeatureControlFrame 对象的实例来创建形位公差。当创建一个 FeatureControlFrame 对象的实例时,它的构造函数可以接受一组可选的参数。当创建新的 FeatureControlFrame 对象时下列参数可以提供给它。

创建一个形位公司

This example creates a simple geometric tolerance in Model space.

下面示例在模型空间中创建一个单一的形位公差。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("CreateGeometricTolerance")> _
Public Sub CreateGeometricTolerance()
  '' 获得当前数据库  Get the current 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 the Geometric Tolerance (Feature Control Frame)
      Dim acFcf As FeatureControlFrame = New FeatureControlFrame()
      acFcf.SetDatabaseDefaults()
      acFcf.Text = "{\Fgdt;j}%%v{\Fgdt;n}0.001%%v%%v%%v%%v"
      acFcf.Location = New Point3d(5, 5, 0)
 
      '' 添加新对象到模型空间和事务中   Add the new object to Model space and the transaction
      acBlkTblRec.AppendEntity(acFcf)
      acTrans.AddNewlyCreatedDBObject(acFcf, True)
 
      '' 提交修改并销毁事务  Commit the changes and dispose of the transaction
      acTrans.Commit()
  End Using
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
 
[CommandMethod("CreateGeometricTolerance")]
public static void CreateGeometricTolerance()
{
  // 获得当前数据库  Get the current 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 the Geometric Tolerance (Feature Control Frame)
      FeatureControlFrame acFcf = new FeatureControlFrame();
      acFcf.SetDatabaseDefaults();
      acFcf.Text = "{\\Fgdt;j}%%v{\\Fgdt;n}0.001%%v%%v%%v%%v";
      acFcf.Location = new Point3d(5, 5, 0);
 
      // 添加新对象到模型空间和事务中   Add the new object to Model space and the transaction
      acBlkTblRec.AppendEntity(acFcf);
      acTrans.AddNewlyCreatedDBObject(acFcf, true);
 
      // 提交修改并销毁事务  Commit the changes and dispose of the transaction
      acTrans.Commit();
  }
}
VBA/ActiveX 代码参考