您可以通过创建对象的实例来创建几何公差。创建对象的实例时,其构造函数可以接受一组可选的参数。创建新对象时,可以提供以下参数:FeatureControlFrameFeatureControlFrameFeatureControlFrame
创建几何公差此示例在模型空间中创建一个简单的几何公差。 VB.NETImports 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 相关概念父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:15
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.