Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

VB6 and AutoCad (dsi ..do reply)

Status
Not open for further replies.

Rednyx

Civil/Environmental
Feb 22, 2001
42
I asked about generating visual effects in other programming languages through autocad, which dsi mentioned that VB6 can be of help. I have actually made a program of Stiffness Matrix in Fortran , but am not satisfied with the presentation, im looking forward to make it in VB , if any one can help me in mentioning the sources from where i can get hints about working in Autocad and VB6 together.
 
Replies continue below

Recommended for you

The first step would be to learn the AutoCAD VBA. Once you learn how to do stuff there, you can easily do it in VB6. You just have to include the AutoCAD Object Library in your project references.

There is a ton of information in the AutoCAD help files on VBA. Go to Help > Contents and see the chapter on ActiveX and VBA.

There is also a good book that covers this topic pretty well. AutoCAD 2000 VBA by Joe Sutphin. I found it for less than $30.

I am still unsure of excatly what you want to accomplish. If you want, you can send me some screen captures of your existing Fortran results. If they will help, I can link them into this thread so others can view them as well.

Here is a quick sample on how to use VB6 to automate AutoCAD
Code:
Sub Test()
    Dim CadApp As AcadApplication
    Dim CadDwg As AcadDocument
    Dim textObj As AcadText

    Dim pt2(0 To 2) As Double

    '<><><><><><><><><><><><><><><><><><><><><>
    '  Connect to AutoCAD
    '<><><><><><><><><><><><><><><><><><><><><>
    On Error Resume Next
    Set CadApp = GetObject(, &quot;AutoCAD.Application&quot;)
    If Err.Number <> 0 Then     'Not Running
        Set CadApp = CreateObject(&quot;AutoCAD.Application&quot;)
        Err.Clear
    End If
    On Error GoTo ErrHndlr

    '<><><><><><><><><><><><><><><><><><><><><>
    '  Open the Drawing Template
    '<><><><><><><><><><><><><><><><><><><><><>
    sDwgTemplate = &quot;C:\Temp\A5-Template.dwg&quot;
    If Dir(sDwgTemplate) <> &quot;&quot; Then
        CadApp.Documents.Open sDwgTemplate
    Else
        MsgBox &quot;File &quot; & sDwgTemplate & &quot; does not exist.&quot;
    End If

    '<><><><><><><><><><><><><><><><><><><><><>
    '  Update Drawing
    '<><><><><><><><><><><><><><><><><><><><><>
    Set CadDwg = CadApp.ActiveDocument

    pt2(x) = 8.6422:    pt2(y) = 7.1831:    pt2(z) = 0

    'Insert 1/8&quot; text at pt 2
    Set textObj = CadDwg.ModelSpace.AddText(&quot;Test&quot;, pt2, 0.125)

    CadApp.ZoomExtents
'    CadDwg.SaveAs (&quot;FullPath and New File Name Here&quot;)


CleanUp:
    Set CadDwg = Nothing
    Set CadApp = Nothing
    Set textObj = Nothing
    Exit Sub
ErrHndlr:
    CadApp.Visible = False
    MsgBox &quot;Error in Test()&quot; & vbCrLf & vbCrLf & _
           &quot;Error No. &quot; & Err.Number & vbCrLf & _
           &quot;Description: &quot; & Err.Description
    Err.Clear
    CadApp.Visible = True
End Sub
I hope that works! I quickly scammed a couple of lines from one of my applications.

As you can see, it is not too difficult. Hope this helps!
 
Rednyx:

Oops! Left out the e-mail address.

DimensionalSolutions@Core.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor