本帖最后由 woaishuijia 于 2012-6-2 05:26 编辑
用定时器吧
插入标准模块"模块1",代码
- Option Explicit
- Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
- Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
- Dim lngTimerID As Long
- Private Sub TimerProc()
- KillTimer 0, lngTimerID
- ThisDrawing.ModifyPL
- End Sub
- Sub ST(T As Integer)
- lngTimerID = SetTimer(0, 0, T, AddressOf TimerProc)
- End Sub
thisdrawing模块代码- Option Explicit
- Dim WithEvents PL As AcadLWPolyline
- Dim P1 As Variant
- Private Sub PL_Modified(ByVal pObject As IAcadObject)
- Dim P2 As Variant
- On Error GoTo 10
- P2 = PL.Coordinates
- If P2(2) <> P1(2) Or P2(3) <> P1(3) Then
- P2(4) = P2(4) + P2(2) - P1(2)
- P2(5) = P2(5) + P2(3) - P1(3)
- P1 = P2
- 模块1.ST 1
- Else
- P1 = PL.Coordinates
- End If
- 10 End Sub
- Sub AddPL()
- Dim P2(5) As Double
- P2(2) = 100
- P2(3) = 100
- P2(4) = 200
- P2(5) = 100
- Set PL = ThisDrawing.ModelSpace.AddLightWeightPolyline(P2)
- P1 = P2
- End Sub
- Sub ModifyPL()
- On Error Resume Next
- PL.Coordinates = P1
- End Sub
|