Eng-Tips is the largest forum for Engineering Professionals on the Internet.

Members share and learn making Eng-Tips Forums the best source of engineering information on the Internet!

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

Open a new drawing from within Autocad

Status
Not open for further replies.

LumpoDelMagnifico

Electrical
Joined
Sep 22, 2004
Messages
35
Location
US
I am doing a program that uses VBA to open, Center, Zoom and then time stamp a drawing in AUTOCAD. I can do everything else, but how do I open a different drawing using VBA from within autocad?

Just to clarify, I have 10 drawings in a set on my engineering directory, I want to open each one individually, center the viewport,zoom to extents, and then save and close the drawing. So how do I open the second drawing from VBA?
 
You need to use code like:
Code:
Sub OpenFiles()
    Dim CurrentDwg As AcadDocument
    Dirname = "C:\Documents and Settings\Mala Singh\My Documents\"
    Dim DwgNames(1 To 10)
    DwgNames(1) = "Dwg1"
    DwgNames(2) = "Dwg2"
    DwgNames(3) = "Dwg3"
    DwgNames(4) = "Dwg4"
    DwgNames(5) = "Dwg5"
    DwgNames(6) = "Dwg6"
    DwgNames(7) = "Dwg7"
    DwgNames(8) = "Dwg8"
    DwgNames(9) = "Dwg9"
    DwgNames(10) = "Dwg10"
    For i = 1 To 10
        DwgName = Dirname & DwgNames(i) & ".dwg"
        Set CurrentDwg = Application.Documents.Open(DwgName)
        'Put remaining code here...
    Next i
End Sub

Replace DirName with your actual folder path (remember to end it with a backslash '\').
Replace the drawing names with the actual drawing names (without .dwg extension).

Hope this helps...


Mala Singh
'Dare to Imagine'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top