Friday, January 13, 2006

Linking AutoCAD VBA to a VB DLL

Platform: AutoCAD 2006

Platform: Required VB 6

Visual Basic for Applications (VBA) is a great tool for quick routines or even large projects that have no budget. However, if the project requires any controls that VBA does not include, like a listview, a full Visual Basic application might be required. Linking a VB application to AutoCAD is not that easy and is usually left to C++ or .Net programmers with ObjectARX.

Fortunately, we can reference a Visual Basic Dynamic Link Library (DLL) within AutoCAD VBA.

Start a Visual Basic project with the ActiveX Dll template and copy the code below into the class module.

Public Function HelloWorld() As Boolean
On Error GoTo ErrorHandler
MsgBox "Hello World!", vbOKOnly + vbExclamation, "Hello"

HelloWorld = True

End Function

Rename the class module to "Sample" and rename the project to "vb2vba". Save the project as "vb2vba" as well. Compile the application as "vb2vba.dll".

In AutoCAD 2006, open the VBA Interface and add the code block below to the "ThisDrawing" module.

Public Sub ShowDialog()
' Show the Hello World message box
On Error GoTo ErrorHandler
Dim objSample As vb2vba.Sample

Set objSample = New vb2vba.Sample
If Not objSample.HelloWorld = True Then Err.Raise vbObjectError + 1, , "Error calling HelloWorld from ShowDialog"

Set objSample = Nothing

Exit Sub
Set objSample = Nothing
End Sub

Click on the "Tools" menu in the VBA IDE and select "References...". Find "vb2vba" and click the check mark on.

You should now be able to run the "ShowDialog" subroutine in AutoCAD VBA. It will call the VB Dll and display a message box with the famous "Hello World!" message.

Wednesday, January 04, 2006

New Blog on the Block

I thought I should post a quick note about a new blog some of you might be interested in. CADgneto focuses on the Autodesk mechanical products with extra emphasis on AutoCAD Electrical. CADgneto is maintained by Steve McCarthy, an Applicaitons Specialist (and coworker) with SolidCAD.

Steve usualy knows more about AutoCAD Electrical than the Autodesk support desk so he's a good reference for those annoying little quirks AutoCAD Electrical sometimes has.

This page is powered by Blogger. Isn't yours?

vba, acad vba, cad vba, cad, visual basic, visual basic for applications, autocad vba, acad vba, training, vba training, cad training, acad training, autocad training, autocad vba training, bom, bill of material, meta-data, meta data, metadata, property data, data, inventor properties, document management, document, management,technical support resource for users of Autodesk Mechanical CAD Software including Autodesk Inventor & Mechanical Desktop inventor, autodeskinventor, inventor 2, inventor 3, inventor 4, inventor 5, inventor 6, inventor7, inventor 8, inventor 9, inventor 10, autodesk inventor, autodesk inventor2, autodesk inventor 3, autodesk inventor 4, autodesk inventor 5, autodeskinventor 6, autodesk inventor 7, autodesk inventor 8, autodesk inventor9, autodesk inventor 10, inventor r, inventor r2, inventor r3, inventor r4, inventor r5, inventor r6, inventor r7, inventor r8, inventor r9, inventorr10, autodesk inventor, autodesk inventor r2, autodesk inventor r3, autodeskinventor r4, autodesk inventor r5, autodesk inventor r6, autodesk inventorr7, autodesk inventor r8, autodesk inventor r9, autodesk inventor r10,inventor series, autodesk inventor series, inventor series 5, inventorseries R5, autodesk inventor series 5, autodesk inventor series r5, inventorseries 6, inventor series R6, autodesk inventor series 6, autodesk inventorseries r6, inventor autodesk, autodesk inventor download, autodesk inventortutorial, autodesk inventor help, autodesk inventor faq, autodesk inventortips, autodesk inventor routines, autodesk inventor support, autodesk inventor, inventor download, inventor tutorial, inventor help, inventorfaq, inventor tips, inventor routines, inventor support, inventor, inventor help line, help for inventor, inventortraining, autodesk inventor training, mdt, mdt 4, mdt 5,mdt 6, mdt 7, mdt 8, mdt4, mdt5, mdt6, mdt7, mdt8, mdt 2000, mdt 2002,mdt r4, mdt r5, mdt r6, mdt r2000, mdt r2002, mechanical desktop, mechanicaldesktop 4, mechanical desktop 5, mechanical desktop 6, mechanical desktop7, mechanical desktop 2000, mechanical desktop 2002, autodesk, autodesk auto cad, autodesk inc,training, education, auto cad support, autocad support, mcad, autocad mechanical,mechanical, autocad mechanical 6, autocad mechanical 7, autocad mechanical8, autocad mechanical 9, autocad mechanical r6, autocad mechanical r7,autocad mechanical r8, autocad mechanical r9, support, help, tips, routines, reseller, mech, cad, acad, technical, ontario, canada, f.a.q.,faq, answers, resource, barrie, autolisp, auto lisp, autocad, auto cad, autocad desktop, auto cad desktop, autocad inventor, auto cadinventor, powerpack, MAI, desktop, cad software, autocad lt, auto cad lt,cad cam, cad design, cad job, job cad, autocad lisp, auto cad lisp, 3dcad software, 3d cad, free, free cad software, service pack, render, system, computer, aided, drafting, design, manufacturing, modeling, solidmodeling, solid modelling