.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

when line change?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
h.sezenn
3396 Views, 4 Replies

when line change?

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 🙂

19-11-13-SORU01.jpg

_____________________________________________________________________________________
Everything For Duct
4 REPLIES 4
Message 2 of 5
mzakiralam
in reply to: h.sezenn

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.

 

http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff2566ffd511ff6f8c7ca-36...

Message 3 of 5
h.sezenn
in reply to: mzakiralam

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

 

_____________________________________________________________________________________
Everything For Duct
Message 4 of 5
mzakiralam
in reply to: h.sezenn

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

 

Message 5 of 5
h.sezenn
in reply to: mzakiralam

Thank you 🙂 it works.
_____________________________________________________________________________________
Everything For Duct

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost