Author Topic: Get and change current view  (Read 16612 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Get and change current view
« Reply #15 on: June 12, 2006, 10:10:14 PM »
Ooohhhh ... bookmarked .. !

Thanks Glenn
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Get and change current view
« Reply #16 on: June 13, 2006, 02:33:42 AM »
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).

Code: [Select]
                [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();
}
}
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Get and change current view
« Reply #17 on: February 23, 2008, 03:03:53 AM »

Glenn, Mick :
Thanks for this ... I'm doing some prep' work for next weekend :-)

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: Get and change current view
« Reply #18 on: February 23, 2008, 04:57:27 PM »
What's happening next weekend Kerry...???

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Get and change current view
« Reply #19 on: February 23, 2008, 04:59:32 PM »

What's happening next weekend Kerry...???

I'll be writing some code, just for a change ... :-)
just planning this weekend .. and doing some painting.
« Last Edit: February 23, 2008, 05:09:34 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.