I'm adding this little ditty to my code library for sure....
vla-Get-ViewAnnoScale
Returns the annotation scale of a named view
Code:
(vla-Get-ViewAnnoScale ViewName)
ViewName
A string.
Return values
The annotation scale as string, if the ViewName exists within the ViewTable Collection, Nil if the supplied ViewName does not exist.
Examples
Code:
Command: (if (vla-Get-ViewAnnoScale "foo") t nil)
nil
Command: v
-VIEW Enter an option [?/Delete/Orthographic/Restore/Save/sEttings/Window]: s
Enter view name to save: foo
UCSVIEW = 1 UCS will be saved with view
Command: (if (vla-Get-ViewAnnoScale "foo") t nil)
T
Command: (vla-Get-ViewAnnoScale "foo")
"1\" = 50'"
Attached to this post is a .NET Assembly, compiled to .NET 3.5 and will work for AutoCAD versions 2010 and newer. Be sure to unblock the attached .ZIP file before decompressing, then Simply NETLOAD the assembly into your session of AutoCAD.
If, like me, you'd prefer to compile the .NET assembly yourself, here's the source code for your use:
Code:
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports System
' This line is not mandatory, but improves loading performance
<Assembly: CommandClass(GetType(RenderMan.vlaGetViewAnnoScale))>
Namespace RenderMan
Public Class vlaGetViewAnnoScale
'
' Initialization message:
'
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Public Sub Initialize() Implements _
IExtensionApplication.Initialize
Dim ed As Editor = _
Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage(vbLf & "vla-Get-ViewAnnoScale utility loaded. " & vbLf & _
"... Another creative innovation by RenderMan, 2012 " & vbLf)
End Sub
Public Sub Terminate() Implements _
IExtensionApplication.Terminate
Console.WriteLine("Cleaning up... ")
End Sub
Private Shared ed As Editor = _
Application.DocumentManager.MdiActiveDocument.Editor
'
' Syntax: (vla-Get-ViewAnnoScale ViewName)
'
<LispFunction("vla-Get-ViewAnnoScale")> _
Public Function vlaGetViewAnnoScale(ByVal args As ResultBuffer)
Try
If args = Nothing Then
'Throw New ArgumentNullException( _
' "; error: too few arguments")
ed.WriteMessage(vbLf & _
"; error: too few arguments " _
& vbLf)
Return Nothing
End If
Dim myArgs As Array = args.AsArray()
If myArgs.Length > 1 Then
'Throw New ArgumentException( _
' "; error: too many arguments")
ed.WriteMessage(vbLf & _
"; error: too many arguments " _
& vbLf)
Return Nothing
End If
Dim acDoc As Document = _
Application.DocumentManager.MdiActiveDocument
Dim acDb As Database = acDoc.Database
If myArgs(0).TypeCode <> LispDataType.Text Then
ed.WriteMessage(vbLf & _
"; error: bad argument type: stringp " _
& vbLf)
Return Nothing
End If
Dim viewName As String = _
CType(myArgs.GetValue(0), TypedValue).Value
Using acTrans As Transaction = _
acDb.TransactionManager.StartTransaction()
Dim acViewTbl As ViewTable = _
acTrans.GetObject(acDb.ViewTableId, _
OpenMode.ForRead)
If acViewTbl.Has(viewName) = True Then
acViewTbl.UpgradeOpen()
Dim acViewRec As ViewTableRecord = _
acTrans.GetObject(acViewTbl(viewName), OpenMode.ForRead)
Dim annoScale As AnnotationScale = acViewRec.AnnotationScale
Return annoScale.Name
Else
Return Nothing
End If
acTrans.Commit()
End Using
Catch ex As System.Exception
ed.WriteMessage(ex.Message)
Return Nothing
End Try
End Function
End Class
End Namespace
Cheers!