幾何公差を記入する(.NET)

幾何公差を記入するには、FeatureControlFrame オブジェクトのインスタンスを作成します。FeatureControlFrame オブジェクトのインスタンスを作成すると、コンストラクタはパラメータのオプション セットを受け取ることができます。新しい FeatureControlFrame オブジェクトを作成するときは、次のパラメータを指定できます。

幾何公差を記入する

次の例は、モデル空間に簡単な幾何公差を記入します。

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)
        Using acFcf As FeatureControlFrame = New FeatureControlFrame()
            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)
        End Using

        '' 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)
        using (FeatureControlFrame acFcf = new FeatureControlFrame())
        {
            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 コード リファレンス

Sub CreateGeometricTolerance()
    Dim toleranceObj As AcadTolerance
    Dim textString As String
    Dim insertionPoint(0 To 2) As Double
    Dim direction(0 To 2) As Double
 
    ' Define the tolerance object
    textString = "{\Fgdt;j}%%v{\Fgdt;n}0.001%%v%%v%%v%%v"
    insertionPoint(0) = 5
    insertionPoint(1) = 5
    insertionPoint(2) = 0
    direction(0) = 1
    direction(1) = 0
    direction(2) = 0
 
    ' Create the tolerance object in model space
    Set toleranceObj = ThisDrawing.ModelSpace. _
                           AddTolerance(textString, insertionPoint, direction)
 
    ZoomAll
End Sub