Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with VBA

Status
Not open for further replies.

RufussMcGee

Technical User
Jan 7, 2005
117
US
Need help with VBA in Autocad, tell me to write a lisp routine and will have it for you. But when it comes to VBA just cannot figure out how to do things. For Example wrote this simple code...

Private Sub CommandButton1_Click()
Dim aline As AcadLine
Dim startPoint
Dim endPoint

Me.Hide
startPoint = ThisDrawing.Utility.GetPoint(Prompt:="Pick a point:")
endPoint = ThisDrawing.Utility.GetPoint(Prompt:="Pick a point:")

Set aline = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)
aline.Update
End Sub

It draws a line when the user picks the two points. If I wanted to expand this in Lisp would write a simple code to offset the line one side then add an arc by either filettng the lines or just drawing the arc. But how do you do something as simple as that with VBA? Even if I could find a way to send information by user selection from VBA to my Lisp routine would be great. Does anyone have any advice?
 
Hi Rufuss,

To offset your line, change your code to this:

Code:
Private Sub CommandButton1_Click()
    Dim aline As AcadLine
    Dim startPoint
    Dim endPoint
    Dim offsetObj as Variant

    Me.Hide
    startPoint = ThisDrawing.Utility.GetPoint(Prompt:="Pick a point:")
    endPoint = ThisDrawing.Utility.GetPoint(Prompt:="Pick a point:")

    Set aline = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)
    aline.Update
    ' For a positive X or Y direction. 
    Set offsetObj = aline.Offset(0.25) ' 
    ' make it aline.Offset(-0.25) to go in a negative X or Y direction.
End Sub

To add your arc, you use this syntax:
Code:
object.AddArc(Center, Radius, StartAngle, EndAngle)

If you want to communicate between the two languages, you'll want to write some of your variables to the "User" variables - this the easiest way to communicate between the two languages. In VBA you'll use the SetVariable method:

Code:
ThisDrawing.SetVariable "USERR1", 3

Take a look at AutoCAD's VBA reference manual, it's really pretty good!

HTH
Todd
 
WHere can I find the VBA reference manual is it a book or outline? Have nothing have actual books to work with.

Thanks.
 
Hi Rufuss,

It's in the AutoCAD help files - look under "ActiveX and VBA refernence guide"

HTH
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top