CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

创建纵坐标尺寸 (.NET)

2023-1-1 11:47| 发布者: admin| 查看: 373| 评论: 0|来自: AutoCAD

纵坐标或基准尺寸测量从原点(称为基准)到尺寸特征(如零件中的孔)的垂直距离。这些尺寸通过保持特征与基准面的精确偏移来防止错误升级。

纵坐标尺寸由带有引出线的XY纵坐标组成。X 基准纵坐标尺寸测量特征与基准沿X轴的距离。Y 基准纵坐标尺寸沿Y轴测量相同的距离。AutoCAD 使用当前用户坐标系 (UCS) 的原点来确定测量的坐标。使用坐标的绝对值。

尺寸文本与纵坐标引出线对齐,而不考虑当前标注样式定义的方向。您可以接受默认文本,也可以用自己的文本覆盖它。

通过创建对象的实例来创建纵坐标尺寸。创建对象的实例时,其构造函数可以接受一组可选的参数。创建新对象时,可以提供以下参数:OrdinateDimensionOrdinateDimensionOrdinateDimension

  • 使用 X 轴(属性)UsingXAxis
  • 定义点(属性)DefiningPoint
  • 领导端点(属性)LeaderEndPoint
  • 尺寸文本(属性)DimensionText
  • 标注样式(或属性)DimensionStyleNameDimensionStyle

将值传递到对象构造函数时,第一个值是一个布尔标志,它指定尺寸是X 基准还是Y 基准纵坐标尺寸。如果输入,将创建X 基准纵坐标尺寸。如果输入,将创建Y 基准纵坐标尺寸。该属性还可用于指定纵坐标尺寸是X 基准面还是Y 基准面。OrdinateDimensionTRUEFALSEUsingXAxis

创建纵坐标尺寸

本示例在模型空间中创建一个纵坐标尺寸。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("CreateOrdinateDimension")> _
Public Sub CreateOrdinateDimension()
    '' 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 an ordinate dimension
        Using acOrdDim As OrdinateDimension = New OrdinateDimension()
            acOrdDim.UsingXAxis = True
            acOrdDim.DefiningPoint = New Point3d(5, 5, 0)
            acOrdDim.LeaderEndPoint = New Point3d(10, 5, 0)
            acOrdDim.DimensionStyle = acCurDb.Dimstyle

            '' Add the new object to Model space and the transaction
            acBlkTblRec.AppendEntity(acOrdDim)
            acTrans.AddNewlyCreatedDBObject(acOrdDim, 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("CreateOrdinateDimension")]
public static void CreateOrdinateDimension()
{
    // 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 an ordinate dimension
        using (OrdinateDimension acOrdDim = new OrdinateDimension())
        {
            acOrdDim.UsingXAxis = true;
            acOrdDim.DefiningPoint = new Point3d(5, 5, 0);
            acOrdDim.LeaderEndPoint = new Point3d(10, 5, 0);
            acOrdDim.DimensionStyle = acCurDb.Dimstyle;

            // Add the new object to Model space and the transaction
            acBlkTblRec.AppendEntity(acOrdDim);
            acTrans.AddNewlyCreatedDBObject(acOrdDim, true);
        }

        // Commit the changes and dispose of the transaction
        acTrans.Commit();
    }
}

VBA/ActiveX 代码参考

Sub CreateOrdinateDimension()
    Dim dimObj As AcadDimOrdinate
    Dim definingPoint(0 To 2) As Double
    Dim leaderEndPoint(0 To 2) As Double
    Dim useXAxis As Boolean
 
    ' Define the dimension
    definingPoint(0) = 5
    definingPoint(1) = 5
    definingPoint(2) = 0
    leaderEndPoint(0) = 10
    leaderEndPoint(1) = 5
    leaderEndPoint(2) = 0
    useXAxis = True
 
    ' Create an ordinate dimension in model space
    Set dimObj = ThisDrawing.ModelSpace. _
                     AddDimOrdinate(definingPoint, _
                     leaderEndPoint, useXAxis)
 
    ZoomAll
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-27 11:02

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部