Consulting

Results 1 to 3 of 3

Thread: Solved: Opening Named Views in AutoCAD

  1. #1

    Solved: Opening Named Views in AutoCAD

    Hi all,

    I'm trying to open an AutoCAD file within Excel and then restore a named view within AutoCAD. Any help would be greatly appreciated.

    Cheers,
    Darth_Lando

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Hi Darth_Lando,

    Welcome to VBA Express!!

    The below code will open an existing Acad drawing, and display the existing named view "fred".

    Place the following code in a module:

    [VBA]
    Public objAcad As AcadApplication
    Sub NamedView(iDwg As String, iNamedView As String)
    Dim mEachView As AcadView
    Dim mAdwg As AcadDocument
    Dim mViewPort As AcadViewport
    'iDwg has the full pathe to the drawing ex. "C:\acad\somedrawing.dwg"
    Set mAdwg = objAcad.Documents.Open(iDwg)
    'get the active view port
    Set mViewPort = mAdwg.ActiveViewport
    For I = 0 To mAdwg.Views.Count - 1
    'find the named view you are looking for
    If mAdwg.Views(I).Name = iNamedView Then
    Set mEachView = mAdwg.Views(I)
    End If
    Next
    'set the view of the viewport
    mViewPort.SetView mEachView
    'show it
    mAdwg.ActiveViewport = mViewPort
    End Sub

    Sub Main()
    Set objAcad = New AcadApplication
    objAcad.Visible = True
    NamedView "C:\acad\mainteab2.dwg", "fred"
    End Sub


    [/VBA]

    HTH If you need more help let me know

  3. #3
    Tommy,

    Thank you so much for your help. It worked like a charm.

    Cheers,
    Jake

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •