PDA

View Full Version : Solved: Opening Named Views in AutoCAD



Darth_Lando
07-25-2005, 03:11 PM
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

Tommy
07-26-2005, 10:27 AM
Hi Darth_Lando, :hi:

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:


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




HTH If you need more help let me know :)

Darth_Lando
07-26-2005, 11:04 AM
Tommy,

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

Cheers,
Jake