hello everybody, I have a question.
There is a line in my draw ( on picture first action ) when I change it ( on picture second action ) , after changed it, I want to know its modify last point [ like p2(2500,1000) ]. how Can I do it with .net
Also I have lots of line on my drawing, I want it, for all of my line which are changed. Is there any way to do it?
thanks everybody 🙂
Solved! Go to Solution.
Solved by mzakiralam. Go to Solution.
You can find a line end point with below code
<CommandMethod("TST")> Public Sub TestLine() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Dim peo As PromptEntityOptions = New PromptEntityOptions(vbLf & "Select a line:") Dim per As PromptEntityResult = ed.GetEntity(peo) If per.Status <> PromptStatus.OK Then Return End If Using tx As Transaction = db.TransactionManager.StartTransaction() Dim ent As Entity = tx.GetObject(per.ObjectId, OpenMode.ForRead) If TypeOf ent Is Line Then Dim ln As Line = TryCast(ent, Line) MsgBox(ln.EndPoint.ToString) End If tx.Commit() End Using End Sub
But if you want to get the end point after modify it , then you have to use object event handler. In that case , you can go through the below link which will give you a proper guideline.
Thank you your answer. at this link code that worked. but there is a problem in code.
I recode again for my self.
I draw lots of lines on my draw area. after draw some lines. I want to modfy any of them( for example first drawn line ), but After I modfy the first one line, alert massage show that's last line's end point. but I want to know first line's end point( which I modfy line)
is there any solition about that? can we do it line's id number?( Line.Id)
thanks alot 🙂
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.EditorInput Public Class _20_11_13_soru01 Dim Line As Line = Nothing <CommandMethod("CTE01")> _ Public Sub cte_01() Dim Doc As Document = Application.DocumentManager.MdiActiveDocument Dim Db As Database = Doc.Database 'NOKTA SEÇİMİ İÇİN GETPOİNT OLUŞTURULDU Dim pPtRes As PromptPointResult Dim pPtOpts As PromptPointOptions = New PromptPointOptions("") 'İLK NOKTA SEÇİMİ YAPILDI pPtOpts.Message = vbLf & "BAŞLANGIÇ NOKTASINI SEÇ (PİCK FİRST POİNT): " pPtRes = Doc.Editor.GetPoint(pPtOpts) Dim ptStart As Point3d = pPtRes.Value Do 'İKİNCİ NOKTA OLUŞTURULDU pPtOpts.Message = vbLf & "NOKTA SEÇİMİ YAPIN( PİCK POİNT) : " pPtOpts.UseBasePoint = True pPtOpts.BasePoint = ptStart pPtRes = Doc.Editor.GetPoint(pPtOpts) Dim ptEnd As Point3d = pPtRes.Value If pPtRes.Status = PromptStatus.OK Then Using Tr As Transaction = Db.TransactionManager.StartTransaction() '' BLOK TABLOSU OKUMAK İÇİN AÇILDI Dim Bt As BlockTable Bt = Tr.GetObject(Db.BlockTableId, OpenMode.ForRead) '' BLOK TABLO KAYDI YAZMAK İÇİN AÇILDI Dim btr As BlockTableRecord btr = Tr.GetObject(Bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite) Line = New Line(ptStart, ptEnd) btr.AppendEntity(Line) Tr.AddNewlyCreatedDBObject(Line, True) AddHandler Line.Modified, AddressOf linemod Tr.Commit() End Using ptStart = ptEnd 'LİNE ÇİZMEK İÇİN İLK NOKTA DEĞERİ Bİ ÖNCEKİ LİNE IN SON NOKTASI OLARAK GÜNCELLENDİ Else : End If Loop While pPtRes.Status = PromptStatus.OK End Sub Public Sub linemod(ByVal senderObj As Object, _ ByVal evtArgs As EventArgs) Application.ShowAlertDialog("line id " & Line.Id.ToString & "modfied end point:" & Line.EndPoint.ToString) End Sub End Class
This is happening because you are adding line and that line is pointed to the event handler. So which last line is added through the code it is showing only that line's information. However, I have written few lines for your purpose. It will track database modify event. if database is modified and modified object is line only then the event will be triggered. Please see below code if it serve your purpose.
Dim objIdColl As New ObjectIdCollection() <CommandMethod("TST")> Public Sub TESTLine() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Using tx As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead) Dim ms As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead) For Each id As ObjectId In ms objIdColl.Add(id) Next End Using AddHandler db.ObjectModified, AddressOf acLineMod End Sub Public Sub acLineMod(sender As Object, e As ObjectEventArgs) If objIdColl.Contains(e.DBObject.Id) Then If TypeOf e.DBObject Is Line Then If e.DBObject.IsModified Then Dim ln As Line = TryCast(e.DBObject, Line) MsgBox(ln.EndPoint.ToString) End If End If End If End Sub