偏移线中点
您好,我想通过代码(在我的代码行Obj2中)获得由偏移创建的直线中点的坐标:Dim lineObj2 As Variant
lineObj2 = lineObj.Offset(2 * Round(lineObj.Length, 2))
我该怎么做
请给我提个建议。
您好,我可以使用以下代码解决这个问题:
Dim lineObj2 As Variant, lineObj3 As AcadLine
lineObj2 = lineObj.Offset(2 * Round(lineObj.Length, 2))
Dim ent As AcadEntity
Set ent = ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1)
If ent.ObjectName = "AcDbLine" Then
Set lineObj3 = ent
ent.Highlight True
Dim AA As Variant
Dim BB As Variant
Dim CC As Variant
AA = lineObj3.startPoint
BB = lineObj3.endPoint
CC(0) = (AA(0) + BB(0)) * 0.5
CC(1) = (AA(1) + BB(1)) * 0.5
CC(2) = (AA(2) + BB(2)) * 0.5
Debug.Print CC(0), CC(1), CC(2)
Else
End If
但是我认为有#039;这是一个更好的方法,如果你有更好的建议,请说。 看起来没问题,唯一的其他方法是通过使用角度和线的距离。 您可以使用AcadLine对象而不是变体,并获取其中点:
Dim lineObj2 As AcadLine
Set lineObj2 = lineObj.Offset(-2 * Round(lineObj.Length, 2))(0) ' <-- get the first element of then variant spitted out of Offset method and set it to a line object (because you know it really is!)
Dim midPoint2(0 To 2) As Double
With lineObj2
midPoint2(0) = (.startPoint(0) + .endPoint(0)) * 0.5
midPoint2(1) = (.startPoint(1) + .endPoint(1)) * 0.5
midPoint2(2) = (.startPoint(2) + .endPoint(2)) * 0.5
End With
页:
[1]