Getting Started Common Acronyms FAQ Forum Help Forum Tips Secure File Upload Helpful GuidelinesInserting and Attaching images, videos, or files to postsProduct Community Directory SELECTsupport
James,
You want to lok at the .Reattach() method of the Attachment object. It will let you reattach with a different path. Follow that with a call to the .Rewrite() method.
Whilst MS_RFDIR is one way around this, I much prefer the use of relative paths.
With MS_RFDIR we have had instances of users opening and printing DGN for 'Option 1' of a project, and because they didn't pay attnetion to the PCF file they were using, all the background reference files were comign from the 'Option 2' directories. End result, lots of printed drawings where the title block said 'Option 1' but the design shown on the drawings was actually 'Option 2'. Nearly a very expensive error if they'd been issued. MS_RFDIR also can cuase problems if you have reference files with the same names in different directories. You'll alsways get the one that is first on the MS_RFDIR path.
The code below should convert reference to relative paths, but it's a long while since I used it...
Private Declare Function PathRelativePathTo Lib "shlwapi.dll" Alias "PathRelativePathToA" (ByVal pszPath As String, ByVal pszFrom As String, ByVal dwAttrFrom As Long, ByVal pszTo As String, ByVal dwAttrTo As Long) As Long Private Const MAX_PATH As Long = 260 Private Const FILE_ATTRIBUTE_DIRECTORY As Long = &H10 Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80 '----------------------------------------------------------- ' Creates a relative path from one file or folder to another. ' ' made by Alexander Triantafyllou alextriantf@yahoo.gr 'This code is copyrighted and has limited warranties. 'Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.50088/lngWId.1/qx/vb/scripts/ShowCode.htm ' ' usage relative_path=get_relative_path_to(root_path,file_path) ' get_relative_path_to("d:\a\b\c\d","d:\a\b\index.html") will return ' "..\..\index.html" ' use FILE_ATTRIBUTE_DIRECTORY if the path is a directory ' or FILE_ATTRIBUTE_NORMAL if the path is a file '----------------------------------------------------------
Public Function get_relative_path_to(ByVal parent_path As String, ByVal child_path As String) As String Dim out_str As String Dim par_str As String Dim child_str As String out_str = String(MAX_PATH, 0) par_str = parent_path + String(100, 0) child_str = child_path + String(100, 0) PathRelativePathTo out_str, par_str, FILE_ATTRIBUTE_DIRECTORY, child_str, FILE_ATTRIBUTE_NORMAL out_str = StripTerminator(out_str) 'MsgBox out_str get_relative_path_to = out_str End Function
'Remove all trailing Chr$(0)'s Function StripTerminator(sInput As String) As String Dim ZeroPos As Long ZeroPos = InStr(1, sInput, Chr$(0))
If ZeroPos > 0 Then StripTerminator = Left$(sInput, ZeroPos - 1) Else StripTerminator = sInput End If End Function
Sub SetRelativePathPref() ' Set the dialog box value SetCExpressionValue "userPrefsP->refFilePrefs.saveRelativePath", 1, "REF" End Sub
' Call this function to change all attachments to relative Function UpdateToRelativeRefPath() As String Dim i As Integer Dim txtRefFileName As String Dim txtRefAbsolutePath As String Dim txtRefRelativePath As String Dim txtThisFileDirectory As String Dim txtModelName As String Dim blnWasDisplayOff As Boolean Dim ref As Attachment Call SetRelativePathPref For i = 1 To ActiveModelReference.Attachments.count Set ref = ActiveModelReference.Attachments.Item(i) 'Reset the txt variables txtRefFileName = "" txtThisFileDirectory = "" txtRefAbsolutePath = "" txtRefRelativePath = "" txtModelName = "" blnWasDisplayOff = False 'Debug.Print Left(ref.AttachName, 9) If Not ref.IsMissingFile Then If Not ref.ElementsVisible Then blnWasDisplayOff = True ref.ElementsVisible = True ref.Rewrite End If txtRefFileName = ref.DesignFile.FullName txtThisFileDirectory = ActiveDesignFile.Path txtRefAbsolutePath = ref.DesignFile.Path txtRefRelativePath = get_relative_path_to(txtThisFileDirectory, txtRefFileName) If Left(txtRefRelativePath, 3) = "..\" Then Set ref = ref.Reattach(txtRefRelativePath, vbNullString) ref.Rewrite UpdateToRelativeRefPath = UpdateToRelativeRefPath & "Changed " & txtRefFileName & _ " to " & txtRefRelativePath & vbCrLf ElseIf Left(txtRefRelativePath, 2) = ".\" And InStr(3, txtRefRelativePath, "\") > 0 Then Set ref = ref.Reattach(txtRefRelativePath, vbNullString) ref.Rewrite UpdateToRelativeRefPath = UpdateToRelativeRefPath & "Changed " & txtRefFileName & _ " to " & txtRefRelativePath & vbCrLf End If
' Turn off if it was on before If blnWasDisplayOff Then ref.ElementsVisible = False ref.Rewrite End If End If Next End Function
James: How can I change the Path of my Reference File attachments?
The smart move would be to attach reference files using configuration variables (CfgVars). In particular, CfgVar MS_RFDIR tells MicroStation where to look for reference files. Your DGN does not have to store the full path of each reference.
If you use MS_RFDIR, then changing from Server1 to Server2 is as simple as redefining that variable. No VBA required.
Regards, Jon Summers LA Solutions
We are having to move our server folders. How can I change the Path of my Reference File attachments? I can retrieve the Path but cannot rewrite the path. I get the message: "Can't assign to read-only property"
Thanks, James.......................