Steven P Posted December 6, 2017 Share Posted December 6, 2017 good afternoon, I think the answer is probably no for this, but is it possible to open a text file and scroll down to a certain line of text? For example, I have a text file with project numbers and some details for each (lets call them projects 100, 101, 102, 103 and so on). So the goal would be to have a routine that can open the text file and scroll down to show the details for, say project 150 (or another as chosen by the user). i think you can get a LISP to read the line you want but I want to read it in the actual text file. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted December 6, 2017 Share Posted December 6, 2017 If your text application is Notepad: Look into using the Sendkeys method of the WScript.Shell object. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 7, 2017 Share Posted December 7, 2017 Whats the problem just read each line and when "project" = 100 stop. (close fname) eg 100,BIGAL,September eg2 100 BIGAL September ; thanks to Lee-mac for this defun ; convert csv to a list ; comma is character 44 ; space is 32 (defun _csv->lst ( str / pos ) (if (setq pos (vl-string-position 44 str)) (cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2)))) (list str) ) ) Quote Link to comment Share on other sites More sharing options...
Steven P Posted December 8, 2017 Author Share Posted December 8, 2017 Thanks. Roy - that looks promising, I haven't had chance to look into this since I asked but that could be what I want. Similarly BigAl, thanks - Useful I think, again I haven't had time yet to look at this, I'll probably have more questions on this when I get 10 minutes free... Quote Link to comment Share on other sites More sharing options...
Steven P Posted December 15, 2017 Author Share Posted December 15, 2017 Thanks for the replies.. now as the office empties for Christmas lunch I have had a chance to look at this again. I got so far with Sendkeys and it looks promising, but the one thing I am struggling with is that when the file opens AutoCAD stops the command until I go back into it and then resumes... so ctrl+F (for 'find;) then toggles AutoCAD OSNAP. Right so how do I keep AutoCAD executing the LISP when a text file opens up? So far my quick code is (and with thanks to another Lee Mac peie of genius) (startapp "notepad" "c:\\Users\\SP\\Desktop\\LISPTEST.LSP") (setq sendkeyscommand "^Ffindtext{enter}") ;; ^F = Find ;;Findtext = text to find ;;{enter} = enter (LM:SendKeys sendkeyscommand) ;;^ = ctrl ) ;;Lee Mac Code (defun LM:sendkeys ( keys / wsh ) ;;note can also be used to run a LISP.... (setq wsh (vlax-create-object "wscript.shell")) (vl-catch-all-apply 'vlax-invoke (list wsh 'sendkeys keys)) (vlax-release-object wsh) (princ) ) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted December 15, 2017 Share Posted December 15, 2017 What are you doing once you find this line? Quote Link to comment Share on other sites More sharing options...
Steven P Posted December 16, 2017 Author Share Posted December 16, 2017 Hi RonJon, I was just wanting to view the line / text in the file. Indtead of just opening the text file and manually scrolling down to the part I want I was wondering if a routine can do both Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 16, 2017 Share Posted December 16, 2017 If you go back to my post and just simply read a text file look for some variable = value and stop then just use ALERT. Copy this to command line (Alert "this is a test") ; crude version ; (setq lineread etc.... from file (if (= val variable) (alert (strcat "Found the line \n" lineread)) ) Quote Link to comment Share on other sites More sharing options...
Steven P Posted December 16, 2017 Author Share Posted December 16, 2017 Hi BigAl, Many thanks for your suggestion though its not quite what I am looking for. Very useful if I want to read something from a text file and use it within a LISP routine later - and I'll make a note of it because I think it will be usefull another time. I was wondering if it was possible to open the text file, perform a 'find' within the text file and rather than grab the text to use in AutoCAD but to view the text in the file via notepad (or similar). Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted December 17, 2017 Share Posted December 17, 2017 The code below works for Notepad++ and Notepad (remove "++" twice). Note 1: In some languages the title bar name of Notepad is not "Notepad". Note 2: You have to dial in the delay. ; (NotepadFind "C:\\Downloads\\test 123.txt" "findtext" 300) (defun NotepadFind (fnm str delay / obj) (vl-catch-all-apply (function (lambda () (setq obj (vlax-get-or-create-object "WScript.Shell")) (vlax-invoke obj 'Run (strcat "Notepad++.exe \"" fnm "\"")) (setvar 'cmdecho 0) (command "_.delay" delay) ; Milliseconds. For BricsCAD users: (sleep delay) does not work. (setvar 'cmdecho 1) (vlax-invoke obj 'AppActivate "Notepad++") ; Title bar name of application. (vlax-invoke obj 'SendKeys (strcat "^f" str "{ENTER}{ESC}")) ) ) ) (if obj (vlax-release-object obj)) ) Quote Link to comment Share on other sites More sharing options...
Steven P Posted December 18, 2017 Author Share Posted December 18, 2017 Thanks!! That loos like it works exactly as I want it to, many thanks - and I was just expecting a 'no it can't be done'. Right, now to break it and work out and learn from what you did (though maybe do that between Christmas and new year when its very quiet). Quote Link to comment Share on other sites More sharing options...
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.