Author Topic: Save (only) the path of a specific Xref  (Read 1161 times)

0 Members and 1 Guest are viewing this topic.

Clujna

  • Mosquito
  • Posts: 12
  • Juanjo, draftsman
Save (only) the path of a specific Xref
« on: February 18, 2022, 03:49:48 PM »
Hi all.

I'm trying to find a simple method to extract only the saved path of an specific Xref. The only thing I've achieved has been this paleozoic code:

Code - Auto/Visual Lisp: [Select]
  1. (setq XPATHNAME (cdr (assoc 1 (tblsearch "BLOCK" "XREF-A0-BOX"))))
  2. (setq XPATH (substr XPATHNAME 1 (- (strlen XPATHNAME)(+ (strlen "XREF-A0-BOX") 4))))

I have tried several combinations with vla-get-path, but it is evident that something I do wrong. Here are a few:
Code - Auto/Visual Lisp: [Select]
  1. (setq XPATH (vla-get-path (vlax-ename->vla-object (cdr (assoc 1 (tblsearch "BLOCK" "XREF-A0-BOX"))))))
or
Code - Auto/Visual Lisp: [Select]
  1. (setq XPATH (vla-get-path (vlax-ename->vla-object (tblobjname "BLOCK" "XREF-A0-BOX"))))

Thanks in advance.
Juan José Bernal, civil works draftsman

mhupp

  • Bull Frog
  • Posts: 250
Re: Save (only) the path of a specific Xref
« Reply #1 on: February 18, 2022, 05:44:39 PM »
Code - Auto/Visual Lisp: [Select]
  1. (setq XPATHNAME (vl-filename-directory (cdr (assoc 1 (tblsearch "BLOCK" "XREF-A0-BOX")))))

Sorry never noticed that before.   :smitten:
« Last Edit: February 18, 2022, 08:00:31 PM by mhupp »

JohnK

  • Administrator
  • Seagull
  • Posts: 10661
Re: Save (only) the path of a specific Xref
« Reply #2 on: February 18, 2022, 07:26:42 PM »
...
https://documentation.help/AutoLISP-Functions/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-68bc.htm

Hey, mhupp. Click on the "vl-filename-directory" function in your code block. ;)  Most times you don't have to link to another website because we worked really hard and developed our own code block with built in help. Cool huh?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ribarm

  • Gator
  • Posts: 3309
  • Marko Ribar, architect
Re: Save (only) the path of a specific Xref
« Reply #3 on: February 19, 2022, 02:51:37 AM »
Well, I've asked the same thing back in 2020 I think...
And I did get very comprehensive answer...
Thank you MP again (though he is not among us anymore, but his spirit lives with us...)

So, I've pulled essence from here :
http://www.theswamp.org/index.php?topic=55658.msg597784#msg597784

