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

erase Viewport

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
739 Views, 4 Replies

erase Viewport

Hi,

I'm creating a new Layout in my Drawing. After that I try to erase all Viewports in this new Layout. I'm using the Viewport.erase() method. After erasing the Viewports I try to manually open the Layermanager but it crashes and gives the "eInvalidObjectId"-Exception. Maybe there is any Reference on the erased Viewport?

Thank you,

Jo
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

It would be easier to get an answer if you supplied the relevant code.
Message 3 of 5
Anonymous
in reply to: Anonymous

Oh I'm sorry.

Here is the Code...


Document doc2 = Application.DocumentManager.MdiActiveDocument;
DocumentLock dLock = doc2.LockDocument();
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
BlockTable bt = tm.GetObject(db.BlockTableId, OpenMode.ForRead, false) as BlockTable;
string Name; //Layoutname
Autodesk.AutoCAD.DatabaseServices.LayoutManager lm = Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current;
Transaction t2 = tm.StartTransaction();
try
{
lm.CreateLayout(Name);
lm.CurrentLayout = Name;
Autodesk.AutoCAD.DatabaseServices.ObjectId objId = lm.GetLayoutId(Name);
lay = (Layout)t2.GetObject(objId, OpenMode.ForWrite);
CreatePagesetup(db, tm, lay);//
r = (BlockTableRecord)t2.GetObject(lay.BlockTableRecordId, OpenMode.ForWrite);
//List VPDELLIST = new List();
//VPDELLIST.Clear();
Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection IDColl = new Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection();
IDColl.Clear();
foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId VPID in lay.GetViewports())
{
IDColl.Add(VPID);
}
Viewport vpdel = new Viewport();
foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId VPID in IDColl)
{

//Here is the Problem. When I erase the Viewport everthing seems to be right. Viewport isn't shown. But when I enter the Layoutmanager after the Function is completed, it crashes...
vpdel = (Viewport)t2.GetObject(VPID, OpenMode.ForWrite);
vpdel.Erase();
}
CreateViewport(r, lay, db, tm, ed, LayoutTyp, Geschoss);
ed.Regen();
IDColl.Dispose();
t2.Commit();
vpdel.Dispose();
}

catch
{
t2.Abort();
System.Windows.Forms.MessageBox.Show("Fehler!", "Abbruch");
}
finally
{
t2.Dispose();
}
tm.Dispose();
dLock.Dispose();


Thanks...
Message 4 of 5
Anonymous
in reply to: Anonymous

See the documentation for the AcDbLayout::getViewportArray()
Function in the ObjectARX docs (which is what the GetViewports()
method wraps).

Note what it says about the first element in the returned array,
and keep in mind that you should never erase the paperspace
viewport (e.g., the viewport contaning all paper space objects,
including model space viewports).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5747776@discussion.autodesk.com...
Oh I'm sorry.

Here is the Code...


Document doc2 = Application.DocumentManager.MdiActiveDocument;
DocumentLock dLock = doc2.LockDocument();
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
BlockTable bt = tm.GetObject(db.BlockTableId, OpenMode.ForRead, false) as BlockTable;
string Name; //Layoutname
Autodesk.AutoCAD.DatabaseServices.LayoutManager lm = Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current;
Transaction t2 = tm.StartTransaction();
try
{
lm.CreateLayout(Name);
lm.CurrentLayout = Name;
Autodesk.AutoCAD.DatabaseServices.ObjectId objId = lm.GetLayoutId(Name);
lay = (Layout)t2.GetObject(objId, OpenMode.ForWrite);
CreatePagesetup(db, tm, lay);//
r = (BlockTableRecord)t2.GetObject(lay.BlockTableRecordId, OpenMode.ForWrite);
//List VPDELLIST = new List();
//VPDELLIST.Clear();
Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection IDColl = new Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection();
IDColl.Clear();
foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId VPID in lay.GetViewports())
{
IDColl.Add(VPID);
}
Viewport vpdel = new Viewport();
foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId VPID in IDColl)
{

//Here is the Problem. When I erase the Viewport everthing seems to be right. Viewport isn't shown. But when I enter the Layoutmanager after the Function is completed, it crashes...
vpdel = (Viewport)t2.GetObject(VPID, OpenMode.ForWrite);
vpdel.Erase();
}
CreateViewport(r, lay, db, tm, ed, LayoutTyp, Geschoss);
ed.Regen();
IDColl.Dispose();
t2.Commit();
vpdel.Dispose();
}

catch
{
t2.Abort();
System.Windows.Forms.MessageBox.Show("Fehler!", "Abbruch");
}
finally
{
t2.Dispose();
}
tm.Dispose();
dLock.Dispose();


Thanks...
Message 5 of 5
Anonymous
in reply to: Anonymous

I don't know if it's going to help you but there is someting I noticed when I was trying to work with objects on the paper space.

I made a function that allows me to select all the objects on a certain layer (it returns the objectID of all the items in a collection) on the modelSpace or a Layout.

When I tried to select all the Items on layer 0, on any Layout, the first item of the collection was always a viewport, even if I had no viewport on the Layout.

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