Retrieve partial file name

Retrieve partial file name

zwhaas2001
Observer Observer
313 Views
3 Replies
Message 1 of 4

Retrieve partial file name

zwhaas2001
Observer
Observer

I have drawing file names that are consistently XXXXXXXX_Rev_Y.dwg or XXXXXXXX_R_YY.dwg, and I want to create a field with the Y or YY value. How would I extract the Y or YY portion of the file name using LISP or Diesal expression?

0 Likes
Accepted solutions (1)
314 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

The AutoLisp approach:

 

(setq str (vl-filename-base (getvar 'dwgname)))
Say that returns "ABCDEFGH_R_YY"

(substr str (+ (vl-string-position (ascii "_") str 1 T) 2))

returns whatever is after the last underscore character -- in this case "YY" -- whether there's one or more than one underscore character [the T argument has it search from the end].

Kent Cooper, AIA
Message 3 of 4

pendean
Community Legend
Community Legend
0 Likes
Message 4 of 4

zwhaas2001
Observer
Observer

Thank you. That worked perfectly! I really appreciate your help

 

0 Likes