Author Topic: open an MS word doc with lisp  (Read 4889 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
open an MS word doc with lisp
« on: January 04, 2011, 10:10:50 AM »
im attempting to open an MS word doc with lisp


ndir = "F:/directory name with spaces"

Code: [Select]
(startapp "\"C:/Program Files (x86)/Microsoft Office/Office/winword.exe\"" ndir)
the issue im having is it opens ms word but pops up with an alert telling me the document path is invalid

can anyone offer some thoughts on what im doing wrong?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: open an MS word doc with lisp
« Reply #1 on: January 04, 2011, 10:15:09 AM »
forward slashes nfg?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: open an MS word doc with lisp
« Reply #2 on: January 04, 2011, 10:19:30 AM »
Maybe? (been a while since I've LSP'ed)

Code: [Select]
(startapp (strcat "C:/Program Files (x86)/Microsoft Office/Office/winword.exe " ndir))
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: open an MS word doc with lisp
« Reply #3 on: January 04, 2011, 10:29:39 AM »
try:

ndir = "\"F:\\directory name with spaces\\docname.doc""

(startapp "\"C:\\Program Files (x86)\\Microsoft Office\\Office\\winword.exe\"" ndir)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

andrew_nao

  • Guest
Re: open an MS word doc with lisp
« Reply #4 on: January 04, 2011, 11:09:57 AM »
thanks for the replies

but i still get the same error

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: open an MS word doc with lisp
« Reply #5 on: January 04, 2011, 11:16:09 AM »
Works on my machine:

Code: [Select]
(setq
    doc_path "\"C:\\docs\\docname.doc\""
    app_path "\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\winword.exe\""
)

(startapp app_path doc_path)

Check the validity of the paths you're supplying.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: open an MS word doc with lisp
« Reply #6 on: January 04, 2011, 11:43:09 AM »
ndir = "\"F:\\directory name with spaces\\docname.doc\""

Missed one  :wink:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: open an MS word doc with lisp
« Reply #7 on: January 04, 2011, 11:47:27 AM »
where's my coffee medic?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

andrew_nao

  • Guest
Re: open an MS word doc with lisp
« Reply #8 on: January 04, 2011, 12:07:06 PM »
Works on my machine:

Code: [Select]
(setq
    doc_path "\"C:\\docs\\docname.doc\""
    app_path "\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\winword.exe\""
)

(startapp app_path doc_path)

Check the validity of the paths you're supplying.

they paths are good
im thinking because i have spaces in the path with periods and commas?

try your code again but with a directory that has spaces and a peroid and a comma
like "docs\\some name, inc.\\doc file.doc"

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: open an MS word doc with lisp
« Reply #9 on: January 04, 2011, 12:12:35 PM »
Works on my machine:

Code: [Select]
(setq
    doc_path "\"C:\\docs\\stupid path with spaces\\stupid filename with spaces.doc\""
    app_path "\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\winword.exe\""
)

(startapp app_path doc_path)

Check the validity of the paths you're supplying.

Edit:

im thinking because i have spaces in the path with periods and commas?

punctuation, like commas, in paths / filenames is just asking for trouble IMO
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: open an MS word doc with lisp
« Reply #10 on: January 04, 2011, 12:16:59 PM »
Works on my machine:

Code: [Select]
(setq
    doc_path "\"C:\\docs\\stupid path with spaces, and commas\\stupid filename with spaces, and commas.doc\""
    app_path "\"C:\\Program Files (x86)\\Microsoft Office\\Office14\\winword.exe\""
)

(startapp app_path doc_path)

Check the validity of the paths you're supplying.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7531
Re: open an MS word doc with lisp
« Reply #11 on: January 04, 2011, 12:23:53 PM »
See if it works with this ... if all else fails post the filepath you're using.

Code: [Select]
(defun openfile (file / sh)
  (setq sh (vlax-get-or-create-object "Shell.Application"))
  (vlax-invoke-method sh 'open (findfile file))
  (vlax-release-object sh)
)
(openfile "whateveryourfullfilepathishere")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

andrew_nao

  • Guest
Re: open an MS word doc with lisp
« Reply #12 on: January 04, 2011, 01:07:20 PM »
here is the code im using
the code returns the correct info but i just cant get it to open

Code: [Select]
(SETQ lst (VL-DIRECTORY-FILES "O:/" nil -1))
(defun wcmatch_first ( lst pattern flag / result )
    (setq pattern (if flag (strcase pattern) pattern))
    (vl-some
       '(lambda (str) (if (wcmatch str pattern) (setq result str)))
        (if flag (mapcar 'strcase lst) lst)
    )
    result
(setq dir (strcat "O:/" result))
(SETQ NLST (VL-DIRECTORY-FILES DIR "*.DOC"))
)

(defun wcmatch_second ( nlst npattern nflag / nresult )
    (setq npattern (if nflag (strcase npattern) npattern))
    (vl-some
       '(lambda (nstr) (if (wcmatch nstr npattern) (setq nresult nstr)))
        (if nflag (mapcar 'strcase nlst) nlst)
    )
    nresult
(setq ndir nresult)
)
(SETQ var (strcase (GETSTRING "Enter order number: ")))

(if (wcmatch_first lst (strcat "*" var "*") nil)
         ;(alert "yes") ;if found
(progn
   (if (wcmatch_second nlst (strcat "*" "MASTER" "*") nil)
     (progn
  (setq path (findfile (strcat dir "/" ndir)))
              (startapp "\"C:\\Program Files (x86)\\Microsoft Office\\Office\\winword.exe\"" path)
              ;(alert "yes") ;if found
)
              (alert "no") ; not found    
            )
)
         (alert "no") ; not found
)

andrew_nao

  • Guest
Re: open an MS word doc with lisp
« Reply #13 on: January 04, 2011, 01:09:33 PM »
See if it works with this ... if all else fails post the filepath you're using.

Code: [Select]
(defun openfile (file / sh)
  (setq sh (vlax-get-or-create-object "Shell.Application"))
  (vlax-invoke-method sh 'open (findfile file))
  (vlax-release-object sh)
)
(openfile "whateveryourfullfilepathishere")

Ron
this worked perfectly! with the code i posted
thanks

ronjonp

  • Needs a day job
  • Posts: 7531
Re: open an MS word doc with lisp
« Reply #14 on: January 04, 2011, 01:13:12 PM »
See if it works with this ... if all else fails post the filepath you're using.

Code: [Select]
(defun openfile (file / sh)
  (setq sh (vlax-get-or-create-object "Shell.Application"))
  (vlax-invoke-method sh 'open (findfile file))
  (vlax-release-object sh)
)
(openfile "whateveryourfullfilepathishere")

Ron
this worked perfectly! with the code i posted
thanks
:-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC