CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

领导者关联性 (.NET)

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

引线与其注释相关联,因此当引线移动时,引线的端点也会随之移动。移动文本和特征控制框注释时,根据注释与引线倒数第二个(倒数第二个)点的关系,最终引出线段在附着到注释的左侧和右侧之间交替。如果注释的中点在倒数第二个引线点的右侧,则引线附加到右侧;否则,它将附加到左侧。

使用(添加块)或方法从图形中删除任一对象将破坏关联性。如果在单个操作中将引线及其注释一起复制,则新副本是关联的。如果单独复制它们,它们将是非关联的。如果关联性因任何原因(例如,仅复制 Leader 对象或擦除注释)而中断,则钩线将从引线中删除。EraseAddWBlock

将引线关联到批注

此示例创建一个对象。然后使用对象作为其注释创建引出线。MTextMText

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("AddLeaderAnnotation")> _
Public Sub AddLeaderAnnotation()
    '' 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 MText annotation
        Using acMText As MText = New MText()
            acMText.Contents = "Hello, World."
            acMText.Location = New Point3d(5, 5, 0)
            acMText.Width = 2

            '' Add the new object to Model space and the transaction
            acBlkTblRec.AppendEntity(acMText)
            acTrans.AddNewlyCreatedDBObject(acMText, True)

            '' Create the leader with annotation
            Using acLdr As Leader = New Leader()
                acLdr.AppendVertex(New Point3d(0, 0, 0))
                acLdr.AppendVertex(New Point3d(4, 4, 0))
                acLdr.AppendVertex(New Point3d(4, 5, 0))
                acLdr.HasArrowHead = True

                '' Add the new object to Model space and the transaction
                acBlkTblRec.AppendEntity(acLdr)
                acTrans.AddNewlyCreatedDBObject(acLdr, True)

                '' Attach the annotation after the leader object is added
                acLdr.Annotation = acMText.ObjectId
                acLdr.EvaluateLeader()
            End Using
        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("AddLeaderAnnotation")]
public static void AddLeaderAnnotation()
{
    // 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 MText annotation
        using (MText acMText = new MText())
        {
            acMText.Contents = "Hello, World.";
            acMText.Location = new Point3d(5, 5, 0);
            acMText.Width = 2;

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

            // Create the leader with annotation
            using (Leader acLdr = new Leader())
            {
                acLdr.AppendVertex(new Point3d(0, 0, 0));
                acLdr.AppendVertex(new Point3d(4, 4, 0));
                acLdr.AppendVertex(new Point3d(4, 5, 0));
                acLdr.HasArrowHead = true;

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

                // Attach the annotation after the leader object is added
                acLdr.Annotation = acMText.ObjectId;
                acLdr.EvaluateLeader();
            }
        }

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

VBA/ActiveX Code Reference

Sub AddLeaderAnnotation()
    Dim leaderObj As AcadLeader
    Dim mtextObj As AcadMText
    Dim points(0 To 8) As Double
    Dim insertionPoint(0 To 2) As Double
    Dim width As Double
    Dim leaderType As Integer
    Dim annotationObject As Object
    Dim textString As String, msg As String
 
    ' Create the MText object in model space
    textString = "Hello, World."
    insertionPoint(0) = 5
    insertionPoint(1) = 5
    insertionPoint(2) = 0
    width = 2
    Set mtextObj = ThisDrawing.ModelSpace. _
                       AddMText(insertionPoint, width, textString)
 
    ' Data for Leader
    points(0) = 0: points(1) = 0: points(2) = 0
    points(3) = 4: points(4) = 4: points(5) = 0
    points(6) = 4: points(7) = 5: points(8) = 0
    leaderType = acLineWithArrow
 
    ' Create the Leader object in model space and associate
    ' the MText object with the leader
    Set annotationObject = mtextObj
    Set leaderObj = ThisDrawing.ModelSpace. _
                        AddLeader(points, annotationObject, leaderType)
 
    ZoomAll
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-19 14:36

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部