Fullto Relative

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

;;-------------=={ 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)))
)
)

You might also like