P. 1
81959924 AutoCAD VBA Programming Tools and Techniques

81959924 AutoCAD VBA Programming Tools and Techniques

|Views: 280|Likes:
Published by xuanhuynh

More info:

Published by: xuanhuynh on Nov 02, 2012
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Page 68

Name property of the document object. This property contains the file name without the path name attached.

For example, if a drawing is open and in the drawings collection, the following code would access it and make it the
active drawing.

Dim DWGS As AcadDocuments
Set DWGS = ThisDrawing.Application.Documents
Dim ADWG As AcadDocument
On Error Resume Next
Set ADWG = DWGS.Item(DrawingName)
If Err.Number <> 0 then
'drawing name not in collection


If ADWG.Active = False Then ADWG.Activate

End If

In the code segment above, the first step is to establish a link to the AutoCAD documents collection. Variable DWGS is
defined as an instance of the documents collection and then set to the actual value. This process of defining an object
and setting it will be repeated for the majority of linkages you will be building in VBA.

Given the documents collection object, the Item method is employed to obtain the document. The name of the document
is used as the index into the collection. In the next chapter we will explore collections in more detail. The code contains
an error trap to test if the Item method was successful. If it is not, an error will result, and if the error trap is not enabled,
the program will crash. After clearing the error buffer, the Item method is run and the result placed in the DWG
variable. DWG had been dimensioned earlier as a document object. An IF test immediately follows to see if the error
handler ran into something undesirable. If so, the drawing requested was not in the open documents list. Otherwise, the
active property of the document is checked to see if this is the

< previous page


next page >

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->