Script file: Need to strip the extension off a string from a text file

Script file: Need to strip the extension off a string from a text file

MBestSNZMY
Contributor Contributor
546 Views
6 Replies
Message 1 of 7

Script file: Need to strip the extension off a string from a text file

MBestSNZMY
Contributor
Contributor

I'm creating a script file to get a file name (.tif) from a text file.  Use that file name to insert the image into a dwg then save the dwg to the same name as the tiff file.  No matter what I do I can't get the extension off the string.

 

 

(setq f (open "D:\\Project 1000\\Scanned Files\\Test Files\\TIF_file.txt" "r"))
(setq txtline (read-line f))
(close f)
;*****************************
; insert image works perfectly
-insert "D:\\Project 1000\\Scanned Files\\Test Files\\D12345.tif"
;*****************************
;Tried this, don't work
(setq Fname (substr !txtline 1 (- (strlen !txtline) 4)))
;Tried this, don't work either
(setq DWGname (strcat (!txtline ".tif")))

;End result desired
-save Fname
; or
-save DWGname
; or
-save "D:\\Project 1000\\Scanned Files\\Test Files\\D12345" 

 

Thanks for any help!!

0 Likes
Accepted solutions (2)
547 Views
6 Replies
Replies (6)
Message 2 of 7

_gile
Consultant
Consultant

Hi,

(setq filename "D:\\Project 1000\\Scanned Files\\Test Files\\D12345.tif")
(strcat (vl-filename-directory filename) "\\" (vl-filename-base filename) ".dwg")


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 7

MBestSNZMY
Contributor
Contributor

Gilles,

 

After reading the path and file name of the .tif from the text file,  That file name in stored in the string txtline.  From the command line txtline does not show the file name, but !txtline does.

That is the string I need to convert or use to save the file.  There's a list of over 500 tif files I'm going insert into each drawing of their own with the tif name (D12345) and save them as .dwg's.

 

I'm struggling getting the filename, !txtline to 

"D:\\Project 1000\\Scanned Files\\Test Files\\D12345")

 

Thanks for your quick response!!

0 Likes
Message 4 of 7

_gile
Consultant
Consultant
Accepted solution

This way?

(setq txtline (read-line f))
(setq txtline (strcat (vl-filename-directory txtline) "\\" (vl-filename-base txtline)))

Look at the vl-filename-directory and vl-filename-base functions in the documentation.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 7

MBestSNZMY
Contributor
Contributor

Thanks Gilles!

This worked perfectly!!

0 Likes
Message 6 of 7

Sea-Haven
Mentor
Mentor
Accepted solution

Also (setq fname (substr filename 1 (- (strlen filename) 4)))

0 Likes
Message 7 of 7

MBestSNZMY
Contributor
Contributor

Thanks Sea-Haven, initially this was what I was trying to do.

 

I will add this also to my list of solutions.

0 Likes