...百思不得其解(本人小白,请大神帮忙,万分感激)
发布网友
发布时间:2024-10-19 20:15
我来回答
共2个回答
热心网友
时间:2024-11-10 05:16
Set LineObj = activeDoc.ModelSpace.AddLine(startpoint, endpoint) '画线中的参数只需两个点,而你的数组是多点的,不匹配。要画多点连续线可用Set myl = ThisDrawing.ModelSpace.AddLightWeightPolyline(p) '画多段线 。
要分段线可以渐次画出。
sub 划线()'作为一模块
Dim myAcadApp As AutoCAD.AcadApplication
Dim activeDoc As AutoCAD.AcadDocument
Dim acMS As AutoCAD.AcadModelSpace
On Error Resume Next
Set myAcadApp = GetObject(, "Autocad.Application") '检查AutoCAD是否已经打开
If Err <> 0 Then '没有打开
Err.Clear
Set myAcadApp = CreateObject("Autocad.Application") '打开CAD
If Err Then
MsgBox Err.Number & ":" & Err.Description '打开失败
Exit Sub
End If
End If
On Error GoTo prcERR
myAcadApp.Visible = True '显示CAD
Set activeDoc = myAcadApp.ActiveDocument
Dim startpoint(0 To 2) As Double '12 改为2,AddLine首尾点坐标要3维的,平面z不用赋值,默认为0
Dim endpoint(0 To 2) As Double
Dim LineObj As AcadLine
For i = 0 To 5
startpoint(0 = 0
startpoint( 1) = 2 * i
endpoint(0) = 2 * i
endpoint( 1) = 2 * i
'Next i ‘移到下一行,
Set LineObj = activeDoc.ModelSpace.AddLine(startpoint, endpoint) '画线
Next i '到此返回,实现渐次划线
prcExit:
Set activeDoc = Nothing
Set myAcadApp = Nothing
Exit Sub
prcERR:
MsgBox Err.Number & ":" & Err.Description, vbCritical, "错误"
Resume prcExit
End Sub
'祝你成功!
热心网友
时间:2024-11-10 05:15
怎么个出错法?