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

Database set current layout

1 REPLY 1
SOLVED
Reply
Message 1 of 2
marekbecica
1001 Views, 1 Reply

Database set current layout

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.

1 REPLY 1
Message 2 of 2
marekbecica
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

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