LSP: Substitute out 'vl-filename-base' from a LISP command

LSP: Substitute out 'vl-filename-base' from a LISP command

jonnyhyoung
Explorer Explorer
995 Views
4 Replies
Message 1 of 5

LSP: Substitute out 'vl-filename-base' from a LISP command

jonnyhyoung
Explorer
Explorer

Hi,

 

I'm working on a LISP that in part needs to grab the filename (without extension) for a command - I managed to do this using 'vl-filename-base' but since it needs to run in acoreconsole it can't use anything from the VL Library. Is there any way to either remove ".dwg" or remove the last 4 characters from a string in only vanilla LISP?


Here's what I've got so far
 

(defun C:PlotToLocation (/ filename)

      (vl-load-com)

    (setvar "cmdecho" 0)


      (setq filename (vl-filename-base (getvar 'dwgname)))
      (setq filename (strcat "A:\\X\\Y\\" (vl-filename-base (getvar 'dwgname))".pdf"))

 

This sets the filename to "A:\X\Y\filename.pdf"

 

I can currently get "A:\X\Y\filename.dwg.pdf" but since the PDFs have to follow a naming standard, I need a way to remove the ".dwg".

0 Likes
Accepted solutions (1)
996 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@jonnyhyoung wrote:

....

I can currently get "A:\X\Y\filename.dwg.pdf" but since the PDFs have to follow a naming standard, I need a way to remove the ".dwg".


That function returns it without the ".dwg" for me:

Kent1Cooper_0-1627653241434.png

But if somehow you're getting it with the ".dwg" included, you can strip that off this way [among others]:

 

(substr "YourFile.dwg" 1 (- (strlen "YourFile.dwg") 4))
"YourFile"

 

["YourFile.dwg" can be substituted with a variable name containing it.]

 

Another way:

 

(vl-string-subst "" ".dwg" "YourFile.dwg")
"YourFile"

Kent Cooper, AIA
0 Likes
Message 3 of 5

ronjonp
Advisor
Advisor

Another way: 

(cadr (fnsplitl "A:\\X\\Y\\filename.dwg"))
0 Likes
Message 4 of 5

ronjonp
Advisor
Advisor

@jonnyhyoung You have answers HERE too where you cross posted.

0 Likes
Message 5 of 5

jonnyhyoung
Explorer
Explorer

Yeah I posted in both forums as I generally lurk on both haha. Ended up going with 

(substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4))

 

 

 Thanks everyone

0 Likes