Bind and save

Bind and save

Anonymous
Not applicable
1,292 Views
7 Replies
Message 1 of 8

Bind and save

Anonymous
Not applicable
Ok, I have put together a tool that goes through and batch binds, prints, PDF's and DWF's files (subject to user choice) everything works fine except once its finished with the drawing its publishing it closes and doesnt seem to save (none of the xrefs are bound when opened again) although if I watch the process I can see the refs being removed in the xref manager.

here is a snippet of code but dont know if you would want to see the actual bind process, PUBpage has a number of process indicators that show the progress:

Help please someone must know what im doing wrong.

{code}
Dim dwg
dwg = Application.DocumentManager.Open(DestinationFile, False)
Dim ThisDrawing As Document = Application.DocumentManager.MdiActiveDocument
Using LockDB As DocumentLock = ThisDrawing.LockDocument()
'-----------secondary publish--------------
'Bind drawings
If lines(2) = 1 Then
'progress meter
pubPage.BoundProgress.Value = ((ActionList.Items.Count * 100) - (j * 100))
pubPage.BoundVal.Text = j
bindAllDrawings()
End If

If lines(5) = 1 Then
'Print DWFs''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
PrintDWFFiles(lines, FinIsFolder.Text & "\" & Strings.Left(DWGNm, Len(DWGNm) - 4))
'progress meter
pubPage.DWFProgress.Value = ((ActionList.Items.Count * 100) - (j * 100))
pubPage.DWFVal.Text = j
End If

'Print PDFs
If lines(6) = 1 Then
PrintPDFFiles(lines, FinIsFolder.Text & "\" & Strings.Left(DWGNm, Len(DWGNm) - 4))
'progress meter
pubPage.PDFProgress.Value = ((ActionList.Items.Count * 100) - (j * 100))
pubPage.PDFVal.Text = j
End If
'close and save the drawing

Dim DB As Database = ThisDrawing.Database
DB.SaveAs(DWGNm, DwgVersion.Current)

End Using
ThisDrawing.CloseAndSave(DWGNm)
ThisDrawing.Dispose()

Next
{code}

Daniel Edited by: dheselwood on May 1, 2009 9:16 AM
0 Likes
1,293 Views
7 Replies
Replies (7)
Message 2 of 8

arcticad
Advisor
Advisor
This will get the Xref list and bind the files.


{code}
Public Sub QuickBind()
Dim dwg As Document
Dim DestinationFile As String = "c:\test\myFile.dwg"
dwg = Application.DocumentManager.Open(DestinationFile, False)
Dim ThisDrawing As Document = Application.DocumentManager.MdiActiveDocument
Using LockDB As DocumentLock = ThisDrawing.LockDocument()
Dim db As Database = dwg.Database
Dim transMan As DatabaseServices.TransactionManager = db.TransactionManager
Using trans As Transaction = transMan.StartTransaction
Dim iDColl As New ObjectIdCollection
' get list of Xref's
getXref(db, iDColl)
If iDColl.Count > 0 Then
db.BindXrefs(iDColl, False)
trans.Commit()
db.SaveAs(DestinationFile, DwgVersion.Current)
Else
trans.Commit()
End If
End Using
End Using
ThisDrawing.CloseAndDiscard()
End Sub


Public Sub getXref(ByVal db As Database, ByRef idColl As ObjectIdCollection)

Dim transMan As DatabaseServices.TransactionManager = db.TransactionManager
Using trans As Transaction = transMan.StartTransaction
Dim xrgraph As XrefGraph = db.GetHostDwgXrefGraph(False)
' look at all Nodes in the XrefGraph. Skip 0 node since it is the drawing itself.
For i As Integer = 1 To (xrgraph.NumNodes - 1)
Dim xrNode As XrefGraphNode = xrgraph.GetXrefNode(i)
Dim btr As BlockTableRecord = DirectCast(trans.GetObject(xrNode.BlockTableRecordId, OpenMode.ForWrite), BlockTableRecord)
' Add Xref's to Collection
idColl.Add(btr.ObjectId)
Next
End Using
End Sub
{code}
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 3 of 8

Anonymous
Not applicable
The binding function works fine, If I (dare I say it) place in a sendCommandToExecute("qsave close ") and close the drawing that way, it saves all changes and when I open, all the references are saved, the problem I have is that I can seem to do it with the closeAndSave feature, just doesnt seem to save anything? Its Bizarre.
0 Likes
Message 4 of 8

arcticad
Advisor
Advisor
Make sure you commit your transaction before saving
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 5 of 8

norman.yuan
Mentor
Mentor
DataBase.SaveAs() method is not implemeted, AFAIK. That is, it does nothing. You need to use different approach to save your changed drawing.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 8

arcticad
Advisor
Advisor
Why do you say that? It works fine for me.
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 7 of 8

Anonymous
Not applicable
SaveAs() works, it's Save() that doesn't do anything.

--
http://www.caddzone.com

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

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6175104@discussion.autodesk.com...
Why do you say that? It works fine for me.
0 Likes
Message 8 of 8

Anonymous
Not applicable
Hi Tony,

Most of the time, db.SaveAs command works fine, but sometimes, this command and the automatic saving commands produces some error : it always save my file at its opening state. That is to say that all my modifications are suppressed, and the drawing return to its opening state, Every update is lost !
Do you have an idea of what is happening ?

Thanks a lot for all your help.
0 Likes