Ross Dunkley Posted May 20, 2019 Posted May 20, 2019 Hi, First time poster so please take it easy..! I am having trouble getting my lisp to open a file, write to it then close again. I am using Lee Mac's 'LM:findfile' function. The variable 'dntxtloc' works when testing, returning a path "L:\\DESIGN\\2018\\2018-167 Commercial Road, MASLIN BEACH\\2018-167 Designer's Notes.txt" so I think the 'LM:findfile' function is working fine. It seems to fail after that, writing the 'write-line' to the command line instead and returning the error below... Command: Drawing Name is of an acceptable format20/05/2019 (Rosdun) - ; error: bad argument type: streamp nil Command: I was hoping someone might be able to help me as I'm sure it's something basic that I'm missing. Any help at all would be greatly appreciated. Snippet that seems to be the problem. (cond ( (setq dntxtloc (LM:findfile nnametxt sfpath)) ( (setq ff (open dntxtloc "a")) (write-line (strcat mydate " (" myusername ") - ") ff) (close ff) (startapp "C://Windows/Notepad.exe" dntxtloc) (princ) ) ) ( (setq dndocloc (LM:findfile nnamedoc sfpath )) ( (startapp "C://Program Files (x86)//Microsoft Office//root//Office16//WINWORD.exe" dndocloc ) (princ) ) ) (t ((alert "Designer's Notes not found...")(princ))) ); End Cond I will attach the full copy also. Regards, Ross. Open Designer's Notes V6.lsp Quote
rlx Posted May 20, 2019 Posted May 20, 2019 dunno the working of the rest of the routine but with path's in general its either / or \\ but not // as far as I know (but then I don't know everything...) 1 Quote
dlanorh Posted May 20, 2019 Posted May 20, 2019 (edited) You are inconsistant with your "\\" and "/" either one or the other "//" is a No No Oops @rlx beat me to it Edited May 20, 2019 by dlanorh Quote
Ross Dunkley Posted May 20, 2019 Author Posted May 20, 2019 4 minutes ago, rlx said: dunno the working of the rest of the routine but with path's in general its either / or \\ but not // as far as I know (but then I don't know everything...) Thanks. It's interesting! The path returned from the 'LM:findfile' function is "L:\\DESIGN\\2018\\2018-167 Commercial Road, MASLIN BEACH\\2018-167 Designer's Notes.txt" which seems fine. But the paths I specify to open Notepad and Word have worked on earlier tests with the // and / which is strange..? I'll replace them with \\ and see if that helps, however, I have a feeling the issue is more to do with the way I have constructed my cond statement and have my open function within it and how it may not be reading the variable 'dntxtloc' correctly? I'll post back if your suggestion fixes it. Quote
rlx Posted May 20, 2019 Posted May 20, 2019 3 hours ago, dlanorh said: You are inconsistant with your "\\" and "/" either one or the other "//" is a No No Oops @rlx beat me to it just by a second haha (recently had the same thing with Lee posting @ the same time) but on topic , // can be used but only (and only once) at the beginning of a network path. I use this all the time when inserting titleblocks, symbols and xrefs to avoid mapped drives. 1 Quote
dlanorh Posted May 20, 2019 Posted May 20, 2019 1 hour ago, rlx said: just by a second haha (recently had the same thing with Lee posting @ the same time) but on topic , // can be used but only (and only once) at the beginning of a network path. I use this all the time when inserting titleblocks, symbols and xrefs to avoid mapped drives. Didn't know that, who said you can't teach and old dog new tricks. Quote
Tharwat Posted May 20, 2019 Posted May 20, 2019 5 hours ago, Ross Dunkley said: ...... , however, I have a feeling the issue is more to do with the way I have constructed my cond statement and have my open function within it and how it may not be reading the variable 'dntxtloc' correctly? Yes, that's right and you don't need the two extra open and close brackets right after the statement once it is none-nil as noted in the codes below. (cond ( (setq dntxtloc (LM:findfile nnametxt sfpath)) ( ;; this open bracket is not required (setq ff (open dntxtloc "a")) (write-line (strcat mydate " (" myusername ") - ") ff) (close ff) (startapp "C://Windows/Notepad.exe" dntxtloc) (princ) ) ;; and the closed one of course that releated to the above noted one. ;; the same thing on the other statement. 1 Quote
Roy_043 Posted May 20, 2019 Posted May 20, 2019 The error message 'streamp nil' most likely means the text file cannot be opened for appending. Maybe a previous version of the code opened it but failed to close it? Try restarting AutoCAD and/or rebooting. Quote
BIGAL Posted May 21, 2019 Posted May 21, 2019 (edited) I am trying to remember Lee posted a a vl-file command that takes into account spaces in the string not that long ago this may help when opening a file in say notepad the name stops at the 1st space. Counted 4 spaces. It was a similar question. https://www.cadtutor.net/forum/topic/67649-save-and-open-the-note/ Edited May 21, 2019 by BIGAL Quote
Ross Dunkley Posted May 21, 2019 Author Posted May 21, 2019 6 hours ago, Tharwat said: Yes, that's right and you don't need the two extra open and close brackets right after the statement once it is none-nil as noted in the codes below. (cond ( (setq dntxtloc (LM:findfile nnametxt sfpath)) ( ;; this open bracket is not required (setq ff (open dntxtloc "a")) (write-line (strcat mydate " (" myusername ") - ") ff) (close ff) (startapp "C://Windows/Notepad.exe" dntxtloc) (princ) ) ;; and the closed one of course that releated to the above noted one. ;; the same thing on the other statement. Thankyou so much! The extra brackets were the problem..! Quote
Tharwat Posted May 21, 2019 Posted May 21, 2019 7 hours ago, Ross Dunkley said: Thankyou so much! The extra brackets were the problem..! You're welcome anytime. 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.