Here is another approach to getting the current view param's.
I'm having trouble setting the view centre, acedTrans'ing it in a large model put's me out in the paddock so some work needs to be done there.
This sets up a view to the current ucs z direction using the current vport size (plus a bit more to centre the view just a little). I will probably use a db object's extents to set up a view with clipping for my application needs but this is a start.
Many thanks Glenn and to rwilkins (from the adesk ng).
[DllImport("acad.exe",CallingConvention=CallingConvention.Cdecl,
EntryPoint = "?acedSetCurrentView@@YA?AW4ErrorStatus@Acad@@PAVAcDbViewTableRecord@@PAVAcDbViewport@@@Z")]
private static extern int acedSetCurrentView(IntPtr pVtr, /*IntPtr.Zero*/IntPtr pVP);
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedTrans")]
static extern int acedTrans(double[] point, IntPtr fromRb, IntPtr toRb, int disp, double[] result);
[DllImport("acad.exe", CallingConvention=CallingConvention.Cdecl,
EntryPoint="?acedVports2VportTableRecords@@YA?AW4ErrorStatus@Acad@@XZ")]
private static extern bool acedVports2VportTableRecords();
[CommandMethod("ViewTest2")]
static public void MickyDViewCommand2()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
try
{
if(db.TileMode == true)//make sure we're in model space, else leave:
{
//convert current vport info to our viewtable objects:
//note:there can be more than one view
acedVports2VportTableRecords();
//get the current view, should be the first un-erased viewtable record:
ViewportTable vpt = (ViewportTable)tr.GetObject(db.ViewportTableId,OpenMode.ForRead);
ViewportTableRecord currVptr = null;
foreach(ObjectId id in vpt)
{
if(!id.IsErased)
{
//got the first un erased record, return:
currVptr = (ViewportTableRecord)tr.GetObject(id,OpenMode.ForRead);
break;
}
}
//use some of the info in the current vtr to set to our new one:
ViewTableRecord newVtr = new ViewTableRecord();
newVtr.IsPaperspaceView = false;
newVtr.Target = db.Ucsorg;
newVtr.Height = currVptr.Height*2;
newVtr.Width = currVptr.Width*2;
newVtr.ViewDirection = db.Ucsxdir.CrossProduct(db.Ucsydir);
//set the new view:
acedSetCurrentView(newVtr.UnmanagedObject, IntPtr.Zero);
//Just to be safe...
newVtr.Dispose();
}
tr.Commit();
}
finally
{
tr.Dispose();
}
}