Hello Ppl,
I am trying to programmatically apply updates to a set of .dwg drawings, one of which involves inserting a block as per the below code. However, as per the subject line, I'm having trouble going about saving the resultant drawing to the filesystem even though it's to a different folder. The error message is "Error writing/closing file" when I use Database.SaveAs()
If I use the call to Document.CloseAndSave() instead, AutoCAD crashes, even when I've got a lock on the Document. Could somebody kindly shed some light on what I am doing wrong, and the proper way to go about it?
From the C++ samples I've checked, I shouldn't be too far from getting it right.. but that's not good enough yet. Thanks.
=====================================================
Public Shared Sub InsertSymbol(ByVal doc As Document, ByVal dwgPath As String, ByVal insertPoint As Point3d, Optional ByRef attribValues As StringDictionary = Nothing, Optional ByVal prompt As Boolean = False)
' dim loc as DocumentLock = doc.LockDocument()
Using t As Transaction = doc.TransactionManager.StartTransaction(), db As Database = New Database(False, False)
'read drawing
db.ReadDwgFile(dwgPath, FileShare.Read, True, Nothing)
'insert it as a new block
Dim idBTR As ObjectId = doc.Database.Insert("Watermark", db, True)
'create a ref to the block
Using bt As BlockTable = t.GetObject(doc.Database.BlockTableId, OpenMode.ForRead), _
btr As BlockTableRecord = t.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), _
bref As BlockReference = New BlockReference(insertPoint, idBTR)
btr.AppendEntity(bref)
doc.TransactionManager.AddNewlyCreatedDBObject(bref, True)
Dim ed As Autodesk.AutoCAD.EditorInput.Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage("DWG Added")
End Using
t.Commit()
db.SaveAs("multicomponent_dyn.dwg", DwgVersion.Current) ' or doc.CloseAndSave("multicomponent_dyn.dwg")
' loc.Dispose()
End Using
End Sub
=====================================================
Rico.