Changing multiple references

If I have a large amount of .dgn files which have a reference attached, located say for example in "C:\REFONE". Is there a batch process or an automated way I can change the reference in all the files to "C:\REFTWO" ?

Directories are made up, I just want to know if i can change all the existing ref directories for another.

Parents
  • Hi,

    I've used this routine in the past to fix some of my drawings:

    Sub ReferenceNameReplace()
        Dim oldString As String
        Dim newString As String
        Dim OldFileName As String
        oldString = "Details11"
        newString = "Details13"
       
        For Each AttachedFile In ActiveModelReference.Attachments
            OldFileName = AttachedFile.AttachName
            If Left(OldFileName, Len(oldString)) = oldString Then
                NewAttachmentName = newString & Right(OldFileName, Len(OldFileName) - Len(oldString))
                AttachedFile.SetAttachNameDeferred NewAttachmentName
                AttachedFile.Rewrite
            End If
        Next
    End Sub

    In your case, the old string is the old path and the new string is either the new path or a configuration variable and a colon.  You could use a batch command to run this on each file (vba run ReferenceNameReplace), or you could continue it in vba and have vba open each file and then run the command.

    Please note that I am using SetAttachedNameDEFERRED, which means that the new file will not show up until the drawing is re-opened.  If you're doing this on multiple files, it will save time not loading up the new file.

    --Robert

Reply
  • Hi,

    I've used this routine in the past to fix some of my drawings:

    Sub ReferenceNameReplace()
        Dim oldString As String
        Dim newString As String
        Dim OldFileName As String
        oldString = "Details11"
        newString = "Details13"
       
        For Each AttachedFile In ActiveModelReference.Attachments
            OldFileName = AttachedFile.AttachName
            If Left(OldFileName, Len(oldString)) = oldString Then
                NewAttachmentName = newString & Right(OldFileName, Len(OldFileName) - Len(oldString))
                AttachedFile.SetAttachNameDeferred NewAttachmentName
                AttachedFile.Rewrite
            End If
        Next
    End Sub

    In your case, the old string is the old path and the new string is either the new path or a configuration variable and a colon.  You could use a batch command to run this on each file (vba run ReferenceNameReplace), or you could continue it in vba and have vba open each file and then run the command.

    Please note that I am using SetAttachedNameDEFERRED, which means that the new file will not show up until the drawing is re-opened.  If you're doing this on multiple files, it will save time not loading up the new file.

    --Robert

Children