XRef Path Conversion

Relative Path to Full Path

Function Syntax (LM:XRef:Relative->Full <dir> <path>)
Current Version 1.0
Arguments
Symbol Type Description
dir String Directory of the Drawing in which the XRef resides
path String Relative Xref Path
Returns
Type Description
String Full XRef Path
Select all
;;-------------=={ Relative Path to Full Path }==-------------;;
;;                                                            ;;
;;  Converts a Relative XRef path to a Full Path.             ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  dir  - Directory of the Drawing in which the Xref resides ;;
;;  path - Relative Xref Path                                 ;;
;;------------------------------------------------------------;;
;;  Returns:  Full XRef Path                                  ;;
;;------------------------------------------------------------;;

(defun LM:XRef:Relative->Full ( dir path )
    (setq dir (vl-string-right-trim "\\" dir))
    (cond
        (   (eq ".." (substr path 1 2))
            (LM:XRef:Relative->Full
                (substr dir 1 (vl-string-position 92 dir nil t))
                (substr path 4)
            )
        )
        (   (eq "." (substr path 1 1))
            (strcat dir (substr path 2))
        )
        (   (strcat dir "\\" path))
    )
)

Example Function Calls

_$ (LM:XRef:Relative->Full "C:\\Folder1\\Folder2\\Folder3" ".\\XRef.dwg")
"C:\\Folder1\\Folder2\\Folder3\\XRef.dwg"

_$ (LM:XRef:Relative->Full "C:\\Folder1\\Folder2\\Folder3" "..\\XRef.dwg")
"C:\\Folder1\\Folder2\\XRef.dwg"

_$ (LM:XRef:Relative->Full "C:\\Folder1\\Folder2\\Folder3" "..\\..\\Folder4\\XRef.dwg")
"C:\\Folder1\\Folder4\\XRef.dwg"

Full Path to Relative Path

Function Syntax (LM:XRef:Full->Relative <dir> <path>)
Current Version 1.0
Arguments
Symbol Type Description
dir String Directory of the Drawing in which the XRef resides
path String Full Xref Path
Returns
Type Description
String Relative XRef Path
Select all
;;-------------=={ Full Path to Relative Path }==-------------;;
;;                                                            ;;
;;  Converts a Full XRef path to a Relative Path.             ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  dir  - Directory of the Drawing in which the Xref resides ;;
;;  path - Full Xref Path                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  Relative XRef Path                              ;;
;;------------------------------------------------------------;;

(defun LM:XRef:Full->Relative ( dir path / p q )
    (setq dir (vl-string-right-trim "\\" dir))
    (cond
        (   (and
                (setq p (vl-string-position 58  dir))
                (setq q (vl-string-position 58 path))
                (not (eq (strcase (substr dir 1 p)) (strcase (substr path 1 q))))
            )
            path
        )
        (   (and
                (setq p (vl-string-position 92  dir))
                (setq q (vl-string-position 92 path))
                (eq (strcase (substr dir 1 p)) (strcase (substr path 1 q)))
            )
            (LM:Xref:Full->Relative (substr dir (+ 2 p)) (substr path (+ 2 q)))
        )
        (   (and
                (setq q (vl-string-position 92 path))
                (eq (strcase dir) (strcase (substr path 1 q)))
            )
            (strcat ".\\" (substr path (+ 2 q)))
        )
        (   (eq "" dir)
            path
        )
        (   (setq p (vl-string-position 92 dir))
            (LM:Xref:Full->Relative (substr dir (+ 2 p)) (strcat "..\\" path))
        )
        (   (LM:Xref:Full->Relative "" (strcat "..\\" path)))
    )
)

Example Function Calls

_$ (LM:XRef:Full->Relative "C:\\Folder1\\Folder2\\Folder3" "C:\\Folder1\\Folder2\\Folder3\\XRef.dwg")
".\\XRef.dwg"

_$ (LM:XRef:Full->Relative "C:\\Folder1\\Folder2\\Folder3" "C:\\Folder1\\Folder2\\XRef.dwg")
"..\\XRef.dwg"

_$ (LM:XRef:Full->Relative "C:\\Folder1\\Folder2\\Folder3" "C:\\Folder1\\Folder4\\XRef.dwg")
"..\\..\\Folder4\\XRef.dwg"

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010