Jump to content

Can't get text file to open in Lisp.


Ross Dunkley

Recommended Posts

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

Link to comment
Share on other sites

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...)

  • Like 1
Link to comment
Share on other sites

You are inconsistant with your  "\\" and "/" either one or the other "//" is a No No

 

Oops @rlx beat me to it :thumbsup:

Edited by dlanorh
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :thumbsup:

 

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.

 

:beer:

  • Like 1
Link to comment
Share on other sites

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.

 

:beer:

 

Didn't know that, who said you can't teach and old dog new tricks.:beer:

Link to comment
Share on other sites

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.

 

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by BIGAL
Link to comment
Share on other sites

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..!

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...