Code - Auto/Visual Lisp: [Select]
  1. (defun xrefpath ( name / mpx-split-folders mpx-join-folders mpx-absolute-path xref doc data2 data1 path-parent path path-type found path-absolute name! correct-name )
  2.  
  3.  
  4.   (defun mpx-split-folders ( path )
  5.     ( (lambda ( lst / apart parts )
  6.         (foreach x (reverse lst)
  7.           (if (eq 92 x)
  8.             (setq parts (cons apart parts) apart nil)
  9.             (setq apart (cons x apart))
  10.           )
  11.         )
  12.         (mapcar 'vl-list->string (cons apart parts))
  13.       )
  14.       (vl-string->list (vl-string-trim "\\" (vl-string-translate "/" "\\" path)))
  15.     )
  16.   )
  17.  
  18.   (defun mpx-join-folders ( parts )
  19.     (if parts
  20.       (apply 'strcat
  21.         (cons
  22.           (car parts)
  23.           (mapcar (function (lambda ( p ) (strcat "\\" p))) (cdr parts))
  24.         )
  25.       )
  26.       ""
  27.     )
  28.   )
  29.  
  30.   (defun mpx-absolute-path ( parent-path relative-path / parent relative )
  31.    (cond
  32.       ( (wcmatch relative-path "~*\\*")
  33.         (strcat
  34.           (vl-string-right-trim "/\\" parent-path)
  35.           "\\"
  36.           relative-path
  37.         )
  38.       )
  39.       ( (wcmatch relative-path "`.\\*")
  40.         (strcat
  41.           (vl-string-right-trim "/\\" parent-path)
  42.           (substr relative-path 2)
  43.         )
  44.       )
  45.       ( (wcmatch relative-path "`.`.\\*")
  46.         (setq
  47.             parent   (cdr (reverse (mpx-split-folders (vl-string-right-trim "/\\" parent-path))))
  48.             relative (cdr (mpx-split-folders relative-path))
  49.         )
  50.         (while (eq ".." (car relative))
  51.           (setq parent   (cdr parent)
  52.                 relative (cdr relative)
  53.           )
  54.         )
  55.         (strcat
  56.           (mpx-join-folders (reverse parent))
  57.           "\\"
  58.           (mpx-join-folders relative)
  59.         )
  60.       )
  61.       ("")
  62.     )
  63.   )
  64.  
  65.   (if
  66.     (and
  67.       (= (vla-get-isxref xref) :vlax-true)
  68.       (setq doc (vla-get-document xref))
  69.     )
  70.     (progn
  71.       (vl-catch-all-apply 'eval
  72.       '((setq data2
  73.           (entget
  74.             (cdr
  75.               (assoc 360
  76.                 (setq data1
  77.                   (entget
  78.                     (vlax-vla-object->ename xref)
  79.                   )
  80.                 )
  81.               )
  82.             )
  83.           )
  84.         ))
  85.       )
  86.       (setq path-parent
  87.         (cond
  88.           ((/= 'vla-object (type doc)) "")
  89.           ((vlax-property-available-p doc 'path) (vla-get-path doc))
  90.           ((vlax-property-available-p doc 'name) (vl-filename-directory (vla-get-name doc)))
  91.           ("")
  92.         )
  93.       )
  94.       (setq path (cdr (assoc 1 data2)))
  95.       (setq path-type
  96.         (if (wcmatch path "*`.\\*,~*\\*")
  97.           "RELATIVE"
  98.           "ABSOLUTE"
  99.         )
  100.       )
  101.       (setq found
  102.         (cond
  103.           ((eq "ABSOLUTE" path-type) (if (findfile (setq path-absolute path)) "TRUE" "FALSE"))
  104.           ((findfile (setq path-absolute (mpx-absolute-path path-parent path))) "TRUE")
  105.           ("FALSE")
  106.         )
  107.       )
  108.       (setq
  109.         name!        (strcase name)
  110.         correct-name (if (eq name! (strcase (vl-filename-base path))) "TRUE" "FALSE")
  111.       )
  112.       (prompt "\nName : ") (princ name)
  113.       (prompt "\nCorrectName : ") (princ correct-name)
  114.       (prompt "\nSavedPath : ") (princ path)
  115.       (prompt "\nAbsolutePath : ") (princ path-absolute)
  116.       (prompt "\nPathType : ") (princ path-type)
  117.       path
  118.     )
  119.   )
  120. )
  121.  

You call it with just :

Code: [Select]
(xrefpath "XREF-A0-BOX")

You should get all important info + output (correct path string as a return of evaluation of function (xrefpath name)...

HTH., M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Clujna

  • Mosquito
  • Posts: 12
  • Juanjo, draftsman
Re: Save (only) the path of a specific Xref
« Reply #4 on: February 19, 2022, 05:48:11 AM »
Thanks mhupp and Marko (sorry for the delay...) vl-filename-directory it works perfectly.
My intention was to get a quick way to rename Xrefs keeping the original paths, and integrate them into an Acaddoc to apply the changes to large sets of drawings as a script.
I attach the result.

Greetings
Juan José Bernal, civil works draftsman

ribarm

  • Gator
  • Posts: 3309
  • Marko Ribar, architect
Re: Save (only) the path of a specific Xref
« Reply #5 on: February 19, 2022, 06:19:37 AM »
Thanks mhupp and Marko (sorry for the delay...) vl-filename-directory it works perfectly.
My intention was to get a quick way to rename Xrefs keeping the original paths, and integrate them into an Acaddoc to apply the changes to large sets of drawings as a script.
I attach the result.

Greetings

Are you aware that when you rename xrefs-DWG files (childs), you'll also have to alter all DWG files (parents) that use them to have valid data (new xref names after renaming) stored inside DWG files in order to have them operate properly/ordinary like they supposed to?
If you don't alter them - you'll get buch of - missed - not founded signs instead of actual DWG blocks/xrefs inside their parent drawings...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Clujna

  • Mosquito
  • Posts: 12
  • Juanjo, draftsman
Re: Save (only) the path of a specific Xref
« Reply #6 on: February 19, 2022, 07:23:00 AM »
Yes, I am aware. After applying the script/acaddoc on the most obvious files, I do a general sweep with the Reference Manager to confirm that there are no DWGs left that still have the old Xref.
Juan José Bernal, civil works draftsman

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Save (only) the path of a specific Xref
« Reply #7 on: February 20, 2022, 07:46:15 AM »
FWIW, you can also use the fnsplitl function to obtain either the path, filename, or extension for a supplied filepath, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (car (fnsplitl (cdr (assoc 1 (tblsearch "block" "xref-a0-box")))))

Clujna

  • Mosquito
  • Posts: 12
  • Juanjo, draftsman
Re: Save (only) the path of a specific Xref
« Reply #8 on: February 20, 2022, 01:21:33 PM »
Thank you very much Lee. I confess my absolute ignorance of that function. I'll have to add it to my list of "rare" AutoLISP commands...
Juan José Bernal, civil works draftsman