View Table

View Table

Anonymous
Not applicable
465 Views
1 Reply
Message 1 of 2

View Table

Anonymous
Not applicable
Good Morning,

I have a simple program that when run checks if a given view is in the View Table for a drawing, if it is it will load it by default. The program works fine when it checks for the view. However the problem I am running into is that it does not change to the view afterwards. Any thoughts? Code below.

<code>

[CommandMethod("def")]
static public void DefViewLoad() // This method can have any name
{
//Set current application session
AcadApplication app;
app = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;



// Get current DWG Database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acDB = acDoc.Database;

//Set Editor to save typing
Editor ed = acDoc.Editor;

//Start Transaction to play with DWG.

using (Transaction acTran = acDB.TransactionManager.StartTransaction())
{
//Open current drawing layer table listing and read.
ViewTable acVT;
acVT = acTran.GetObject(acDB.ViewTableId, OpenMode.ForRead) as ViewTable;
ViewTableRecord acVTRec = new ViewTableRecord();

if (acVT.Has("test")==true)
{
ed.WriteMessage("test works");
acVTRec.Name = "test";

ed.SetCurrentView(acVTRec);

}

acTran.Commit();
}


ed.Regen();

}

}
}


</code>
0 Likes
466 Views
1 Reply
Reply (1)
Message 2 of 2

chiefbraincloud
Collaborator
Collaborator

You have simply created a new ViewTableRecord (with defaults which would match the currently active settings), then named it "test" and set the view.  You need to open the existing record to pass to SetCurrentView.

 

I use VB, so I'm not going to try too hard to get this syntax right, but you should get the idea.

 

if (acVT.Has("test")==true)  // This can return true for erased objects
{
ed.WriteMessage("test works");
acVTRec = acTran.GetObject(acVT("test"), OpenMode.ForRead, False); //Open the record
  // I would check here to make sure acVtRec.IsErased = False

  if (acVTRec.IsErased==false)

  {
  ed.SetCurrentView(acVTRec);
  }
}

Dave O.                                                                  Sig-Logos32.png
0 Likes