I'm just finishing up with a command that sets up custom paperspaces for our designers, and once it's done, it deletes the default Layout1 and Layout2 paperspace. The error i'm getting though is the following:
If a drawing contains Layout1 and Layout2, both are deleted as they should be
If a drawing contains Layout1 but not Layout2
If a drawing contains Layout2 but not Layout1
I get an error and it crashes. This seems really stupid i know, but i must be doing something wrong here. I'm using if statements to determine if Layout1 exists, then delete it, and if Layout2 exists, then delete it. However, it seems that everytime, if one of those layouts are missing, it still assumes it's there, tries to delete it, and errors out because it doesn't exist. I've tried many variations of "if" statements. If someone could point me in the right direction, that would be awesome.
public class CHDelete
// This function will delete Layout1 and Layout2
public void CHRENAMECOMMAND()
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.D
Database db = doc.Database;
Editor ed = doc.Editor;
using (DocumentLock acLckDoc = doc.LockDocument())
using (Transaction trx = db.TransactionManager.StartTransaction())
LayoutManager lm = LayoutManager.Current;
LayerTable acLyrTbl; acLyrTbl = trx.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
if (acLyrTbl.Has("Layout1") == false)
if (acLyrTbl.Has("Layout2") == false)
Solved! Go to Solution.
your code looks like you have difficulties in differencing the object types of "Layer" and "Layout".
On one side you write you want to delete the "Layout1" but you look to
and that does not fit together!
- alfred -