Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Autocad + Visual Basic 6

Status
Not open for further replies.

efighettib

Structural
Jan 13, 2004
26
CL
Hello

I have read the focus, and i have not found what I need.

All I want is to open a drawing from VB6 (by a command button), and draw a line from 2 points that were specified in the visual basic 6 aplication.

Can someone tell me the code that I need please.
(My proyect has the autocad library, all I need is know how to open an autocad file and draw the line)

Very simple!
 
Replies continue below

Recommended for you

If that's all you want to do then I suggest you look at creating a DDE connection between your VB programme and AutoCAD and then use sendkeys from VB to AutoCAD to open the drawing and draw the line.
 
When i said that this is all what I need to know, is because with a line I have a start point to continue with my project. My problem is to start it. I don`t want to do this with sendkeys, because i know that autocad as vba, and with that my programm will have a better performance.

Thanks anyway.
 
Sorry, I'm a bit confused here?
Are you opening an existing drawing or starting a new drawing?
Are you using Visual Basic or AutoCAD's inbuilt Visual Basic for Applications?
 
Hi...

First, in Visual Basic 6.0 You must go to the menu Project->References..

Second, you must found the AutoCAD 2000 Type Library and select it and press To Accept.

Third, in the section of Declarations you must declare the variable that represents the application of AutoCAD and other that represents the utility of AutoCAD. For example:

Options Explicit
Private autocadApp As AcadApplication
Private utilGet As AcadUtility

Quarter, in the Load event of the Form you must make the reference to variable. For example:

Private Sub Form_Load()
On Error Resume Next
Set autocadApp = GetObject(, "AutoCAD.Application.15")
Set utilGet = autocadApp.ActiveDocument.Utility
If Err Then
Err.Clear
Set autocadApp = CreateObject("AutoCAD.Application.15")
Set utilGet = autocadApp.ActiveDocument.Utility
If Err Then
MsgBox Err.Description
Exit Sub
End If
End If
End Sub

Fifth, in a CommandButton you must do the following thing:

Private Sub Command1_Click()
Form1.Hide
Dim Distance As Double
AppActivate autocadApp.Caption
Distance = utilGet.GetDistance(, vbCr & "Specify first point: ")
Form1.Show
MsgBox Distance, vbInformation, "Example"
End Sub

To open a drawing you must make this:

First declare a variable type Document, next open the drawing:

Dim doc As AcadDocument
Set doc = autocadApp.Application.Documents.Open("c:\drawing.dwg")

I hope that it serves to him
 
Tnanks a lot to everyone. That really helps to clarify the ideas.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top