Results 1 to 9 of 9

Thread: XREF: Absolute > Relative Path

  1. #1
    Member
    Join Date
    2000-10
    Location
    New England
    Posts
    7
    Login to Give a bone
    0

    Question XREF: Absolute > Relative Path

    Any way to automate the convertion of Saved Path of Xref(s) from Absolute to Relative?

    Want to convert a set of (parent) drawings (batch mode) without knowing the folder structure which would indicate the location of the (child) Xref(s). Manually making this change is much work opening file counting how many folders to backup before following path to (child) xref (ie. ..\..\..\folder\folder\child.dwg)

    Of course I would also have to fisrt check if DWG file has an xref.

    Thanks

  2. #2
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: XREF: Absolute > Relative Path

    If you put the xref in the same folder as the installation-drawing, it the installation drawing will find it automatically (relative path). This way the absolute path is not necessary anymore. Any other way requires an absolute path as far as I know.

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

    Default Re: XREF: Absolute > Relative Path

    Quote Originally Posted by darfnuggi View Post
    Any other way requires an absolute path as far as I know.
    If the file is on the same drive, you can still specify a relative dir using the old dos notation for a parent folder ".."
    C:> ED WORKING....


    LinkedIn

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

    Default Re: XREF: Absolute > Relative Path

    Quote Originally Posted by stephen View Post
    Want to convert a set of (parent) drawings (batch mode) without knowing the folder structure which would indicate the location of the (child) Xref(s).
    If you are using ACA or MEP, have you tried the Reference Manager?
    C:> ED WORKING....


    LinkedIn

  5. #5
    Member
    Join Date
    2008-02
    Location
    New York
    Posts
    29
    Login to Give a bone
    0

    Default Re: XREF: Absolute > Relative Path

    I wrote this awhile ago but it still works. It changes all xref and image paths from full path to relative path on the current drawing or on all the drawings in the current drawings folder. Let me know how it works for you.
    Code:
    Sub Runsall()
    Dim cmd As String
    Dim cmd2 As String
    
    cmd = ThisDrawing.Utility.GetString(False, "You are about to update all of the Xref and image paths from hard paths to relative paths. Would you like to continue?: Y/N:  ")
    If UCase(cmd) <> "Y" Then
    Exit Sub
    End If
    cmd2 = ThisDrawing.Utility.GetString(False, "Would you like to run this on the entire directory or the current drawing? D/C :  ")
    If UCase(cmd2) = "D" Then
    direct
    ElseIf UCase(cmd2) = "C" Then
    xrefpth
    End If
    End Sub
    Sub xrefpth()
    
    Dim a As Integer
    Dim l As Integer
    Dim c As Integer
    Dim D As Integer
    Dim i As Integer
    Dim pth As String
    Dim npath As String
    Dim newstr As String
    Dim tmpstr As String
    Dim xref As AcadExternalReference
    Dim ent As AcadEntity
    Dim img As AcadRasterImage
    Dim blkref As AcadBlockReference
    
    
    On Error Resume Next
    'Loop through the drawing and fid
    For i = 0 To ThisDrawing.ModelSpace.Count
        If ThisDrawing.ModelSpace.Item(i).ObjectName = "AcDbBlockReference" Then
            Set xref = ThisDrawing.ModelSpace.Item(i)
                
                    pth = xref.Path
                    l = Len(pth)
                        For a = 1 To l
                            tmpstr = Mid(pth, a, 1)
                                If tmpstr = "\" Then
                                    D = c
                                    c = a
                                    
                                 End If
                        Next a
                            newstr = Mid(pth, D)
                            npth = ".." & newstr
                            xref.Path = npth
                'End If
        ElseIf ThisDrawing.ModelSpace.Item(i) = "AcDbRasterImage" Then
            Set img = ThisDrawing.ModelSpace.Item(i)
                pth = img.ImageFile
                 l = Len(pth)
                        For a = 1 To l
                            tmpstr = Mid(pth, a, 1)
                                If tmpstr = "\" Then
                                    D = c
                                    c = a
                                 End If
                        Next a
                        newstr = Mid(pth, D)
                npth = ".." & newstr
                img.ImageFile = npth
        End If
    
        npth = ""
        pth = ""
    Next i
    
    
    End Sub
    
    Sub direct()
    Dim doc As AcadDocument
    Dim docs As AcadDocuments
    ' Get the directory of the current drawing
    MyPath = (ThisDrawing.Path) & "\*.dwg"   ' Set the path.
    MyName = Dir(MyPath, vbNormal)
        Do While MyName <> ""    ' Start the loop.
            ' Ignore the current directory and the encompassing directory.
            If MyName <> "." And MyName <> ".." Then
            ' check if document is already open
                If Not MyName = ThisDrawing.Application.ActiveDocument.Name Then
                    ThisDrawing.Application.Documents.Open (ThisDrawing.Path & "\" & MyName)
                End If
                    'run the xref routine
                    xrefpth
    
                            'close drawing as long as 1 drawing is always open
                            If ThisDrawing.Application.Documents.Count > 1 Then
                            ThisDrawing.Application.ActiveDocument.Close
                End If
        End If
            MyName = Dir    ' Get next entry.
        Loop
    
    End Sub
    Last edited by RobertB; 2008-10-29 at 03:44 PM. Reason: added code tags

  6. #6
    Member
    Join Date
    2000-10
    Location
    New England
    Posts
    7
    Login to Give a bone
    0

    Thumbs up Re: XREF: Absolute > Relative Path

    Thanks jason, this works but assumes:
    ..\path
    From the folder of the host drawing, move up one folder level and follow the specified path


    This is not always the case in my situation. My challenge is being able to count folders (up) from host before following path to xref. Here is an example:

    Host Location
    D:\CAD\F076\CP012-06\VEND\PROCESS\SPEC\HOST.dwg

    Xref Location
    D:\CAD\F076\CP012-06\VEND\REF\REF2\REF3\REF4\XREF1.dwg
    Relative Path
    ..\..\..\VEND\REF\REF2\REF3\REF4\XREF1.dwg

  7. #7
    Member
    Join Date
    2008-02
    Location
    New York
    Posts
    29
    Login to Give a bone
    0

    Default Re: XREF: Absolute > Relative Path

    If its consistent or there are two variations I can write it in to the code. If it’s all over the place it would be difficult to nail down. I suppose I could have the code look at the folder structure to create the Relative path string instead of replacing it. I’ll take a look at that possibility and get back to you.

  8. #8
    Member
    Join Date
    2008-02
    Location
    New York
    Posts
    29
    Login to Give a bone
    0

    Default Re: XREF: Absolute > Relative Path

    This is probably the easy way out but......
    If you replace the xrefpth sub with this it will prompt you for the coding that you want to replace. This should give you some flexibility.

    PHP Code:
    Sub xrefpth()
    Dim a As Integer
    Dim l 
    As Integer
    Dim c 
    As Integer
    Dim D 
    As Integer
    Dim i 
    As Integer
    Dim pth 
    As String
    Dim npath 
    As String
    Dim newstr 
    As String
    Dim tmpstr 
    As String
    Dim xref 
    As AcadExternalReference
    Dim ent 
    As AcadEntity
    Dim img 
    As AcadRasterImage
    Dim blkref 
    As AcadBlockReference
    Dim relcode 
    As String
    On Error Resume Next
    'Loop through the drawing and fid
    relcode = ThisDrawing.Utility.GetString(False, "Enter relative path string:  ")
    For i = 0 To ThisDrawing.ModelSpace.Count
        If ThisDrawing.ModelSpace.Item(i).ObjectName = "AcDbBlockReference" Then
            Set xref = ThisDrawing.ModelSpace.Item(i)
     
                    pth = xref.Path
                    l = Len(pth)
                        For a = 1 To l
                            tmpstr = Mid(pth, a, 1)
                                If tmpstr = "\" Then
                                    D = c
                                    c = a
     
                                 End If
                        Next a
                            newstr = Mid(pth, D)
                            npth = relcode & newstr
                            xref.Path = npth
                '
    End If
        ElseIf 
    ThisDrawing.ModelSpace.Item(i) = "AcDbRasterImage" Then
            Set img 
    ThisDrawing.ModelSpace.Item(i)
                
    pth img.ImageFile
                 l 
    Len(pth)
                        For 
    1 To l
                            tmpstr 
    Mid(ptha1)
                                If 
    tmpstr "\" Then
                                    D = c
                                    c = a
                                 End If
                        Next a
                        newstr = Mid(pth, D)
                npth = "
    .." & newstr
                img.ImageFile = npth
        End If
        npth = ""
        pth = ""
    Next i
     
    End Sub 

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

    Default Re: XREF: Absolute > Relative Path

    Quote Originally Posted by stephen View Post
    Host Location
    D:\CAD\F076\CP012-06\VEND\PROCESS\SPEC\HOST.dwg

    Xref Location
    D:\CAD\F076\CP012-06\VEND\REF\REF2\REF3\REF4\XREF1.dwg
    Relative Path
    ..\..\..\VEND\REF\REF2\REF3\REF4\XREF1.dwg
    Actually, the relative path starts from where HOST.dwg is stored, backing up to a common folder and then down to the xref. i.e.
    ..\..\..\REF\REF2\REF3\REF4\XREF1.dwg

    Using vba string functions, and searching for backslashes, compare folder strings. If they don't match, move up a folder (search for the next "\" to the left) and compare again until they match. Each time they don't match, replace the folder string with ".." When they do match, just discard everything to the left that still remains. e.g. the first folder string in the host path is "spec". Using InStr to search the xref path, counting how many iterations you do this. When InStr finds "VEND" note its position, calculate the position where it ends and trim the left. Prepend "..\" times the folder count.
    C:> ED WORKING....


    LinkedIn

Similar Threads

  1. 2014: Relative vs Absolute path and Managing Links
    By 58D Pilot in forum Revit Architecture - General
    Replies: 0
    Last Post: 2013-10-22, 08:48 PM
  2. 2009: Xref relative path
    By LanceMcHatton in forum AutoCAD General
    Replies: 7
    Last Post: 2011-07-26, 03:58 PM
  3. Change Xref from Full Path to Relative Path
    By ccowgill in forum AutoLISP
    Replies: 6
    Last Post: 2009-05-27, 11:54 AM
  4. Relative Xref Path default
    By jmagarolas962356 in forum AutoCAD General
    Replies: 1
    Last Post: 2008-10-01, 12:19 PM
  5. Relative path for xref with attributes
    By rlh in forum AutoCAD General
    Replies: 3
    Last Post: 2007-07-31, 09:42 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
  •