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

0 Members and 1 Guest are viewing this topic.

CadFrank

  • Guest
Lisp to open a note pad
« on: November 17, 2011, 01:28:15 PM »
Hi, I would like to know if a lisp routine exist for the fallowing explanation.

Ok well i have a Notepad saved as TimeTracker.txt in my desktop.

Would it be possible that when i press CTRL+S in AutoCad drawing that the file .txt open.

I would also like to know how i keep a .lsp loaded in a .dwt file.

Thx alot for all the help.

Cheers & Beers

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Lisp to open a note pad
« Reply #1 on: November 17, 2011, 01:34:09 PM »
Code: [Select]
(startapp "notepad" "C:\\YourFilename.txt")

CadFrank

  • Guest
Re: Lisp to open a note pad
« Reply #2 on: November 17, 2011, 01:39:20 PM »
Ok, lets say I do not know how to creat a lisp routine.

where would i put the script you posted?

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Lisp to open a note pad
« Reply #3 on: November 17, 2011, 01:45:30 PM »
At the point in your program at which you want the Text file to open, for example:

Code: [Select]
(defun c:test ( )
    (getstring "\nPress Enter to open Notepad...")
    (startapp "notepad")
    (princ)
)

Or, as a better example:

Code: [Select]
(defun c:test ( / file )
    (if (setq file (getfiled "Select Text File to Open" "" "txt" 16))
        (startapp "notepad" file)
    )
    (princ)
)

CadFrank

  • Guest
Re: Lisp to open a note pad
« Reply #4 on: November 17, 2011, 01:45:59 PM »
Would this work?

Quote
(defun c:timet()

(startapp "notepad" "C:\\TimeTracker.txt")

)

(princ)

CadFrank

  • Guest
Re: Lisp to open a note pad
« Reply #5 on: November 17, 2011, 01:46:56 PM »
So this would make it start when i press Ctrl+s or Save

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Lisp to open a note pad
« Reply #6 on: November 17, 2011, 01:48:34 PM »
So this would make it start when i press Ctrl+s or Save

No, for that you would need to alter your cui.

CadFrank

  • Guest
Re: Lisp to open a note pad
« Reply #7 on: November 17, 2011, 01:50:37 PM »
Would altering my cui. be hard or creat problems?

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Lisp to open a note pad
« Reply #8 on: November 17, 2011, 01:57:50 PM »
Would altering my cui. be hard or creat problems?

Not too difficult...

Type CUI at the command-line, navigate to 'Keyboard Shortcuts' > 'Shortcut Keys' > 'Save'

Alter the macro to call the LISP function before (or after) executing the 'qsave' command, e.g.:

Code: [Select]
^C^C(c:test);_.qsave

CadFrank

  • Guest
Re: Lisp to open a note pad
« Reply #9 on: November 17, 2011, 02:11:02 PM »
Ok it works when i Save.. But if the text file i only want to open is TimeTracker.txt and i want it to open when i press Ctrl+S what should i change in the routine.

Code: [Select]
(defun c:timet ( / file )
    (if (setq file (getfiled "Select Text file To Open" "" "txt" 16))
        (startapp "notepad" file)
    )
    (princ)
)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Lisp to open a note pad
« Reply #10 on: November 17, 2011, 02:12:28 PM »
You can also do this from the commandline by default (defined in acad.pgp). just type NOTEPAD
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Lisp to open a note pad
« Reply #11 on: November 17, 2011, 02:14:42 PM »
Ok it works when i Save.. But if the text file i only want to open is TimeTracker.txt and i want it to open when i press Ctrl+S what should i change in the routine.

Code: [Select]
(defun c:timet ( / file )
    (if (setq file (getfiled "Select Text file To Open" "" "txt" 16))
        (startapp "notepad" file)
    )
    (princ)
)

Hint:

Code: [Select]
(startapp "notepad" "C:\\YourFilename.txt")

You can also do this from the commandline by default (defined in acad.pgp). just type NOTEPAD

That's a new one for me, thanks.  :-)

CadFrank

  • Guest
Re: Lisp to open a note pad
« Reply #12 on: November 17, 2011, 02:21:42 PM »
So it writes impossible to open file

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

Where should i put my .txt file for it to be found?

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Lisp to open a note pad
« Reply #13 on: November 17, 2011, 02:42:07 PM »
Where should i put my .txt file for it to be found?

Anywhere - as long as the filepath in the startapp expression matches the location of the text file.

Code: [Select]
(startapp "notepad" <filepath of textfile>)

CadFrank

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

Well Thx alot for your help Lee

Cheers & Beers !

Lee Mac

  • Seagull
  • Posts: 12913
  • 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: 12913
  • 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")