引线关联性
 
 

Leaders are associated with their annotation so that when the annotation moves, the endpoint of the leader moves with it. As you move text and feature control frame annotation, the final leader line segment alternates between attaching to the left side and to the right side of the annotation according to the relation of the annotation to the penultimate (second to last) point of the leader. If the midpoint of the annotation is to the right of the penultimate leader point, then the leader attaches to the right; otherwise, it attaches to the left.

引线与其注释是关联的,因此当注释移动时,引线的端点也会随着移动。在移动文字注释和特征控制框注释时,引线的最后一段会根据注释与引线的倒数第二个点之间的关系,决定是附加到注释的左侧还是右侧。如果注释的中点在引线的倒数第二个点的右侧,则引线将附着到右侧,否则将附着到左侧。  

Removing either object from the drawing using either the Erase, Add (to add a block), or WBlock method will break associativity. If the leader and its annotation are copied together in a single operation, the new copy is associative. If they are copied separately, they will non-associative. If associativity is broken for any reason, for example, by copying only the Leader object or by erasing the annotation, the hook line will be removed from the leader.

使用 Erase、Add(添加块)或 WBlock 方法从图形中删除对象将失去关联性。如果在一次操作中同时复制了引线及其注释,则新的副本也具有关联性。如果分别复制它们,则新的副本没有关联性。如果因为任何原因失去了关联性,例如,只复制了 Leader 对象或删除了注释,基线都将从引线中删除。  

将引线关联到注释

This example creates an MText object. A leader line is then created using the MText object as its annotation.

本例创建 MText 对象。接着使用 MText 对象作为其注释来创建引线。  

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
      Dim acMText As MText = New MText()
      acMText.SetDatabaseDefaults()
      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
      Dim acLdr As Leader = New Leader()
      acLdr.SetDatabaseDefaults()
      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()
  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
      MText acMText = new MText();
      acMText.SetDatabaseDefaults();
      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
      Leader acLdr = new Leader();
      acLdr.SetDatabaseDefaults();
      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 代码参考