.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ViewportTableRecord - Unable to cast types??

1 REPLY 1
Reply
Message 1 of 2
PTipton
381 Views, 1 Reply

ViewportTableRecord - Unable to cast types??

 

Hello,

 

My ultimate goal is to switch to World coordinate system, then back to the user coordinate system.

 

With that said, I have not been able to get past populating the ViewportTableRecord in my code below. I keep getting the same error:

 

{Unable to cast object of type 'Autodesk.AutoCAD.DatabaseServices.Viewport' to type 'Autodesk.AutoCAD.DatabaseServices.ViewportTableRecord}

 

Any suggestions? or an easier way?  -- thanks PT

 

Here is my sample code:

 

Sub World()
        Dim lDrawing As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim Db As Database = lDrawing.Database
        Dim ed As Editor = lDrawing.Editor
 
        'Set to WORLD Coordinate System and back.
        Using LockDoc As DocumentLock = lDrawing.LockDocument
            Using acTrans As Transaction = Db.TransactionManager.StartTransaction()
                Dim acVpT As ViewportTable
                acVPT = acTrans.GetObject(Db.ViewportTableId, OpenMode.ForWrite)
                'Dim acVpTRec As ViewportTableRecord
 
 
                'I have tried the following lines. All give the same error.
                Dim acVpTRec As ViewportTableRecord = acTrans.GetObject(ed.ActiveViewportId, OpenMode.ForWrite)
                'acVpTRec = acTrans.GetObject(ed.CurrentViewportObjectId, OpenMode.ForWrite)
                'acVpTRec = CType(acTrans.GetObject(ed.ActiveViewportId, OpenMode.ForWrite), ViewportTableRecord)
                'acVpTRec = CType(acTrans.GetObject(ed.CurrentViewportObjectId, OpenMode.ForWrite), ViewportTableRecord)
                'acVpTRec = CType(acTrans.GetObject(ed.ActiveViewportId, OpenMode.ForWrite), Autodesk.AutoCAD.DatabaseServices.ViewportTableRecord)
 
                Dim VpTRecID As Autodesk.AutoCAD.DatabaseServices.ObjectId
                'grab current User Coordinate System.
                VpTRecID = ed.ActiveViewportId
 
                'Set to World
                acVpTRec.SetUcsToWorld()
                'return to User
                acVpTRec.SetUcs(VpTRecID)
            End Using
        End Using
    End Sub
1 REPLY 1
Message 2 of 2
Marat.Mirgaleev
in reply to: PTipton

Could you, please, check that it is the cause of the issue:

[from ObjectARX\docs\arxref.chm]

AcDbObjectId acedActiveViewportId();
Description
Returns the object ID of the viewport that is currently active in the editor. In tilemode, it returns the ID is of a viewport table record. In layout mode, returns the object ID of a viewport entity .

Have you tried to cast to Viewport? I guess you can see the actual type of the object in the debugger's Watch window.



Marat Mirgaleev
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost