Xref repath like find command

Xref repath like find command

darkfprh
Advocate Advocate
571 Views
1 Reply
Message 1 of 2

Xref repath like find command

darkfprh
Advocate
Advocate

Hi I found a lisp that I want.

 

But It changes only 1 word.

 

Help me please...

 

ex.

O : C:\before\before\before.dwg -> C:\after/after/after.dwg

X : C:\before\before\before.dwg -> C:\after/before/before.dwg

 

----------------------- LISP CODE -------------------

 

;;Written by Clinton Cogswell
;;November 19, 2013

(defun c:path ( / sFullPath )
(vl-load-com)

;;Requests text in path to be replaced
(setq oldPath (getstring t "\nEnter Existing Path to be replaced: "))

;;Requests text to replace the old with
(setq newPath (getstring t "\nEnter New path: "))


(vlax-for x

;;grabs all blocks including xref's
(vla-get-Blocks
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)

;;goes thru blocks and changes the path for xrefs
(if
(eq :vlax-true (vla-get-isXref x))
(progn
(setq sFullPath (vla-get-path x))

;;Checks if the path contains the oldPath text and if the
;;path contains the text it then replaces it with the new text
(if
(vl-string-search oldPath sFullPath 0)
(progn
(setq sNewFullPath (vl-string-subst newPath oldPath sFullPath 0))
(vla-put-path x sNewFullPath)
(vla-reload x)
) ; progn
) ; if
) ; progn
) ; if
) ; for

(princ)
)

0 Likes
572 Views
1 Reply
Reply (1)
Message 2 of 2

john.uhden
Mentor
Mentor

The first thing that strikes me is that vl-string-search is case sensitive...

Command: (vl-string-search "abc" "1234AbC567")
nil

The second is that while AutoCAD accepts either one forward slash or two backslashes as path delimiters, vl-string search does not...

Command: (vl-string-search "H:/ABC/123" "H:\\ABC\\123")

nil

Thre may be other things you've got going that are faulty, but at first you're going to have to account for the differences I revealed...

F'rinstance:

(Setq oldpath "H:/ABC\\123")
(setq sfullpath "H:\\abc\\123")
They look equal from an AutoCAD point of view, but they are not, so...
1st:
(setq oldpath (strcase oldpath))
(setq sfullpath (strcase sfullpath))
2nd:
Use my @strsubst_all function to equalize the slashes
(defun @strsubst_all (new old what / l n)
   (setq l (strlen new) n 0)
   (while (setq n (vl-string-search old what n))
      (setq what (vl-string-subst new old what n)
            n (+ n l)
      )
   )
   what
)
(setq oldpath (@strsubst_all "/" "\\" oldpath))
(setq sfullpath (@strsubst_all "/" "\\" sfullpath))
NOW, you can use:
(vl-string-search oldpath sfullpath)
and get the correct result.

John F. Uhden

0 Likes