Author Topic: Edit path type for xrefs via lisp  (Read 3480 times)

0 Members and 1 Guest are viewing this topic.

densan

  • Mosquito
  • Posts: 12
Edit path type for xrefs via lisp
« on: June 20, 2019, 01:33:10 PM »
Hello, I need some help understanding what to edit in the code below.
I have to set the path of attached xrefs to NONE (familiar with reference manager tool, lisp needed for automation purposes).
  • If I want to set the xref path type to none, do I still need Lee's function section?
  • It cannot be as simple as to edit line 16, rigth?
It doesn't have to be this code in particular, but looking through various forums and testing multiple sets of code, this one was the closest to what I need.
Any help would be appreciated, thank you.

Code - Auto/Visual Lisp: [Select]
  1. ;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/xref-relative-path-lisp/td-p/4792859
  2. ;; Changes xref path types from absolute to relative
  3. ;; Functions by:
  4. ;; Henrique Moreira da Silva - 2014
  5. ;; Lee Mac - 2011
  6. ;;
  7. ;;
  8. (defun c:rpath (/)
  9.   (vlax-For blk
  10.     (if (and (= (vla-Get-IsXref blk) :vlax-True)
  11.              (/= (vl-string-search "." (vla-get-path blk)) 0)
  12.         )
  13.       (vla-put-path     blk
  14.         (LM:XRef:Full->Relative
  15.           (vl-string-right-trim "\\" (getvar 'DWGPREFIX)) <- use "dwgname" in this line?
  16.           (vla-get-path blk)
  17.         )
  18.       )
  19.     )
  20.   )
  21.   (vl-cmdf "_.qsave")
  22.   (princ)
  23. )
  24.  
  25.  
  26. ;;-------------=={ Full Path to Relative Path }==-------------;;
  27. ;;                                                            ;;
  28. ;;  Converts a Full XRef path to a Relative Path.             ;;
  29. ;;------------------------------------------------------------;;
  30. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  31. ;;------------------------------------------------------------;;
  32. ;;  Arguments:                                                ;;
  33. ;;  dir  - Directory of the Drawing in which the Xref resides ;;
  34. ;;  path - Full Xref Path                                     ;;
  35. ;;------------------------------------------------------------;;
  36. ;;  Returns:  Relative XRef Path                              ;;
  37. ;;------------------------------------------------------------;;
  38.  
  39. (defun LM:XRef:Full->Relative ( dir path / p q )
  40.     (setq dir (vl-string-right-trim "\\" dir))
  41.     (cond
  42.         (   (and
  43.                 (setq p (vl-string-position 58  dir))
  44.                 (setq q (vl-string-position 58 path))
  45.                 (not (eq (strcase (substr dir 1 p)) (strcase (substr path 1 q))))
  46.             )
  47.             path
  48.         )
  49.         (   (and
  50.                 (setq p (vl-string-position 92  dir))
  51.                 (setq q (vl-string-position 92 path))
  52.                 (eq (strcase (substr dir 1 p)) (strcase (substr path 1 q)))
  53.             )
  54.             (LM:Xref:Full->Relative (substr dir (+ 2 p)) (substr path (+ 2 q)))
  55.         )
  56.         (   (and
  57.                 (setq q (vl-string-position 92 path))
  58.                 (eq (strcase dir) (strcase (substr path 1 q)))
  59.             )
  60.             (strcat ".\\" (substr path (+ 2 q)))
  61.         )
  62.         (   (eq "" dir)
  63.             path
  64.         )
  65.         (   (setq p (vl-string-position 92 dir))
  66.             (LM:Xref:Full->Relative (substr dir (+ 2 p)) (strcat "..\\" path))
  67.         )
  68.         (   (LM:Xref:Full->Relative "" (strcat "..\\" path)))
  69.     )
  70. )

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Edit path type for xrefs via lisp
« Reply #1 on: June 20, 2019, 02:45:31 PM »
This should be sufficient -
Code - Auto/Visual Lisp: [Select]
  1. (defun c:xrnone ( )
  2.         (if (= :vlax-true (vla-get-isxref b))
  3.             (vla-put-path b (apply 'strcat (cdr (fnsplitl (vla-get-path b)))))
  4.         )
  5.     )
  6.     (princ)
  7. )

densan

  • Mosquito
  • Posts: 12
Re: Edit path type for xrefs via lisp
« Reply #2 on: June 20, 2019, 04:13:23 PM »
There are not enough thanks to Lee for all the help.
I now know the answer to my question.

...(apply 'strcat (cdr (fnsplitl (vla-get-path b))))...
;; pass all but first item from fnsplitl (....

Thank you very much

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Edit path type for xrefs via lisp
« Reply #3 on: June 20, 2019, 04:31:11 PM »
Precisely  :-)

You're most welcome.