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

CloseAndSave problem

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
543 Views, 5 Replies

CloseAndSave problem

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
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous


Reading this newsgroup and searching (if you can, that is)
on

the phrase 'SendStringToExecute' might help.

 

SendStringToExecute() is just like VBA's SendCommand(),
it's

asynchronous, meaning that it returns before the commands
that

you pass it have finished.

 

For that reason, I seriously doubt that what you're
attempting

to do is going to work.

 


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000
through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
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
Message 3 of 6
Anonymous
in reply to: Anonymous


Many thanks Tony, as ever. Is there a programmatic
equivalent of attsync or a workaround you can think of?


--
Regards

 

Dave Preston


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Reading this newsgroup and searching (if you can, that is)
on

the phrase 'SendStringToExecute' might help.

 

SendStringToExecute() is just like VBA's SendCommand(),
it's

asynchronous, meaning that it returns before the commands
that

you pass it have finished.

 

For that reason, I seriously doubt that what you're
attempting

to do is going to work.

 


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000
through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
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
Message 4 of 6
Anonymous
in reply to: Anonymous


I suppose I could run ScriptPro on all files and
just do the attsync in a script file


--

Regards

 

Dave Preston


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Many thanks Tony, as ever. Is there a
programmatic equivalent of attsync or a workaround you can think
of?


--
Regards

 

Dave Preston


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Reading this newsgroup and searching (if you can, that is)
on

the phrase 'SendStringToExecute' might help.

 

SendStringToExecute() is just like VBA's SendCommand(),
it's

asynchronous, meaning that it returns before the commands
that

you pass it have finished.

 

For that reason, I seriously doubt that what you're
attempting

to do is going to work.

 


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD
2000 through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
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
Message 5 of 6
Anonymous
in reply to: Anonymous


Aside from writing your own attsync, I think the
only

alternative is script pro.


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000
through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Many thanks Tony, as ever. Is there a
programmatic equivalent of attsync or a workaround you can think
of?


--
Regards

 

Dave Preston


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Reading this newsgroup and searching (if you can, that is)
on

the phrase 'SendStringToExecute' might help.

 

SendStringToExecute() is just like VBA's SendCommand(),
it's

asynchronous, meaning that it returns before the commands
that

you pass it have finished.

 

For that reason, I seriously doubt that what you're
attempting

to do is going to work.

 


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD
2000 through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
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
Message 6 of 6
Anonymous
in reply to: Anonymous


I've already run the first phase that swaps the
blocks on 500+ files

The problem with ScriptPro is that it is slow.
Never mind, thanks for your help Tony


--
Regards

 

Dave Preston


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Aside from writing your own attsync, I think the
only

alternative is script pro.


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000
through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Many thanks Tony, as ever. Is there a
programmatic equivalent of attsync or a workaround you can think
of?


--
Regards

 

Dave Preston


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Reading this newsgroup and searching (if you can, that
is) on

the phrase 'SendStringToExecute' might
help.

 

SendStringToExecute() is just like VBA's SendCommand(),
it's

asynchronous, meaning that it returns before the
commands that

you pass it have finished.

 

For that reason, I seriously doubt that what you're
attempting

to do is going to work.

 


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD
2000 through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
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

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