Author Topic: Part of code to make XREF path full instead of relative  (Read 2524 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Part of code to make XREF path full instead of relative
« on: December 11, 2014, 06:26:14 AM »
There is 2 point about this part of code
- When finish the path comes as small letters I want It capital, I used strcase but not working I think that the issue in vla-put-path
- Any comments will be appreciated
Code - Auto/Visual Lisp: [Select]
  1. (defun selx (/ blk name xrefs)                              ;LEE-mac.com
  2.    (while (setq blk (tblnext "BLOCK" (not blk)))
  3.       (if (> (logand 4 (cdr (assoc 70 blk))) 0)
  4.          (progn
  5.             (setq name  (cdr (assoc 2 blk))
  6.                   xrefs (if xrefs
  7.                            (strcat xrefs "," name)
  8.                            name
  9.                         )
  10.             )
  11.          )
  12.       )
  13.    )
  14.    (ssget "X" (list '(0 . "INSERT") (cons 2 xrefs)))
  15. )
  16. (setq cntX 0)
  17.  
  18. (if (sslength (setq ssBlk (selx)))
  19.    (progn
  20.       (while
  21.          (setq blk (ssname ssBlk cntX))
  22.            (setq blk (vlax-ename->vla-object blk))
  23.            (setq blkPth (vla-get-path blk))
  24.            (setq blknm (vla-get-name blk))
  25.            (if (= (vl-string-elt blkPth 0) 46)
  26.               (command "_.-xref" "_pathType" blknm "full")
  27.            )
  28.            (setq blkPth (strcase (vla-get-path blk)))
  29.            (vla-put-path blk blkPth)
  30.            (vla-update blk)
  31.            (setq cntX (1+ cntX))
  32.       )
  33.    )
  34. )
  35.  


edit kdub-> formatting to code=cadlisp-7
fix title spelling
« Last Edit: December 11, 2014, 06:59:18 AM by Kerry »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Part of code to make XREF path full instead of relative
« Reply #1 on: December 11, 2014, 06:58:34 AM »

Can you try again to explain your problem.

ie
I expect this : < example>
I get this : < example >

From a quick perusal, the code should work without fault.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Part of code to make XREF path full instead of relative
« Reply #2 on: December 11, 2014, 07:13:05 AM »

Just for my Curiosity ..
Why Do you want the Saved Path to be in uppercase instead of the case returned by (findfile ... )

Regards
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Part of code to make XREF path full instead of relative
« Reply #3 on: December 11, 2014, 07:30:49 AM »
...
edit kdub-> formatting to code=cadlisp-7
fix title spelling
- Thanks kdub I believe that it is better than before
- see my sign  :oops:


Can you try again to explain your problem.

ie
I expect this : < example>
I get this : < example >

From a quick perusal, the code should work without fault.


- The code working without fault, and I asking for comments
- I tried again and working well.  :-o  :embarrassed:

And faced another issue, I want to replace a part of path with another part

Full path
Code: [Select]
\\10.120.200.11\projects\GEN\3120B01\BASE\Col-Grids&SE\3120B01-XCOFO.dwgI want to replace
Code: [Select]
\\10.120.200.11\projects\with
Code: [Select]
X:\

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Part of code to make XREF path full instead of relative
« Reply #4 on: December 11, 2014, 07:46:39 AM »

Just for my Curiosity ..
Why Do you want the Saved Path to be in uppercase instead of the case returned by (findfile ... )

Regards

Some of our projects are prototype, Means the same building repeated in more than one site. And capital and small letters confusing me while change the path using Reference manager. So I want all letters case are capital.
For example

This is BASE path
Code - Text: [Select]
  1. X:\GEN\3120\PROTOTYPE\BASE\3120B01-XCOFO.dwg


This is BASE path
Code - Text: [Select]
  1. X:\GEN\3120\PROTOTYPE\1111\3120B01-C-S101.dwg
  2. X:\GEN\3120\PROTOTYPE\2222\3120B01-C-S101.dwg
  3. X:\GEN\3120\PROTOTYPE\3333\3120B01-C-S101.dwg

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Part of code to make XREF path full instead of relative
« Reply #5 on: December 11, 2014, 08:22:48 AM »
Give this a try:

Code - Auto/Visual Lisp: [Select]
  1. (defun _changexrefpath (/ i newpath p xrpath)
  2.   (setq p "\\\\10.120.200.11\\PROJECTS\\")
  3.   (setq i (strlen p))
  4.     (if (and (minusp (vlax-get x 'isxref))
  5.              (setq xrpath (strcase (vlax-get x 'path)))
  6.              (vl-string-search p xrpath)
  7.              (setq newpath (strcat "X:\\" (substr xrpath i)))
  8.              (findfile newpath)
  9.         )
  10.       (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-path (list x newpath)))
  11.     )
  12.   )
  13.   (princ)
  14. )
*Found Typo
« Last Edit: December 11, 2014, 08:34:19 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Part of code to make XREF path full instead of relative
« Reply #6 on: December 11, 2014, 08:48:59 AM »
Give this a try:

Code - Auto/Visual Lisp: [Select]
  1. (defun _changexrefpath (/ i newpath p xrpath)
  2.   (setq p "\\\\10.120.200.11\\PROJECTS\\")
  3.   (setq i (strlen p))
  4.     (if (and (minusp (vlax-get x 'isxref))
  5.              (setq xrpath (strcase (vlax-get x 'path)))
  6.              (vl-string-search p xrpath)
  7.              (setq newpath (strcat "X:\\" (substr xrpath i)))
  8.              (findfile newpath)
  9.         )
  10.       (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-path (list x newpath)))
  11.     )
  12.   )
  13.   (princ)
  14. )
*Found Typo

Gives error
Code: [Select]
_CHANGEXREFPATH
_$
; error: bad argument type: (or stringp symbolp): nil
_$
By the way I changed G:\\ to X:\\

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Part of code to make XREF path full instead of relative
« Reply #7 on: December 11, 2014, 09:12:25 AM »
Untested :

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun _changexrefpath (/ newpath path1 xrpath old new)
  3.    (setq new "G:\\")
  4.    (setq old "//10.120.200.11\\PROJECTS\\")
  5.    (vlax-for x
  6.              )
  7.       (if (minusp (vlax-get x 'isxref))
  8.          (if (and (setq xrpath (strcase (vlax-get x 'path)))
  9.                   (vl-string-search old xrpath)
  10.                   (setq newpath (vl-string-subst
  11.                                    new
  12.                                    old
  13.                                    xrpath
  14.                                 )
  15.                   )
  16.                   (findfile newpath)
  17.              )
  18.             (vl-catch-all-error-p
  19.                (vl-catch-all-apply 'vla-put-path (list x newpath))
  20.             )
  21.          )
  22.       )
  23.    )
  24.    (princ)
  25. )
  26.  
  27. ;; (_changexrefpath)
  28.  
  29.  


added:
just an option now that ronjonp's typo is fixed :)
« Last Edit: December 11, 2014, 09:16:30 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.