CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

重写维度文本 (.NET)

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

可以使用属性替换显示的维度值。使用此属性可以完全替换维度的显示值,也可以向值追加文本。要在覆盖维度文本中表示测量值,请在文本中使用字符串“<>”。DimensionText

修改尺寸文本

本示例向值追加一些文本,以便同时显示字符串和维度值。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("OverrideDimensionText")> _
Public Sub OverrideDimensionText()
    '' 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 aligned dimension
        Using acAliDim As AlignedDimension = New AlignedDimension()
            acAliDim.XLine1Point = New Point3d(5, 3, 0)
            acAliDim.XLine2Point = New Point3d(10, 3, 0)
            acAliDim.DimLinePoint = New Point3d(7.5, 5, 0)
            acAliDim.DimensionStyle = acCurDb.Dimstyle

            '' Override the dimension text
            acAliDim.DimensionText = "The value is <>"

            '' Add the new object to Model space and the transaction
            acBlkTblRec.AppendEntity(acAliDim)
            acTrans.AddNewlyCreatedDBObject(acAliDim, 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("OverrideDimensionText")]
public static void OverrideDimensionText()
{
    // 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 aligned dimension
        using (AlignedDimension acAliDim = new AlignedDimension())
        {
            acAliDim.XLine1Point = new Point3d(5, 3, 0);
            acAliDim.XLine2Point = new Point3d(10, 3, 0);
            acAliDim.DimLinePoint = new Point3d(7.5, 5, 0);
            acAliDim.DimensionStyle = acCurDb.Dimstyle;

            // Override the dimension text
            acAliDim.DimensionText = "The value is <>";

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

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

VBA/ActiveX 代码参考

Sub OverrideDimensionText()
    Dim dimObj As AcadDimAligned
    Dim point1(0 To 2) As Double
    Dim point2(0 To 2) As Double
    Dim location(0 To 2) As Double
 
    ' Define the dimension
    point1(0) = 5#: point1(1) = 3#: point1(2) = 0#
    point2(0) = 10#: point2(1) = 3#: point2(2) = 0#
    location(0) = 7.5: location(1) = 5#: location(2) = 0#
 
    ' Create an aligned dimension object in model space
    Set dimObj = ThisDrawing.ModelSpace. _
                     AddDimAligned(point1, point2, location)
 
    ' Change the text string for the dimension
    dimObj.TextOverride = "The value is <>"
    dimObj.Update
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-19 12:01

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部