CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

创建线性尺寸 (.NET)

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

线性尺寸可以对齐或旋转。对齐尺寸的尺寸线平行于延伸线原点所在的线。旋转尺寸的尺寸线与延伸线原点成一定角度放置。

您可以通过创建对象实例来创建线性尺寸。创建线性尺寸的实例后,可以修改文本、文本角度或尺寸线的角度。下图显示了线性尺寸的类型和延伸线原点的位置如何影响尺寸线和文本的角度。AlignedDimensionRotatedDimension

创建对象的实例时,可以选择指定延长线原点、尺寸线的位置、尺寸文本和要应用的标注样式。如果不将任何参数传递到对象构造函数中,则会为对象分配一组默认属性值。AlignedDimensionAlignedDimension

对象构造函数提供与对象构造函数相同的选项,但有一个例外。对象构造函数采用一个附加参数,该参数指定尺寸线旋转的角度。RotatedDimensionAlignedDimensionRotatedDimension

尺寸角拐线

线性维度上的旋钮线不是通过一组属性添加的,而是通过扩展数据 (Xdata) 添加的。负责尺寸角拐线的应用程序名称是ACAD_DSTYLE_DIMJAG_POSITION。下面是需要追加到线性维度的 Xdata 结构的示例。

VB.NET

'' Open the Registered Application table for read
Dim acRegAppTbl As RegAppTable
acRegAppTbl = <transaction>.GetObject(<current_database>.RegAppTableId, _
                                      OpenMode.ForRead)
 
'' Check to see if the app "ACAD_DSTYLE_DIMJAG_POSITION" is
'' registered and if not add it to the RegApp table
If acRegAppTbl.Has("ACAD_DSTYLE_DIMJAG_POSITION") = False Then
    Using acRegAppTblRec As RegAppTableRecord = New RegAppTableRecord()
 
        acRegAppTblRec.Name = "ACAD_DSTYLE_DIMJAG_POSITION"
 
        <transaction>.GetObject(<current_database>.RegAppTableId, OpenMode.ForWrite)
 
        acRegAppTbl.Add(acRegAppTblRec)
        <transaction>.AddNewlyCreatedDBObject(acRegAppTblRec, True)
    End Using
End If
 
'' Create a result buffer to define the Xdata
Dim acResBuf As ResultBuffer = New ResultBuffer()
acResBuf.Add(New TypedValue(DxfCode.ExtendedDataRegAppName, _
                                    "ACAD_DSTYLE_DIMJAG_POSITION"))
acResBuf.Add(New TypedValue(DxfCode.ExtendedDataInteger16, 387))
acResBuf.Add(New TypedValue(DxfCode.ExtendedDataInteger16, 3))
acResBuf.Add(New TypedValue(DxfCode.ExtendedDataInteger16, 389))
acResBuf.Add(New TypedValue(DxfCode.ExtendedDataXCoordinate, _
                                    New Point3d(-1.26985, 3.91514, 0)))
 
'' Attach the Xdata to the dimension
<dimension_object>.XData = acResBuf

C#

// Open the Registered Application table for read
RegAppTable acRegAppTbl;
acRegAppTbl = <transaction>.GetObject(<current_database>.RegAppTableId,
                                      OpenMode.ForRead) as RegAppTable;
 
// Check to see if the app "ACAD_DSTYLE_DIMJAG_POSITION" is
// registered and if not add it to the RegApp table
if (acRegAppTbl.Has("ACAD_DSTYLE_DIMJAG_POSITION") == false)
{
    using (RegAppTableRecord acRegAppTblRec = new RegAppTableRecord())
    {
        acRegAppTblRec.Name = "ACAD_DSTYLE_DIMJAG_POSITION";
 
        <transaction>.GetObject(<current_database>.RegAppTableId, OpenMode.ForWrite);
 
        acRegAppTbl.Add(acRegAppTblRec);
        <transaction>.AddNewlyCreatedDBObject(acRegAppTblRec, true);
    }
}
 
// Create a result buffer to define the Xdata
ResultBuffer acResBuf = new ResultBuffer();
acResBuf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName,
                                         "ACAD_DSTYLE_DIMJAG_POSITION"));
acResBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 387));
acResBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 3));
acResBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 389));
acResBuf.Add(new TypedValue((int)DxfCode.ExtendedDataXCoordinate,
                                         new Point3d(-1.26985, 3.91514, 0)));
 
// Attach the Xdata to the dimension
<dimension_object>.XData = acResBuf;

VBA/ActiveX Code Reference

Dim DataType(0 To 4) As Integer
Dim Data(0 To 4) As Variant
Dim jogPoint(0 To 2) As Double
 
DataType(0) = 1001: Data(0) = "ACAD_DSTYLE_DIMJAG_POSITION"
DataType(1) = 1070: Data(1) = 387
DataType(2) = 1070: Data(2) = 3
DataType(3) = 1070: Data(3) = 389
 
jogPoint(0) = -1.26985: jogPoint(1) = 3.91514: jogPoint(2) = 0#
DataType(4) = 1010: Data(4) = jogPoint
 
' Attach the xdata to the dimension
<dimension_object>.SetXData DataType, Data

Create a rotated linear dimension

This example creates a rotated dimension in Model space.

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("CreateRotatedDimension")> _
Public Sub CreateRotatedDimension()
    '' 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 rotated dimension
        Using acRotDim As RotatedDimension = New RotatedDimension()
            acRotDim.XLine1Point = New Point3d(0, 0, 0)
            acRotDim.XLine2Point = New Point3d(6, 3, 0)
            acRotDim.Rotation = 0.707
            acRotDim.DimLinePoint = New Point3d(0, 5, 0)
            acRotDim.DimensionStyle = acCurDb.Dimstyle

            '' Add the new object to Model space and the transaction
            acBlkTblRec.AppendEntity(acRotDim)
            acTrans.AddNewlyCreatedDBObject(acRotDim, 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("CreateRotatedDimension")]
public static void CreateRotatedDimension()
{
    // 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 rotated dimension
        using (RotatedDimension acRotDim = new RotatedDimension())
        {
            acRotDim.XLine1Point = new Point3d(0, 0, 0);
            acRotDim.XLine2Point = new Point3d(6, 3, 0);
            acRotDim.Rotation = 0.707;
            acRotDim.DimLinePoint = new Point3d(0, 5, 0);
            acRotDim.DimensionStyle = acCurDb.Dimstyle;

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

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

VBA/ActiveX 代码参考

Sub CreateRotatedDimension()
    Dim dimObj As AcadDimRotated
    Dim rotationAngle As Double
    Dim startExtPoint(0 To 2) As Double
    Dim endExtPoint(0 To 2) As Double
    Dim dimLinePoint(0 To 2) As Double
 
    ' Define the dimension
    rotationAngle = 0.707
    startExtPoint(0) = 0: startExtPoint(1) = 0: startExtPoint(2) = 0
    endExtPoint(0) = 6: endExtPoint(1) = 3: endExtPoint(2) = 0
    dimLinePoint(0) = 0: dimLinePoint(1) = 5: dimLinePoint(2) = 0
 
    ' Create the rotated dimension in Model space
    Set dimObj = ThisDrawing.ModelSpace. _
                                 AddDimRotated(startExtPoint, endExtPoint, _
                                               dimLinePoint, rotationAngle)
    ZoomAll
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-19 13:08

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部