Jump to content

Recommended Posts

Posted

Good Morning,

 

I have been using this to search for text in a text file, now I have been upgraded to windows 11 it doesn't work, and I can't work out what change to make. Looking for some guidance again, thanks!

 

fnm: File name (including filepath)

str: Text String

delay: a delay, say 1000 mS

 

Will open notepad and should perform a 'find' to jump to the text. It gets as far as 'find' to open the dialogue box but won't populate it or hit 'enter' to do the find, using sendkeys - which has always worked before.

 

thanks for any help

 

;;To find text within a text file.
;;http://www.cadtutor.net/forum/showthread.php?102326-Open-text-file-and-jumping-to-a-line&p=694572#post694572
; example command to call it (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 "\"")) ;; or notepad++ if that is used.
        (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. ++ for notepad++ but still works?
        (vlax-invoke obj 'SendKeys (strcat "^f" str "{ENTER}{ESC}"))
      )
    )
  )
  (if obj (vlax-release-object obj))
)

 

Posted

@Steven P Your function seems to work for me although I am not sure what you expect.   I am using Windows 11 and BricsCAD Pro V25.  When I run my test program which calls your routine: NotePad++ is opened with the test data file, the specified text is highlighted and the text is in the "find" dialog box. ( I had to click the binocular icon as the find dialog did not open on its own.)

Are you expecting the "find" dialog box to open automatically?

testdata.txt testNF.lsp

Posted (edited)

Maybe have a look at the windows command findstr it will search a directory for a key word, I guess could open one at a time.

findstr d2 d:/mylisps/*.lsp

may be useful how I find old posts

Edited by BIGAL
Posted (edited)

Thanks Jerry and BigAl,

 

The main use I have for this one is when I want to edit a LISP file - pop up dialogue to select the routine, open the file in notepad, 'Find' which usually takes me to the LISP name in the file. The find dialogue all happens without me needing to press any buttons.

 

BIgAl - handy but in this case I know the file name and location to go straight to it - handy later in life if I don't know what file I want though, thanks

 

 

MHUPP - going to look into that this morning, saving the answer into my "make windows work right" file

Undoing the alias as in the link was the trick (Start Menu - settings - Apps - Advanced App Settings - Alias), pinned the proper notepad to the task bar (not the new one, located in c:\windows\notepad.exe or c:\windows\system32\notepad32.exe), now to set the proper notepad as the default as it should be.

Edited by Steven P
  • Like 1

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