Hi All,
I have tried to create a leader with simple code like below. After invoking the command, Leader line is there but I can not see the arrowhead. Can any body help me in this regard that why arrowhead is not created?
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("CreateLeader")> _
PublicSubCreateleader()
Dim acDoc AsDocument = Application.DocumentManager.MdiActiveDocument
Dim acCurDb AsDatabase= acDoc.Database
Using acTrans AsTransaction= acCurDb.TransactionManager.StartTransaction()
Dim acBlkTbl AsBlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
Dim acBlkTblRec AsBlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(
BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim acLdr AsLeader = NewLeader()
acLdr.AppendVertex(NewPoint3d(2, 2, 0))
acLdr.AppendVertex(NewPoint3d(4, 4, 0))
acLdr.AppendVertex(NewPoint3d(4, 5, 0))
acLdr.HasArrowHead = True
acBlkTblRec.AppendEntity(acLdr)
acTrans.AddNewlyCreatedDBObject(acLdr, True)
acTrans.Commit()
End Using
End Sub
After creating the line, I have tried to see the properties of the leader. In Misc,'Type' is always 'Line with no arrow' and I cannot force it 'Line with arrow'. I am using VS 2010, ACAD 2011 and framework 3.5.
Please help me in this regard.
Zakir
Solved! Go to Solution.
Solved by Hallex. Go to Solution.
Hi,
this code works for me well:
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
'start a transaction
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, False), BlockTableRecord)
Try
Dim pts As New Point3dCollection()
Dim opts As New PromptPointOptions(vbLf & "Pick leader arrow point: ")
opts.AllowArbitraryInput = True
opts.AllowNone = True
opts.UseBasePoint = False
opts.UseDashedLine = True
Dim dp As New Point3d(Double.NegativeInfinity, 0, 0)
While True
If Not Double.IsNegativeInfinity(dp.X) Then
opts.UseBasePoint = True
opts.BasePoint = dp
End If
Dim res As PromptPointResult = ed.GetPoint(opts)
If res.Status = PromptStatus.OK Then
pts.Add(res.Value)
dp = res.Value
Else
Exit While
End If
opts.Message = vbLf & "Next leader point or (Enter to exit): "
End While
Dim leader As New Leader()
leader.SetDatabaseDefaults()
'take the current annotative scale
leader.Annotative = AnnotativeStates.True
' Get the current UCS, for different ucs
Dim ucs As Matrix3d = ed.CurrentUserCoordinateSystem
For Each p As Point3d In pts
Dim transformedPt As Point3d = p.TransformBy(ucs)
leader.AppendVertex(transformedPt)
Next
Dim leaderId As ObjectId = btr.AppendEntity(leader)
tr.AddNewlyCreatedDBObject(leader, True)
tr.Commit()
Catch ex As System.Exception
ed.WriteMessage(Environment.NewLine & ex.ToString())
End Try
End Using
e.g.
I 've added some settings to your code,
see my poor comments:
<CommandMethod("CreateLeader")> _ Public Sub Createleader() Application.SetSystemVariable("dimldrblk", ".") '"." comma means closed filled it also may be _dot,_dotsmall etc Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim acBlkTbl As BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) Dim acBlkTblRec As BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite) Dim mtextId As ObjectId Dim mtx As MText = New MText() mtx.SetDatabaseDefaults() mtx.Contents = "FIRST LINE\PSECOND LINE" mtx.Location = New Point3d(4, 4, 0) mtx.TextHeight = 0.25 mtx.Attachment = AttachmentPoint.MiddleLeft mtx.SetAttachmentMovingLocation(mtx.Attachment) mtextId = acBlkTblRec.AppendEntity(mtx) acTrans.AddNewlyCreatedDBObject(mtx, True) Dim acLdr As Leader = New Leader() acLdr.SetDatabaseDefaults() acLdr.AppendVertex(New Point3d(2, 2, 0)) acLdr.AppendVertex(New Point3d(4, 4, 0)) '______________________________________' 'problem with arrow size, fix it here: acLdr.Dimasz = 0.25 '______________________________________' acBlkTblRec.AppendEntity(acLdr) acTrans.AddNewlyCreatedDBObject(acLdr, True) acLdr.Annotation = mtextId acLdr.Dimsah = False acLdr.Dimtad = 0 acLdr.Dimgap = 0.25 acLdr.EvaluateLeader() 'just in case if annotation is added then evaluate leader acTrans.Commit() End Using End Sub
Hi Hallex,
Thanks for your code. It is working great as I wanted. I want to ask you another question. Can I put leader and annotation in one block. If yes how? Can you help me in this regard?
Zakir