Results 1 to 6 of 6

Thread: Changing Xref Paths

  1. #1
    100 Club
    Join Date
    2002-10
    Posts
    154
    Login to Give a bone
    0

    Default Changing Xref Paths

    I can't figure this one out. I am trying to modify the path of xrefs in a file. It seams to work as I watch it go through it's loops but it does not save the information. I have tried a few other things but I have not had any luck. here is what I have so far....

    Code:
        Private Sub ModifyAllXrefPaths(ByVal FileName As String, ByVal NewPath As String)
            Dim mDB As New Autodesk.AutoCAD.DatabaseServices.Database
            mDB.ReadDwgFile(FileName, FileOpenMode.OpenForReadAndWriteNoShare, _\
                                        True, "")
            Dim mTransman As Autodesk.AutoCAD.DatabaseServices.TransactionManager = _
                                          mDB.TransactionManager
            Dim mTrans As Autodesk.AutoCAD.DatabaseServices.Transaction = _
                                          mTransman.StartTransaction
            Dim mBT As BlockTable = mTrans.GetObject(mDB.BlockTableId, _
                                          OpenMode.ForWrite, False)
    
            For Each mBTR_ID As ObjectId In mBT
                Dim mBTR As BlockTableRecord = mBTR_ID.GetObject(OpenMode.ForWrite)
                If mBTR.IsFromExternalReference Then
                    mBTR.PathName = Replace(mBTR.PathName.ToString, ".\", NewPath)
                    If InStr(mBTR.PathName.ToString, "\") Then
                        mBTR.PathName = NewPath & _
                               My.Computer.FileSystem.GetName(mBTR.PathName)
                    Else
                        mBTR.PathName = NewPath & mBTR.PathName
                    End If
                End If
            Next
            mTrans.Commit()
            mDB.CloseInput(True)
            mTrans.Dispose()
            mDB = Nothing
            mBT = Nothing
        End Sub
    Last edited by RobertB; 2010-08-03 at 12:30 AM. Reason: Added [code] tags

  2. #2
    100 Club
    Join Date
    2002-10
    Posts
    154
    Login to Give a bone
    0

    Default Re: Changing Xref Paths

    I have tried Save and SaveAs but they do not work either. Commit should have done it.

    I believe that it might not be accepting the entry when it switches to the next BlockTableRecord.

    Any help would be appreciated!!

  3. #3
    100 Club
    Join Date
    2002-10
    Posts
    154
    Login to Give a bone
    0

    Default Re: Changing Xref Paths

    I cleaned it up a little and added a few things in but I still can't get it to save the new paths.

    Code:
     Private Sub ModifyXrefPath(ByVal FileName As String, ByVal OrigPath As String, ByVal DestinationPath As String)
            Dim mDB As New Autodesk.AutoCAD.DatabaseServices.Database
            mDB.ReadDwgFile(FileName, FileOpenMode.OpenForReadAndWriteNoShare, True, "")
            Dim mTransman As Autodesk.AutoCAD.DatabaseServices.TransactionManager = mDB.TransactionManager
            Dim mTrans As Autodesk.AutoCAD.DatabaseServices.Transaction = mTransman.StartTransaction
            Dim mBT As BlockTable = mTrans.GetObject(mDB.BlockTableId, OpenMode.ForWrite, False)
    
            Using mTrans
                For Each mBTR_ID As ObjectId In mBT
                    Dim mBTR As BlockTableRecord = mBTR_ID.GetObject(OpenMode.ForWrite)
                    If mBTR.IsFromExternalReference Then
                        Dim mPathName As String = mBTR.PathName.ToString
                        mPathName = Replace(mPathName, ".\", OrigPath)
    
                        mDB.XrefEditEnabled = True
                        If InStr(origPath, "\") Then
                            mBTR.PathName = DestinationPath & My.Computer.FileSystem.GetName(mPathName)
                        Else
                            mBTR.PathName = DestinationPath & mPathName
                        End If
                    End If
                Next
                mTrans.Commit()
            End Using
            mDB.CloseInput(True)
            mTrans.Dispose()
        End Sub

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,584
    Login to Give a bone
    0

    Default Re: Changing Xref Paths

    Try this thread at the swamp.
    C:> ED WORKING....


    LinkedIn

  5. #5
    100 Club
    Join Date
    2002-10
    Posts
    154
    Login to Give a bone
    0

    Default Re: Changing Xref Paths

    I don’t know if this is the correct way of doing this but I managed to get it working. I loaded a couple of more references (acaz18enu.tlb and axdb18enu.tlb). Then I wrote the following code and it works great.

    Code:
    Private Sub ModifyXref(ByVal ParentFileName As String, ByVal OldSourceName As String, ByVal NewSourceName As String)
            Dim mDoc As New Autodesk.AutoCAD.Interop.Common.AxDbDocument
    
            mDoc.Open(ParentFileName)
            For Each mBlock As Autodesk.AutoCAD.Interop.Common.AcadBlock In mDoc.Blocks
                If mBlock.IsXRef Then
                    If mBlock.Path = OldSourceName Then mBlock.Path = NewSourceName
                End If
            Next
            mDoc.Save()
            mDoc = Nothing
        End Sub

  6. #6
    100 Club
    Join Date
    2002-10
    Posts
    154
    Login to Give a bone
    0

    Default Re: Changing Xref Paths

    correction... you need to use SaveAs instead of Save

    mDoc.SaveAs(ParentFileName)

Similar Threads

  1. changing xref paths
    By 3D Jack in forum AutoLISP
    Replies: 28
    Last Post: 2013-07-08, 05:06 PM
  2. XREF Paths All Messed Up
    By TerribleTim in forum CAD Management - General
    Replies: 23
    Last Post: 2013-07-08, 05:01 PM
  3. xref paths.
    By got_green in forum AutoCAD General
    Replies: 5
    Last Post: 2009-01-22, 05:33 PM
  4. Globally changing the drive letter of all xref paths
    By gregb.68838 in forum AutoLISP
    Replies: 7
    Last Post: 2005-06-20, 08:51 PM
  5. Xref paths
    By Coolmo in forum AutoLISP
    Replies: 5
    Last Post: 2005-02-10, 05:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •