Sub GetPointOfLine()
 
    Dim objLine As Object
    Dim ssetObj As AcadSelectionSet
    Dim startPoint As Variant
    Dim endPoint As Variant
 
    'Ban hay thay doi phan chu do sau moi lan chay nhe!
    Set ssetObj = ThisDrawing.SelectionSets.Add("[COLOR=red]CHON_LINE_1[/COLOR]")
    ssetObj.SelectOnScreen
 
    For Each objLine In ssetObj
        If TypeName(objLine) = "IAcadLine" Then
            startPoint = objLine.startPoint
            endPoint = objLine.endPoint
            MsgBox "Diem dau cua Line: " & startPoint(0) & "," & startPoint(1)
            MsgBox "Diem cuoi cua Line: " & endPoint(0) & "," & endPoint(1)
        End If
    Next objLine
End Sub

[COLOR=red]    ThisDrawing.SelectionSets.Item("CHON_LINE_1").Delete
[/COLOR]    Set ssetObj = Nothing
    Set objLine = NothingN2NTrung đã viết:bạn nvson đã giúp mình viết lệnh để tìm điểm đầu điểm cuối của 1 đoạn thẳng. ý mình là muốn tạo 1 nút lệnh CommandButton để làm sao khi nhấp vào thì lệnh thực hiện dòng thông báo tạo độ các điểm: điểm đầu, điểm cuối, điểm giữa
Bạn thử đoạn code sau:N2NTrung đã viết:Mỗi lần thao tác chỉ biết chiều dài 1 đoạn thẳng (như thế thì kích mỏi tay quá), giúp tớ viết lệnh để đọc hết chiều dài các đoạn thẳng với.
Option Explicit
Sub GetPointOfLine()
 
    Dim objLine As Object
    Dim ssetObj As AcadSelectionSet
    Dim startPoint As Variant
    Dim endPoint As Variant
    Dim midPoint(0 To 2) As Variant
    Dim i As Double
       
    Set ssetObj = ThisDrawing.SelectionSets.Add("CHON_LINE_1")
    ssetObj.SelectOnScreen
 
    For Each objLine In ssetObj
        If TypeName(objLine) = "IAcadLine" Then
            i = i + 1
            startPoint = objLine.startPoint
            endPoint = objLine.endPoint
                                  
            If startPoint(0) <= endPoint(0) Then
                midPoint(0) = startPoint(0) + Abs(startPoint(0) - endPoint(0)) / 2
            Else
                midPoint(0) = endPoint(0) + Abs(startPoint(0) - endPoint(0)) / 2
            End If
            If startPoint(1) <= endPoint(1) Then
                midPoint(1) = startPoint(1) + Abs(startPoint(1) - endPoint(1)) / 2
            Else
                midPoint(1) = endPoint(1) + Abs(startPoint(1) - endPoint(1)) / 2
            End If
            
            MsgBox "Diem dau cua Line " & i & vbCrLf & startPoint(0) & "," & startPoint(1)
            MsgBox "Diem cuoi cua Line " & i & vbCrLf & endPoint(0) & "," & endPoint(1)
            MsgBox "Diem giua cua Line " & i & vbCrLf & midPoint(0) & "," & midPoint(1)
        End If
    Next objLine
    
    ThisDrawing.SelectionSets.Item("CHON_LINE_1").Delete
    Set ssetObj = Nothing
    Set objLine = Nothing
    
End Sub1/ Đang bàn về kỹ thuật lập trình mà.chỉ cần sd dụng lệnh PE có sẵn trong cad nhé, PE enter, R enter là oke
