Message 1 of 6
CloseAndSave problem
Not applicable
10-29-2008
07:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The following replaces all blocks with a file form disk then synchronises
attributes:-
Public Sub RefreshBlocks()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Using docLock As DocumentLock =
Application.DocumentManager.MdiActiveDocument.LockDocument()
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Try
If
'code to replace blocks here
End If
trans.Commit()
Catch ex As System.Exception
MsgBox(ex.Message)
Finally
trans.Dispose()
End Try
doc.SendStringToExecute("_attsync n *" & ControlChars.Cr, True, False,
False)
ed.Regen()
End Using
End Sub
This works perfectly well, but if I call it from a routine that opens a file
it all works except the attsync. The blocks actually get swapped and if I
exit the loop before the doc.closeandsave line the attributes actually
update. It's probably something basic but it's baffled me:-
Sub ProcessAllDWGS()
Try
Dim dir As New DirectoryInfo("L:\work\ASDA\StoreSpace\Drawings\Final
QA")
Dim files() As FileInfo
files = dir.GetFiles("*.dwg")
For Each file As FileInfo In files
Dim doc As Document =
Application.DocumentManager.Open(file.FullName, False)
RefreshBlocks()
doc.CloseAndSave(file.FullName)
doc.Dispose()
Next
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
--
Regards
Dave Preston
attributes:-
Public Sub RefreshBlocks()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Using docLock As DocumentLock =
Application.DocumentManager.MdiActiveDocument.LockDocument()
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Try
If
'code to replace blocks here
End If
trans.Commit()
Catch ex As System.Exception
MsgBox(ex.Message)
Finally
trans.Dispose()
End Try
doc.SendStringToExecute("_attsync n *" & ControlChars.Cr, True, False,
False)
ed.Regen()
End Using
End Sub
This works perfectly well, but if I call it from a routine that opens a file
it all works except the attsync. The blocks actually get swapped and if I
exit the loop before the doc.closeandsave line the attributes actually
update. It's probably something basic but it's baffled me:-
Sub ProcessAllDWGS()
Try
Dim dir As New DirectoryInfo("L:\work\ASDA\StoreSpace\Drawings\Final
QA")
Dim files() As FileInfo
files = dir.GetFiles("*.dwg")
For Each file As FileInfo In files
Dim doc As Document =
Application.DocumentManager.Open(file.FullName, False)
RefreshBlocks()
doc.CloseAndSave(file.FullName)
doc.Dispose()
Next
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
--
Regards
Dave Preston