Strip ".dwg" off drawing names in list

Strip ".dwg" off drawing names in list

DC-MWA
Collaborator Collaborator
2,119 Views
11 Replies
Message 1 of 12

Strip ".dwg" off drawing names in list

DC-MWA
Collaborator
Collaborator

Hello all,

Working on getting a basic sheet index written to external txt file based on the current drawing folder contents.

Works well.

Trying to strip the ".dwg" portion out of the drawing names.

Sample :
"A2.00 - FLOOR PLAN.dwg"   should be  "A2.00-FLOOR PLAN"

Thank you in advance for any input received...

-dc

0 Likes
Accepted solutions (1)
2,120 Views
11 Replies
Replies (11)
Message 2 of 12

ara_neresesian
Collaborator
Collaborator

HI

see line 45,46,47

i think this will help you.

 

let me know if something is wrong

i did what i understand

file name .dwg  - .dwg =>file name

 

good luck

 

0 Likes
Message 3 of 12

DC-MWA
Collaborator
Collaborator

Thank you for responding.

That works well for #List2 (AXX sheets)

but not #List (AX sheets).

??

0 Likes
Message 4 of 12

scot-65
Advisor
Advisor
Perhaps vl-filename-base

From AutoLISP Reference Guide:

Returns the name of a file, after stripping out the directory path and extension

(vl-filename-base filename)

Arguments

filename
A string containing a file name. The vl-filename-base function does not check to see if the file exists.

Return Values

A string containing filename in uppercase, with any directory and extension stripped from the name.

Command: (vl-filename-base "acad.exe")
"acad"

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 5 of 12

ara_neresesian
Collaborator
Collaborator

give me a sample 

what you want on #List (AX sheets).??

 

Message 6 of 12

john.uhden
Mentor
Mentor
Accepted solution

I am at my wife's laptop with no AutoCAD, so I hope I have this right...

;; where dwglist is the list of drawing names...
(setq stripped
  (mapcar '(lambda (x)(vl-string-right-trim ".DWG" (strcase x))) dwglist)
)

I hope you don't mind the return list as being all capitalized.

John F. Uhden

0 Likes
Message 7 of 12

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

....

…. (vl-string-right-trim ".DWG" (strcase x))) ….

 

The difficulty there is that if the drawing name part ends with any of those three letters, they will also be stripped from that part of it -- "EGG.DWG" will become not "EGG" but just "E".

 

But you could use a two-stage version of the same, taking the DWG off first, which will stop at the period, and then taking the period off:

…. (vl-string-right-trim "." (vl-string-right-trim "DWG" (strcase x))) ....
Kent Cooper, AIA
0 Likes
Message 8 of 12

john.uhden
Mentor
Mentor
That's what I get for writing without checking.
Anyway, the best way would be to use vl-filename-base..
(mapcar 'vl-filename-base dwglist)

which might also be helpful looking ahead to when Autodesk copies Microsoft
and starts creating .DWGX files.

John F. Uhden

0 Likes
Message 9 of 12

DC-MWA
Collaborator
Collaborator

Thanks John,

I using this methodology

(mapcar '(lambda (x)(vl-string-right-trim ".DWG" (strcase x))) dwglist)

and adding it as follows:

(setq i 0)
(repeat (length #List)
(write-line (nth i (mapcar '(lambda (x)(vl-string-right-trim ".DWG" (strcase x))) #List)) file2)
(setq i (1+ i))
)
(setq i2 0)
(repeat (length #List2)
(write-line (nth i2 (mapcar '(lambda (x)(vl-string-right-trim ".DWG" (strcase x))) #List2)) file2)
(setq i2 (1+ i2))
)

 

Thank you so much for your assistance.

-DC

0 Likes
Message 10 of 12

DC-MWA
Collaborator
Collaborator

Thank you Ara for your response and time. I could not get this to work for me but that was most likely my lack of knowledge.

I truly appreciate you taking the time to try and assist me with this.

-DC

0 Likes
Message 11 of 12

DC-MWA
Collaborator
Collaborator

Thank you very much Scot for your time and input.

0 Likes
Message 12 of 12

john.uhden
Mentor
Mentor
Do NOT use that.
@Kent1Cooper pointed out that the results can be unwanted.
See my response to him about using vl-filename-base.

John F. Uhden

0 Likes