Hello all,
The following gives me the first folder string, with no back-slashes, that the drawing exists in.
(setq FirstFolder
((lambda (/ tmpDir tmpPos)
(substr
(setq tmpDir (getvar "dwgprefix"))
(+ 2 (setq tmpPos (vl-string-search "\\" tmpDir)))
(- (vl-string-search "\\" tmpDir (1+ tmpPos)) (1+ tmpPos))))))
Is there a way to find the name of the second folder?
Is there a way to find the name of the third folder?
The string length of the characters for each of the first, second, third (and so on) folders are different, which means I can't count character using the "substr" function.
Thanks
KP
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
@kpennell wrote:Hello all,
The following gives me the first folder string, with no back-slashes, that the drawing exists in.
....
Is there a way to find the name of the second folder?
Is there a way to find the name of the third folder?
....
One way is to use one of the many examples of string-splitting-up routines on this forum. Just one example is the sdtol function [it stands for String Delimited to List] here. If you apply it as in the first usage example there, you'll get a list from which you can easily extract any of the folder names using (cadr)/(caddr)/etc., or using (nth).
Hmm, I don't see that function in the help literature through AutoCAD.
I'll certainly be looking what I can see on this discussion group.
Thanks again KC
(defun AT:Str2Lst (s d / i l d) ;; Convert string to list, based on separator ;; s - String to convert ;; d - Delimeter to break string into items ;; Ex. - (AT:Str2Lst "1,2,3" ",") -> '("1" "2" "3") ;; Alan J. Thompson, 11.11.09 / 04.01.10 (while (setq i (vl-string-search (strcase d) (strcase s))) (setq l (cons (substr s 1 i) l) s (substr s (+ i 1 (strlen d))) ) ) (vl-remove "" (reverse (cons s l))) )
eg.
(AT:Str2Lst (getvar 'DWGPREFIX) "\\")
@kpennell wrote:Hmm, I don't see that function in the help literature through AutoCAD.
....
No, you won't find it there -- I wrote it. It's similar in many ways to others on the forum, but if I recall, many of the others work with single characters such as commas or spaces as delimiters [which is also viable in your situation, since as someone else pointed out, "\\" is really a single character in AutoLISP], but in (sdtol) I was going for the possibility of multiple-character delimiters, as you can see from the description there that uses "Mickey Mouse" as a delimiter.
@alanjt_ wrote:(defun AT:Str2Lst (s d / i l d) ;; Convert string to list, based on separator ;; s - String to convert ;; d - Delimeter to break string into items ;; Ex. - (AT:Str2Lst "1,2,3" ",") -> '("1" "2" "3") ;; Alan J. Thompson, 11.11.09 / 04.01.10 (while (setq i (vl-string-search (strcase d) (strcase s))) (setq l (cons (substr s 1 i) l) s (substr s (+ i 1 (strlen d))) ) ) (vl-remove "" (reverse (cons s l))) )
eg.
(AT:Str2Lst (getvar 'DWGPREFIX) "\\")
Interesting approach... Here's one I just posted a bit ago... And another for FilePaths.
"How we think determines what we do, and what we do determines what we get."
KC,
Once again, I've accepted your response as the solution to my post. Huge Thanks. I can see this being very powerful for other applications.
KP
@kpennell wrote:KC,
Once again, I've accepted your response as the solution to my post. Huge Thanks. I can see this being very powerful for other applications.
KP
Thank you -- it's good to know that routines written for a specific request are finding application to different [however slightly in this case] purposes.