Sub myl() Dim p1 As Variant '申明端点坐标 Dim p2 As Variant Dim al() As Double '声明一个动态数组 Dim templ As AcadEntity p1 = ThisDrawing.Utility.GetPoint(, "输入点:") '获取点坐标 p1(2) = 0 '将Z坐标值赋予点坐标中 ReDim al(0 To 2) '定义动态数组 al(0) = p1(0) al(1) = p1(1) al(2) = 0 On Error GoTo Err_Control '出错陷井 Do '开始循环 p2 = ThisDrawing.Utility.GetPoint(p1, vbCr & "输入下一点:") '获取下一个点的坐标 p2(2) = 0 '将Z坐值赋予点坐标中 lub = UBound(al) '获取当前l数组中元的元素个数 ReDim Preserve al(lub + 3) For i = 1 To 3 al(lub + i) = p2(i - 1) Next i Set templ = ThisDrawing.ModelSpace.AddPolyline(al) '画多段线 p1 = p2 '将第二点的端点保存为下一条直线的第一个端点坐标 Loop Err_Control: templ.Closed = True Dim regionobj As Variant regionobj = ThisDrawing.ModelSpace.AddRegion(templ) '转化为面域 regionobj(0).color = acRed Dim Myregion As AcadRegion Set Myregion = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1) Dim pt0 As Variant pt0 = Myregion.Centroid '引用Centroid属性 Dim pt1(0 To 2) As Double pt1(0) = pt0(0): pt1(1) = pt0(1): pt1(2) = 0 Dim pt As AcadPoint Set pt = ThisDrawing.ModelSpace.AddPoint(pt1) pt.color = acBlue ThisDrawing.SetVariable "PDMODE", 2 ThisDrawing.SetVariable "PDSIZE", 0.1 '调用系统变量 ZoomExtents End Sub 版主帮我看一下是什么问题,问了你这么多问题我以为就解决了,可是到最后还是出现了问题,看来还经继续学习. |