.NET

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

Database set current layout

242 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 (196 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
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.