martinle Posted May 15, 2019 Posted May 15, 2019 Hello have the contribution from there but I think he is better off here. https://www.cadtutor.net/forum/topic/65849-action-planner-for-productivity/ Can someone help me please? Hello, Please help I want to open the file in WordPad. This works fine if there is no "." In the DWG name. or "space" is included. But I can not change the name. How can the Lisp accept the point to make it work? Thank you Martin Example file name: This name does not work "179062-0000018159-Fa. Martin.dwg" This name works "179062-0000018159-FaMartin.dwg" (defun c:todo ( / dwgname dwgpre todofname ) (setq dwgname (GETVAR "dwgname")) (setq dwgname (substr dwgname 1 (- (strlen dwgname) 4))) (setq dwgpre (getvar "dwgprefix")) (setq todofname (strcat dwgpre dwgname ".Txt" )) (startapp "write" todofname) ) (defun chktodo ( / dwgname todoname found) (setq dwgname (GETVAR "dwgname")) (setq dwgname (substr dwgname 1 (- (strlen dwgname) 4))) (setq todoname (strcat (getvar "dwgprefix") dwgname ".txt" )) (setq found (findfile todoname)) (if (/= found nil) (startapp "write" todoname) (princ "Todo") ) ) Quote
dlanorh Posted May 15, 2019 Posted May 15, 2019 (edited) Try this : (vl-load-com) (defun c:todo ( / todoname fp) (setq todoname (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".txt")) (cond ( (/= (findfile todoname) nil) (startapp "write" todoname) ) ( (setq fp (open todoname "w")) (close fp) (startapp "write" todoname) ) ) ) It searches for the text file. If it finds it it opens it. If it doesn't find it, it creates it, then opens it. Edited May 15, 2019 by dlanorh Quote
martinle Posted May 15, 2019 Author Posted May 15, 2019 Hello, This does not work. The message follows: "179062-0000018159-Fa" this file could not be found. Check if the correct path and file name has been specified. it lacks the rest of the filename which is still dot and white space and the rest This: . Martin the entire file name is: "179062-0000018159-Fa. Martin.dwg" Thanks for your help Martin Quote
martinle Posted May 15, 2019 Author Posted May 15, 2019 With notepad, there seems to be no problem. Everything works. But it does not work in WordPad. Quote
dlanorh Posted May 15, 2019 Posted May 15, 2019 (edited) Try this (defun c:todo ( / dname todoname ) (setq todoname (strcat (getvar 'dwgprefix) (substr (setq dname (getvar 'dwgname)) 1 (- (strlen dname) 4)) ".txt")) (cond ( (/= (findfile todoname) nil) (startapp "write" (strcat "\"" todoname "\"")) ) ( (setq fp (open todoname "w")) (close fp) (startapp "write" (strcat "\"" todoname "\"")) ) ) ) Bookmark this page for startapp reference purposes. HERE Edited May 15, 2019 by dlanorh 1 Quote
martinle Posted May 15, 2019 Author Posted May 15, 2019 Hello, this works only if a file "txt" already exists then it will be opened. But if there is no "txt" comes an error message "nil" Thank you for your help Greetings Martin Quote
dlanorh Posted May 15, 2019 Posted May 15, 2019 It works on my system when the text file exists or not, unless of course the ". Martin" is literal and you have underlined text in the drawing name. Quote
martinle Posted May 15, 2019 Author Posted May 15, 2019 Oh sorry yes it really works. I did something wrong. Thank you very much for your great help Thank you Greetings Martin Quote
Lee Mac Posted May 15, 2019 Posted May 15, 2019 FWIW, vl-filename-base should still perform as expected even if the filename in question contains periods, observe: _$ (vl-filename-base "179062-0000018159-Fa. Martin.dwg") "179062-0000018159-Fa. Martin" Hence the code could be written: (defun c:todo ( / d f ) (if (or (findfile (setq f (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".txt"))) (and (setq d (open f "w")) (not (close d))) ) (startapp "write" (strcat "\"" f "\"")) ) (princ) ) 1 1 Quote
dlanorh Posted May 15, 2019 Posted May 15, 2019 3 hours ago, martinle said: Oh sorry yes it really works. I did something wrong. Thank you very much for your great help Thank you Greetings Martin Perhaps you didn't make a mistake. I noticed an error once I posted the lisp and edited. You may have copied the unedited lisp while I was editing it. 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.