A2K is theobject variable for the AutoCAD application object ( AcadApplication) and A2Kdwg names the instance of AcadDocument. The second paragraph does the same thing for AutoCAD. The standard VB/VBA message box ( MsgBox will become very familiar throughout the course of this book) presents adialog box that displays the text being processed. Setting xWSto the name of the specific worksheet (using the default name Sheet1)completes this sequence.
![autocad lisp yazma autocad lisp yazma](https://ubunlog.com/wp-content/uploads/2020/02/bricscad-.png)
You should change this tothe path and file name of the Excel Workbook you created earlier. Setting xWB calls the Excel Workbooks propertywith the Open method to open a file containing the desired spreadsheet.Here we've used the name C:\IUnknown.xls. Then the Setstatement is used to assign an object reference to each variable.
![autocad lisp yazma autocad lisp yazma](https://3.bp.blogspot.com/-r971US_OWMQ/XHxk-FNd-sI/AAAAAAAAFG4/KR_7WKqCC-ExDVkcEU0-gEADvfXIz5NxwCLcBGAs/s1600/sprink.gif)
You need to declare ( Dim statements) threeobject variables for the Excel components you are going to call: Application, Workbook, and Worksheet. We do not use any forms in this example, so VBrequires that the Sub procedure be called Main.) The firstparagraph sets up Excel. (Normally,a VB project has a startup form. The procedure, which is called Main, is in five paragraphs. For ourexample procedure, we need references to the AutoCAD 2000 and Microsoft Exceltype libraries, which have been checked as shown in Figure 1-4.įigure 1-4 References Dialog Writing the Procedure The VB References dialog is illustrated in Figure 1-4. In Visual Basic 6.0, which we are using for Example 1-2, you set referencesto the available type libraries using a dialog box accessed through theProject'References menu. (Anytext is OK, but "Hello, World!" is the traditional choice.) Setting Available References Before you can run this program,you will need to create an Excel worksheet with some text in the first cell(A1), then save the workbook to a desired location and exit from Excel. What is interesting is that except for the twomessage boxes that are included to let you know when Excel and AutoCAD arerunning, neither application is ever visible. Spreadsheet, creates an AutoCAD drawing, places the text into the drawing,and then saves the drawing. Visual Basic Automation Sub Main() Dim xAP As Excel.Application Dim xWB As Excel.Workbook Dim xWS As Excel.Worksheet Set xAP = Excel.Application Set xWB = ("C:\A2K2_VBA\IUnknown.xls") Set xWS = xWB.Worksheets("Sheet1") MsgBox "Excel says: """ & Cells(1, 1) & """" Dim A2K As AcadApplication Dim A2Kdwg As AcadDocument Set A2K = CreateObject("AutoCAD.Application") Set A2Kdwg = MsgBox A2K.Name & " version " & A2K.Version & _ " is running." Dim Height As Double Dim P(0 To 2) As Double Dim TxtObj As AcadText Dim TxtStr As String Height = 1 P(0) = 1: P(1) = 1: P(2) = 0 TxtStr = Cells(1, 1) Set TxtObj = (TxtStr, _ P, Height) A2Kdwg.SaveAs "C:\A2K2_VBA\IUnknown.dwg" A2K.Quit Set A2K = Nothing xAP.Quit Set xAP = NothingEnd Sub Example 1-2 is a short butinteresting VB procedure that reads some text data from an Excel Example 1-2. Learn More Buy Creating a Drawing with Visual Basicīefore we complete our discussion of COM, let us see how VB and COM can beused to pass data from one application to another. VBA for AutoCAD 2002: Writing AutoCAD Macros