Author Topic: Lisp to open a note pad  (Read 13899 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Lisp to open a note pad
« Reply #15 on: November 17, 2011, 02:46:46 PM »
well i found the problem i guess i took out one of the 2 "\" int the C:\\TimeTracker.txt and it worked :D

You will need to use two backslashes or a single forward slash to specify the filepath since a single backslash is used in LISP as an escape character.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Lisp to open a note pad
« Reply #16 on: November 17, 2011, 02:54:48 PM »
That's a new one for me, thanks.  :-)
I use it, pbrush and word all the time.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CadFrank

  • Guest
Re: Lisp to open a note pad
« Reply #17 on: November 17, 2011, 03:20:09 PM »
Well this code works.

Code: [Select]
(defun c:timet ( / file )
        (startapp "notepad" "C:\Timetracker.txt")
   
(princ)
)

And this one doesn't

Code: [Select]
(defun c:timet ( / file )
        (startapp "notepad" "C:\\Timetracker.txt")
   
(princ)
)

But anyways i'm not sure I understand what you mean.

CadFrank

  • Guest
Re: Lisp to open a note pad
« Reply #18 on: November 17, 2011, 03:21:01 PM »

Well this code works.

Code: [Select]
(defun c:timet ( / file )
        (startapp "notepad" "C:\Timetracker.txt")
   
(princ)
)

And this one doesn't

Code: [Select]
(defun c:timet ( / file )
        (startapp "notepad" "C:\\Timetracker.txt")
   
(princ)
)

But anyways i'm not sure I understand what you mean.

Quote
You will need to use two backslashes or a single forward slash to specify the filepath since a single backslash is used in LISP as an escape character.

CadFrank

  • Guest
Re: Lisp to open a note pad
« Reply #19 on: November 17, 2011, 03:23:33 PM »
Oh!!  how the heck those the Quote Work!! I repeated myself now :S

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Lisp to open a note pad
« Reply #20 on: November 17, 2011, 03:35:26 PM »
Code: [Select]
(defun c:timet (/ file)
  (if (or (setq file (findfile "c:\\Timetracker.txt"))
          (setq file (getfiled "Select Text File to Open" "c:\\" "txt" 16))
      )
    (startapp "notepad" file)
    (alert "No file for you!")
  )
  (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

jaydee

  • Guest
Re: Lisp to open a note pad
« Reply #21 on: November 17, 2011, 06:59:54 PM »
I used command "start"
to initial window default app to open a particular file extension.
this also avoid having application version issue.
Code: [Select]
(command "start" "c:\\Timetracker.txt"")

zanze02

  • Mosquito
  • Posts: 7
Re: Lisp to open a note pad
« Reply #22 on: November 18, 2011, 02:10:38 AM »
Code: [Select]
;;;-----------------------------------------------------------------------------
;; function Start default application for opening files
;;;-----------------------------------------------------------------------------
(defun OpenFile (filename / shell)
  (vl-load-com)
  (setq shell (vla-getinterfaceobject (vlax-get-acad-object)"Shell.Application"))
  (vlax-invoke-method shell 'Open filename)
  (vlax-release-object shell)
)

Code: [Select]
(OpenFile (findfile "YourFilename.txt"))

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Lisp to open a note pad
« Reply #23 on: November 18, 2011, 05:51:26 AM »
CadFrank,

What is the filepath of your .txt file?

But anyways i'm not sure I understand what you mean.

Quote
You will need to use two backslashes or a single forward slash to specify the filepath since a single backslash is used in LISP as an escape character.

Escape Character.

The backslash is used as an escape character to give a sequence of characters an alternative meaning, e.g.:

Code: [Select]
"\n" = new line character
"\t" = tab character

...

Hence, if you need to use a literal backslash you need to mark it as a literal by prefixing it with another backslash ("\\").

Test these expressions in your console to understand:

Code: [Select]
(princ "C:\timetracker.txt")
(princ "C:\\timetracker.txt")