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

error - reload , save and close

1 REPLY 1
Reply
Message 1 of 2
Anonymous
339 Views, 1 Reply

error - reload , save and close

Hi,

I trying to open dwg files in a folder one by one change its xrefs to overlay,reload xrefs and save the dwg and close and the do the same with next one.  But I am facing problems in ReloadXrefs and DocumentExtension.CloseAndSave. I am using the following code:

Public Sub processxref()
            

            Dim txtbx As String = "D:\sanjay\Autocad\XrefToOverlayDATA\test\"
            For Each File As FileInfo In New DirectoryInfo(txtbx).GetFiles("*.dwg", SearchOption.AllDirectories)
                Try
                    Dim ids As ObjectIdCollection = New ObjectIdCollection()
                    Dim doc As Document = DocumentCollectionExtension.Open(Application.DocumentManager, File.FullName, False)
                    Application.DocumentManager.MdiActiveDocument = doc
                    Dim db As Database = doc.Database
                    Dim ed As Editor = doc.Editor
                    Using (doc.LockDocument())
                        Using tr As Transaction = db.TransactionManager.StartTransaction()
                            Dim dlock As DocumentLock = doc.LockDocument()
                            Dim hs As HostApplicationServices = HostApplicationServices.Current

                            Dim table As BlockTable = CType(tr.GetObject(db.BlockTableId, OpenMode.ForWrite), BlockTable)
                            For Each id As ObjectId In table
                                Try
                                    Dim record As BlockTableRecord = CType(tr.GetObject(id, OpenMode.ForRead), BlockTableRecord)
                                    If record.IsFromExternalReference Then
                                        record.UpgradeOpen()
                                        record.IsFromOverlayReference = True
                                        record.PathName = ""
                                        ids.Add(id)
                                    End If
                                Catch ex As Autodesk.AutoCAD.Runtime.Exception
                                    Dim tt As String = ""
                                End Try
                            Next
                            tr.Commit()
                            If (ids.Count <> 0) Then
                                db.ReloadXrefs(ids)
                            End If
                        End Using
                        Try
                            DocumentExtension.CloseAndSave(doc, File.Name)
                        Catch ex As System.Exception
                            Dim got As String = ex.ToString
                        End Try
                    End Using
                Catch ex1 As System.Exception
                    Dim got1 As String = ex1.ToString
                End Try
            Next
        End Sub

Thanks  Regards

Sanjay Pandey

1 REPLY 1
Message 2 of 2
Virupaksha_aithal
in reply to: Anonymous

Hi,

 

Looks like code is locking the document multiple times ( Dim dlock As DocumentLock = doc.LockDocument())

My suggestion is to create a code/command which works for the current open drawing. Then you can convert the code to work for multiple drawings.

 

 



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report