Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
How can I check when I select Polyline if I am close to endpoint or startpoint
<CommandMethod("ADDTEXT")>
Public Sub test3()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim color As Autodesk.AutoCAD.Colors.Color
Dim peo As New PromptEntityOptions(vbLf & "Select a polyline: ")
peo.SetRejectMessage("Selected object is not a polyline.")
peo.AddAllowedClass(GetType(Polyline), True)
Dim per As PromptEntityResult = ed.GetEntity(peo)
If per.Status <> PromptStatus.OK Then
Return
End If
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim space As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, Autodesk.Gis.Map.Constants.OpenMode.OpenForWrite), BlockTableRecord)
Dim pline As Polyline = CType(tr.GetObject(per.ObjectId, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead), Polyline)
'ed.WriteMessage(vbLf & pline.StartPoint.X.ToString)
'ed.WriteMessage(vbLf & pline.StartPoint.Y.ToString)
tr.Commit()
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Open the Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, Autodesk.Gis.Map.Constants.OpenMode.OpenForRead)
'' Open the Block table record Model space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), Autodesk.Gis.Map.Constants.OpenMode.OpenForWrite)
'' Create the MText annotation
Using acMText As MText = New MText()
acMText.Contents = "Text"
acMText.Location = New Point3d(pline.StartPoint.X + 10, pline.StartPoint.Y + 8, 0)
' acMText.Width = 20
acMText.TextHeight = 1.5
acMText.Layer = "Layer-name"
acMText.Attachment = AttachmentPoint.MiddleLeft
acMText.BackgroundFill = True
color = Color.FromColorIndex(ColorMethod.ByAci, 1)
acMText.BackgroundFillColor = color
acMText.UseBackgroundColor = True
'' 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(pline.StartPoint.X, pline.StartPoint.Y, 0))
acLdr.AppendVertex(New Point3d(pline.StartPoint.X + 8, pline.StartPoint.Y + 8, 0))
acLdr.AppendVertex(New Point3d(pline.StartPoint.X + 8, pline.StartPoint.Y + 9, 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()
acLdr.Layer = "Layer-name"
End Using
End Using
'' Commit the changes and dispose of the transaction
acTrans.Commit()
End Using
End Using
End Sub
Solved! Go to Solution.