Jump to content

Recommended Posts

Posted
Just felt like playing (not case sensitive)...

(defun c:Test (/ #Search #SS #List)
 (cond
   ((and (not (eq "" (setq #Search (getstring T "\nSearch string: "))))
         (setq #SS (ssget "_X" '((0 . "TEXT,MTEXT") (410 . "MODEL"))))
    ) ;_ and
    (vlax-for x (setq #SS (vla-get-activeselectionset
                            (vla-get-activedocument (vlax-get-acad-object))
                          ) ;_ vla-get-activeselectionset
                ) ;_ setq
      (if (wcmatch (strcase (vla-get-textstring x)) (strcase #Search))
        (setq
          #List (cons
                  (strcat (vla-get-objectname x)
                          " - "
                          (vl-princ-to-string
                            (vlax-safearray->list
                              (vlax-variant-value (vla-get-insertionpoint x))
                            ) ;_ vlax-safearray->list
                          ) ;_ vl-princ-to-string
                  ) ;_ strcat
                  #List
                ) ;_ cons
        ) ;_ setq
      ) ;_ if
    ) ;_ vlax-for
    (vla-delete #SS)
    (AT:WriteToFile
      "c:\\StringCount.txt"
      (cons (strcat (itoa (length #List)) " TEXT OBJECTS MATCHING: " #Search)
            #List
      ) ;_ cons
      T
    ) ;_ AT:WriteToFile
    (startapp "notepad" "c:\\StringCount.txt")
   )
 ) ;_ cond
 (princ)
) ;_ defun

 

You'll need this subroutine:

;;; Write list to file
;;; #File - file to write list to (must be in form "c:\\File.txt")
;;; #ListToWrite - list to write to file
;;; #Overwrite - If T, will overwrite; nil to append
;;; Alan J. Thompson, 04.28.09
(defun AT:WriteToFile (#File #ListToWrite #Overwrite / #FileOpen)
 (cond ((and (vl-consp #ListToWrite)
             (setq #FileOpen (open #File
                                   (if #Overwrite
                                     "W"
                                     "A"
                                   ) ;_ if
                             ) ;_ open
             ) ;_ setq
        ) ;_ and
        (foreach x #ListToWrite
          (write-line x #FileOpen)
        ) ;_ foreach
        (close #FileOpen)
        T
       )
 ) ;_ cond
) ;_ defun

 

I checked this but it say some error

 

Like this

 

"Command:

TEST

Search string: 4mb15

; error: no function definition: VLAX-GET-ACAD-OBJECT"

I load this as nomal lisp application. if this wrong Please tell me how to do this

Thanks for this:thumbsup:

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • ruksi

    10

  • ReMark

    3

  • alanjt

    3

  • Krztoff

    2

Top Posters In This Topic

Posted Images

Posted

before running the routine, type the following on command line, including parentheses. It should prevent that error.

 

(vl-load-com)

Posted
Still not work

Then you are not copying everything. I have (vl-load-com) in my startup, so I never think about adding it. Just paste both routines in a lsp file with (vl-load-com) and load it. It works.

Posted

Alanjt,

 

Please tell me step by step how todo this after or befor i have to paste. I have poor knowledge in Lisp.I like to study this

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