.NET

Reply
Member
marekbecica
Posts: 4
Registered: ‎02-26-2014
Message 1 of 2 (222 Views)
Accepted Solution

Database set current layout

222 Views, 1 Replies
02-26-2014 05:35 AM

I'm trying to write application which will load database of the drawing and delete all layouts except given one. It works fine when current layout is Model or the layout which will be kept, but when current layout is the one which was deleted, it fails to open the drawing and crash AutoCAD. So I need to set current layout to the one which will not be deleted before deleting the others. And I got stuck at this point, I haven't found any solution how to set current layout to the drawing database.
There are LayoutManager or variable CTAB which works just fine when I open drawing as a Document, but I need to do it without opening drawing.

...
db.ReadDwgFile(dwgPath, FileOpenMode.OpenForReadAndWriteNoShare, True, "")
... Using tr As Transaction = db.TransactionManager.StartTransaction() Try Dim layoutDict As DBDictionary = CType(tr.GetObject(db.LayoutDictionaryId, OpenMode.ForWrite), DBDictionary) For Each de As DBDictionaryEntry In layoutDict Dim layoutName As String = de.Key
If layoutName="Model" Then 'Current layout need to be set
'LayoutManager.Current.CurrentLayout=keepLayout => doesn't work for not opened drawings
'db.CurrentSpaceId = de.Value => doesn't work because it's readonly End If
If (layoutName <> "Model" And layoutName.ToLower <> keepLayout.ToLower) Then Dim layoutDel As Layout = DirectCast(tr.GetObject(de.Value, OpenMode.ForRead), Layout) layoutDel.UpgradeOpen() layoutDel.Erase() layoutDel.DowngradeOpen() End If Next tr.Commit() Catch ex As System.Exception MsgBox(ex.Message & ex.StackTrace) End Try End Using
db.SaveAs(output, False, DwgVersion.Current, db.SecurityParameters)
...

 Thanks for any help.

Finally I found how to do it.

If you use this to set your loaded database as working database

HostApplicationServices.WorkingDatabase = db

 then you can use LayoutManager.Current

Member
marekbecica
Posts: 4
Registered: ‎02-26-2014
Message 2 of 2 (176 Views)

Re: Database set current layout

03-04-2014 03:02 AM in reply to: marekbecica

Finally I found how to do it.

If you use this to set your loaded database as working database

HostApplicationServices.WorkingDatabase = db

 then you can use LayoutManager.Current

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.