Author Topic: Problem with spaces in script file  (Read 8936 times)

0 Members and 1 Guest are viewing this topic.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Problem with spaces in script file
« on: December 03, 2015, 08:07:31 AM »
I have a program for add file prefix "Xref-" and suffix as current date
and open modified XREF file with close and delete previous file (see attached lisp).
Program working properly until you have file name with spaces between words
(example: pump station.dwg) or you have a path with spaces between words
(example: c:\Pump station\example.dwg)
Can somebody fix it?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Problem with spaces in script file
« Reply #1 on: December 03, 2015, 08:36:36 AM »
Try putting quotes around the text like so "c:\Pump station\example.dwg"

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Problem with spaces in script file
« Reply #2 on: December 03, 2015, 08:40:40 AM »
Part and name of file here is a variable (not constant) so I need to do it programmaticaly somehow...

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Problem with spaces in script file
« Reply #3 on: December 03, 2015, 08:52:21 AM »
Use a combination of vl-prin1-to-string & strcat:
Code - Auto/Visual Lisp: [Select]


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Problem with spaces in script file
« Reply #4 on: December 03, 2015, 09:07:04 AM »
..but this string

Code - Auto/Visual Lisp: [Select]
  1. (alert (vl-prin1-to-string (strcat (getvar 'dwgprefix) "XREF-" (vl-filename-base (getvar 'dwgname) "-TPZ-" thedate ))))
  2.  
  3.  

returns an error: too many arguments

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Problem with spaces in script file
« Reply #5 on: December 03, 2015, 09:13:38 AM »
Your closing paren for vl-filename-base is in the wrong place.


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Problem with spaces in script file
« Reply #6 on: December 03, 2015, 09:27:07 AM »
right way is:
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (setq www (vl-prin1-to-string (strcat (getvar 'dwgprefix) "XREF-" (vl-filename-base (getvar 'dwgname)) "-TPZ-" thedate )))
  3.  
  4.  
but now i have an eror in this strings
Code - Auto/Visual Lisp: [Select]
  1. (write-line (strcat "open " www) fil1)
  2. (write-line (strcat "(vl-file-delete www)") fil1)
  3.  

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Problem with spaces in script file
« Reply #7 on: December 03, 2015, 09:40:58 AM »
Sorry Danglar, I don't have time right now to debug your code. You initial question was just about spaces & text strings.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Problem with spaces in script file
« Reply #8 on: December 03, 2015, 09:59:02 AM »
Thank you ronjonp. Your help was very appreciated..

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Problem with spaces in script file
« Reply #9 on: December 03, 2015, 10:20:39 AM »
Thank you ronjonp. Your help was very appreciated..
You're welcome.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Prickle Farmer

  • Newt
  • Posts: 33
  • 35+ years of AutoCAD / BricsCAD
Re: Problem with spaces in script file
« Reply #10 on: December 03, 2015, 07:58:23 PM »
Why make you life complicated with VL?

Code - Auto/Visual Lisp: [Select]
  1. (setq www (strcat (getvar "DWGPREFIX") "XREF-" (substr (getvar "DWGNAME") 1 (- (strlen (getvar "DWGNAME")) 4)) "-TPZ-" (rtos (gevar "CDATE") 2 0)))


EDIT: Added code tags. - John
« Last Edit: December 04, 2015, 02:00:38 PM by John Kaul (Se7en) »
I'd rather have a bottle in front of me than a frontal lobotomy.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Problem with spaces in script file
« Reply #11 on: December 04, 2015, 10:23:53 AM »
Why make you life complicated with VL?

(setq www (strcat (getvar "DWGPREFIX") "XREF-" (substr (getvar "DWGNAME") 1 (- (strlen (getvar "DWGNAME")) 4)) "-TPZ-" (rtos (gevar "CDATE") 2 0)))
What is complicated about VL ? Your solution seems more complicated to me.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Problem with spaces in script file
« Reply #12 on: December 06, 2015, 01:19:18 AM »
Thank you
for your note, but I still have a problem with script ..
I have an error " error: no function definition: GEVAR"
when I invoke this string
Code - Auto/Visual Lisp: [Select]
  1. (write-line  "open " www fil1)
  2.  

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Problem with spaces in script file
« Reply #13 on: December 06, 2015, 01:27:50 AM »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Problem with spaces in script file
« Reply #14 on: December 06, 2015, 01:33:16 AM »
You are right:
correct string is:
Code - Auto/Visual Lisp: [Select]
  1. (setq www (strcat (getvar "DWGPREFIX") "XREF-" (substr (getvar "DWGNAME") 1 (- (strlen (getvar "DWGNAME")) 4)) "-TPZ-" (rtos (getvar "CDATE") 2 0)))
but program now not working properly