Computer Aided Automation

Full Version: Animation using AutoCAD VBA
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[Image: Animation%20using%20AutoCAD%20VBA%202.JPG?itok=VKpOnmLc]

AutoCAD VBA can be used simple animations like movement of objects, changing colours of objects (line, circle etc)

Example 2. Animation in AutoCAD VBA – circle movement (user form project)

In this example, the circle will be moving along X axis based on the values like frame rate per second and time duration

Description of the code: These codes creates a circle then delete it after frame rate value in seconds then regenerate by changing the center.

Load the project – AutoCAD animation – circle movement.dvb (Download)

Animation using AutoCAD VBA

Or create a new project with following codes and Form Control items


Private Sub CommandButton1_Click()


Me.hide

Dim R As Variant

Dim X As Variant

Dim Y As Variant

Dim F As Long

Dim T As Variant

Dim Count As Integer

Dim Center(0 To 2) As Double

Dim objEnt As AcadCircle

On Error Resume Next

With ThisDrawing.Utility

R = TextBox1.Text

X = TextBox2.Text

Y = TextBox3.Text

F = TextBox4.Text

T = TextBox5.Text

'Center(0) = X: Center(1) = Y: Center(2) = 0

End With

'' draw the entity

For Count = 0 To 10

Center(0) = X + Count: Center(1) = Y: Center(2) = 0

If ThisDrawing.ActiveSpace = acModelSpace Then

Set objEnt = ThisDrawing.ModelSpace.AddCircle(Center, R)

Else

Set objEnt = ThisDrawing.PaperSpace.AddCircle(Center, R)

End If

objEnt.Update

ThisApplication.ActiveView.Fit True

Call WaitFor(F)

objEnt.Delete

ThisApplication.ActiveView.Fit True

Next

End Sub

Sub WaitFor(NumOfSeconds As Long)

Dim SngSec As Long

SngSec = Timer + NumOfSeconds

Do While Timer < SngSec

Loop

End Sub


And related form control items will look like this


Enter the values and press RUN button,
demo video on autocad drawing animation