Changing absolute path of hyperlinks to relative path

Changing absolute path of hyperlinks to relative path

dani_cs
Advocate Advocate
240 Views
1 Reply
Message 1 of 2

Changing absolute path of hyperlinks to relative path

dani_cs
Advocate
Advocate

Hello All,

 

this is my issue. I have a drawing with 637 blocks. Each one has a hyperlink attached to a .JPG image file. Those hyperlink follow an absolute path, so, is there a way to global change the absolute path to a relative path of each hyperlink?

 

I tried "hyperlink base" from "drawing properties" and find and replace in .dxf format with not success.

0 Likes
Accepted solutions (1)
241 Views
1 Reply
Reply (1)
Message 2 of 2

CodeDing
Mentor
Mentor
Accepted solution

@dani_cs ,

 

This should do for ya:

 

;; Hyperlink Update (Absolute --> Relative)
(defun c:HUAR ( / LM:XRef:Full->Relative ss cnt len e eg exData urlData url)
  ;;-------------=={ 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)))
      )
  )
  ;; ------- Main Work -------
  (if (null (setq ss (ssget "_A" '((0 . "INSERT") (-3 ("PE_URL"))))))
    (progn (alert (princ "\nNo objects with Hyperlinks found. Exiting.")) (exit))
  )
  (setq cnt (sslength ss) len cnt)
  (repeat cnt
    (setq e (ssname ss (setq cnt (1- cnt))))
    (setq eg (entget e '("PE_URL")))
    (setq exData (assoc -3 eg))
    (setq urlData (cadr exData))
    (setq url (cdr (assoc 1000 (cdr urlData))))
    (setq url (LM:XRef:Full->Relative (getvar 'DWGPREFIX) url))
    (setq urlData (subst (cons 1000 url) (assoc 1000 (cdr urlData)) urlData))
    (setq exData (subst urlData (cadr exData) exData))
    (setq eg (subst exData (assoc -3 eg) eg))
    (entmod eg)
  );repeat
  (alert
    (princ
      (strcat "\nSuccessfully updated " (itoa len) " hyperlinks.")
    )
  )
  (setq ss nil)
  (princ)
)

 

Best,

~DD

0 Likes