Sorry it has taken me a long time to reply. Here is the code I'm running, and a sample drawing with the block and viewport.
' check north arrow
Dim myDWG As Document = DocumentManager.MdiActiveDocument
Dim database As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = myDWG.Editor
Dim BlockRotAng As Double = 0.0 ' rotation angle of North Arrow Block
Dim UCSAngleDeg As Double = 0.0 ' UCS angle
Dim NORTHCALC As Double = 0.0
Dim vptwistInDegrees As Double = 0.0 ' viewport twist in degrees (WCS)
Using myTrans As Transaction = myDWG.TransactionManager.StartTransaction
Dim NORTHID As ObjectId = FindBlock("ntharrow")
Dim PRJNorth As Boolean = FindTxt("PROJECT NORTH")
If NORTHID.IsNull = False Then
If PRJNorth = False Then
Dim NorthBlkRef As BlockReference = NORTHID.GetObject(OpenMode.ForRead)
BlockRotAng = NorthBlkRef.Rotation
' converting Radian to degree
BlockRotAng = BlockRotAng * (180 / Math.PI)
Dim symTable As SymbolTable = CType(myTrans.GetObject(database.ViewportTableId, OpenMode.ForRead), SymbolTable)
Dim vpcount As Integer = 0
For Each id As ObjectId In symTable
Dim symbol As ViewportTableRecord = CType(myTrans.GetObject(id, OpenMode.ForRead), ViewportTableRecord)
Dim acadDoc As AcadDocument = Autodesk.AutoCAD.ApplicationServices.DocumentExtension.GetAcadDocument(myDWG)
acadDoc.MSpace = True
Dim CVport As Viewport = DirectCast(myTrans.GetObject(myDWG.Editor.CurrentViewportObjectId, OpenMode.ForRead), Viewport)
If (CVport.TwistAngle > 2 * Math.PI) Then
CVport.UpgradeOpen()
CVport.TwistAngle = Math.Atan2(Math.Sin(CVport.TwistAngle), Math.Cos(CVport.TwistAngle))
End If
Dim vptwistInRadians As Double = CVport.TwistAngle
vptwistInDegrees = Math.Abs((vptwistInRadians * (180 / Math.PI)))
NORTHCALC = BlockRotAng
ed.WriteMessage([String].Format(vbLf & "North Block Rotation : {0}", NORTHCALC.ToString))
ed.WriteMessage([String].Format(vbLf & "ViewportTwist: {0}", vptwistInDegrees.ToString))
myTrans.Commit()
acadDoc.MSpace = False
vpcount = vpcount + 1
Next
If NORTHCALC = 360 Then
NORTHCALC = 0
End If
If vptwistInDegrees = 360 Then
vptwistInDegrees = 0
End If
If vpcount = 1 And UCSAngleDeg > 0 Then
If (NORTHCALC - UCSAngleDeg) > 1 Or (UCSAngleDeg - NORTHCALC) > 1 Then
MsgBox("Check the angle of the North Arrow", , "NORTH ARROW ROTATION")
End If
End If
If vpcount = 1 And UCSAngleDeg = 0 Then
If (NORTHCALC - vptwistInDegrees) > 1 Or (vptwistInDegrees - NORTHCALC) > 1 Then
MsgBox("Check the angle of the North Arrow", , "NORTH ARROW ROTATION")
End If
End If
End If
End If
End Using