Jump to content

Create Leader in UCS


kunekainen

Recommended Posts

Hi there;

 

I am trying to write a plug-in which can create a leader (while you are in UCS) with WCS coordinates text. This is what I did so far:

 

<CommandMethod("AddLeaderAnnotation")> _
   Public Sub AddLeaderAnnotation()
       '' Get the current database
       Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
       Dim acCurDb As Database = acDoc.Database
       Dim acCurEd As Editor = acDoc.Editor

       Dim ucs As Matrix3d = acCurEd.CurrentUserCoordinateSystem
       Dim cs As CoordinateSystem3d = ucs.CoordinateSystem3d

       ' Transform from UCS to WCS
       Dim mat As Matrix3d = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, cs.Origin, cs.Xaxis, _
           cs.Yaxis, cs.Zaxis)

       '' 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)

           Dim opt As New PromptPointOptions(vbLf & "Select Point: ")
           opt.AllowNone = False
           Dim res As PromptPointResult = acCurEd.GetPoint(opt)
           Dim pPt As Point3d = res.Value

           Dim baseWcs As Point3d = pPt.TransformBy(mat)

           res = acCurEd.GetPoint(opt)
           Dim pPt1 As Point3d = res.Value


           '' Create the MText annotation
           Dim acMText As MText = New MText()
           acMText.SetDatabaseDefaults()
           acMText.Contents = baseWcs.X & vbCrLf & baseWcs.Y
           acMText.Attachment = AttachmentPoint.BottomLeft
           acMText.Location = pPt1
           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(pPt)
           acLdr.AppendVertex(pPt1)
           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

 

Problem is, when i'm in UCS, it creates leader in WCS. So it creates leader in different points from i picked. And leader text is not horizontal. How can i create it in UCS like when i create it in WCS.

 

Thanks in advance.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...