Jump to content

autocad lisp find and replace search results output


Recommended Posts

Posted

this is the screenshot for seperated excel lines

4.jpg

  • Like 1
Posted

BigAl and Mhupp, that is my preference, to do all the stuff in LISP and then make an output where you want, thinking it is a lot simpler to keep everything within the same program I'd consider splitting the text (like BigAl suggests) and then a table in AutoCAD (Like Mhupp suggests). Keeping it all in CAD is my preference though I can understand sometimes you need to export to a spreadsheet.

 

The OP is happy for now but it is possible and not too tricky to make this more helpful. Need a little more information from the OP for that I think, like a sample drawing and if they only ever search for one pipe size or if they repeat this exercise for many pipe sizes.

 

Not sure how much the OP knows what LISP can do, maybe that is limiting what is asked for?

  • Agree 1
Posted

Like Steven P, no dwg no answers.

 

I know have done for someone hundreds of objects, counted based on same type, then put in table.

Posted
19 hours ago, Steven P said:

Not sure how much the OP knows what LISP can do, maybe that is limiting what is asked for?

 

Yeah find that a lot more.  People will ask for one thing and then 10 posts in (not in this case) can you add feature  then three more posts its like "well if you can do that i only needed xyz to do 123 so can you code for 123".

  • 3 weeks later...
Posted

hello again , in the attached file , there are copper pipes (orange color) , and pvc pipes (red color) , for pvc pipes (red colored) when i use the lisp ST i search for 40 for example it finds and writes all Q40 pipes on the below list (command window) but for the copper pipes (orange colored) they are written as inch dimensions for example i search for 5/8" it cannot find how can i use it for also inch dimensions?

Drawing4.dwg

Posted

 if i search in Autocad's find command when i search mt (means meter) i can see all the copper pipes list in below list as in the attached file but i cannot copy that list and take it into excel if there is a way to copy Autocad's FİND list it also helps me, thanks

dw1.jpg

Posted (edited)

image.png.0129c458002db1abb395142bf6a0cf39.png

 

image.png

Edited by egilim123
Posted (edited)

and a question from me, are there any error messages in the command line which might suggest why it isn't working?

 

 

 

 

EDIT....

My error in the copy to clipboard part. Technical explanation that most entities use dxf code '1' to contain the text.. but not all of them do, and here I think the multileaders use 304.. will see if I can fix it quickly

Edited by Steven P
Posted

Aha, copy and paste, love it.... (probably shorter ways of doing this, just copied from other stuff)

 

Try this (and hope I copied and pasted everything I needed to - if not post back here with any error messages hat the command line gives)

 

(defun SetClipBoardText ( MyText / htmlfile result )
  (vlax-invoke (vlax-get (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow) 'ClipBoardData) 'setData "Text" Mytext)
  (vlax-release-object htmlfile)
  (princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun gettextdxfcodes ( entlist1 / dxfcodes)
;;DXF codes containing texts
  (setq dxfcodes (list 3 4 1 172 304)) ;;general

  (if (= (cdr (assoc 0 entlist1)) "DIMENSION") ;;If Dimension
    (progn
      (if (= (cdr (assoc 1 entlist1)) nil)
        (setq dxfcodes (list 4 42 172 304)) ;;No 3, add 42 for dimension value
        (if (and (= (wcmatch "<>" (cdr (assoc 1 entlist1))) nil)(= (wcmatch "\"\"" (cdr (assoc 1 entlist1))) nil) )
          (setq dxfcodes (list 4 1 172 304)) ;;No 3, no 42 for dimension value
          (setq dxfcodes (list 4 1 42 172 304)) ;;Somehow combine 1 and 42 here, text replace and so on.
        ) ;end if
      ) ;end if
  ));end progn end if Dimensions

  (if (= (cdr (assoc 0 entlist1)) "MULTILEADER") ;;Is MultiLeader
    (progn
      (setq dxfcodes (list 304))
  ));end progn end if Dimensions
  dxfcodes
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun getfroment (ent listorstring entcodes / acount acounter mytext newtext stringtext)
;;get dotted pairs list
  (setq entlist (entget ent))
  (setq enttype (cdr (assoc 0 entlist)))
  (setq acount 0)
  (while (< acount (length entlist))
    (setq acounter 0)
    (while (< acounter (length entcodes))
      (setq entcode (nth acounter entcodes))
      (if (= (car (nth acount entlist)) entcode )
        (progn
          (setq newtext (cdr (nth acount entlist)))
          (if (numberp newtext)(setq newtext (rtos newtext))) ;fix for real numbers
          (setq mytext (append mytext (list (cons (car (nth acount entlist)) newtext) )) )
        );end progn
      );end if
      (setq acounter (+ acounter 1))
    );end while
    (setq acount (+ acount 1))
  );end while
;;get string from dotted pair lists
  (if (= listorstring "astring") ;convert to text
    (progn
      (if (> (length mytext) 0)
        (progn
          (setq acount 0)
          (setq temptext "")
          (while (< acount (length mytext))
            (setq temptext (cdr (nth acount mytext)) )
            (if (= (wcmatch temptext "LEADER_LINE*") nil)()(setq temptext "")) ;;Fix for Multileader 'Leader_Line' Text
            (if (= stringtext nil)
              (setq stringtext temptext)
              (setq stringtext (strcat stringtext temptext ))
            );end if
            (setq acount (+ acount 1))
          );end while
        );end progn
      );end if
      (if (= stringtext nil)(setq stringtext ""))
      (setq mytext stringtext)
    );end progn
  );end if
  mytext
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;




(defun C:ST (/ txt ss typ)
  (if (eq (setq txt (strcase (getstring "\nSearch for Text [Area]: "))) "");hit enter for defult options.
    (setq txt "AREA") ;set defult search options here
  )
  (if (setq ss (ssget "_X" (list '(0 . "MTEXT,TEXT,MULTILEADER,DIMENSION") (cons 410 (getvar 'ctab)))))
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (setq typ (cdr (assoc 0 (entget ent))))
      (cond
        ((member typ '("TEXT" "MTEXT" "MULTILEADER"))
          (setq obj (vlax-ename->vla-object ent)) ;convert to val-object
          (if (vl-string-search txt (strcase (vlax-get obj 'TextString))) 
            (progn) ;if found leave in selection set
            (ssdel ent ss) ;if not found in string remove from selection s
          ) ; end if
        ) ; end cond 1
        ((eq typ "DIMENSION") 
          (setq obj (vlax-ename->vla-object ent)) ;convert to val-object
          (if (vl-string-search txt (strcase (vlax-get obj 'TextOverride)))
            (progn) ;if found leave in selection set
            (ssdel ent ss) ;if not found in string remove from selection s
          ) ;end if
        ) ; end cond 2
      ) ; end conds
    ) ; end for each
  ) ; end if
  (if (> (sslength ss) 1) ;if anything is still in the selection set
    (progn
      (prompt (strcat "\n" (itoa (sslength ss)) " Entitys containing \"" txt "\""))
      (sssetfirst nil ss)
    ) ; end progn
    (prompt (strcat "\n" txt "Not Found in Drawing"))
  ) ; end if

  (setq myent (ssname ss 0))
  (setq entlist1 (entget myent))
  (setq entcodes (gettextdxfcodes entlist1) )
  (setq texta (getfroment myent "astring" entcodes))

  (setq Selectedtexts nil)
  (setq acount 0)
  (while ( < acount (sslength ss))
    (if (= nil Selectedtexts)
      (progn
        (setq myent (ssname ss acount))
        (setq entlist1 (entget myent))
        (setq entcodes (gettextdxfcodes entlist1))
        (setq texta (getfroment myent "astring" entcodes))
        (setq Selectedtexts texta)
      )
      (progn
        (setq myent (ssname ss acount))
        (setq entlist1 (entget myent))
        (setq entcodes (gettextdxfcodes entlist1))
        (setq texta (getfroment myent "astring" entcodes))
        (setq Selectedtexts (strcat Selectedtexts (chr 10) texta))
      )
    )
    (setq acount (+ acount 1))
  ) ; end while

  (SetClipBoardText Selectedtexts)
  (princ Selectedtexts)
  (princ)
)

 

  • Like 1
Posted

hello @Steven P, yes it worked for me, thanks a lot , you are someone like a superman or hero :))))))

  • Like 1
Posted
6 hours ago, egilim123 said:

 someone like a superman or hero :))))))

 

 

... no just copy and paste to fix something.....

  • 1 month later...
Posted

Hi again @Steven P, the lisp works perfectly for me but i need a little bit an add-on. Can we also put something like "\" , i need this to seperate the rows(long seperation) that i copy from Autocad with your lisp. i probably couldnt make myslef clear but i will try it with the attached files.

2.jpg

3.jpg

1.jpg

Posted
On 11/11/2022 at 7:29 AM, egilim123 said:

Hi again @Steven P, the lisp works perfectly for me but i need a little bit an add-on. Can we also put something like "\" , i need this to seperate the rows(long seperation) that i copy from Autocad with your lisp. i probably couldnt make myslef clear but i will try it with the attached files.

 

 

if I remember what I did above correctly (a couple of weekends and a holiday ago), I have this line:

(setq Selectedtexts (strcat Selectedtexts (chr 10) texta))

 

where (chr 10) is the carriage return or new line character.

 

You can replace that with the '\\\\.... \\p" and it should work. Note however that \ is the marker for a special character in a LISP string, to get a \ as a part of the string you might need to put a double \\ in for each single one you want to use.

Posted

in this line    (setq Selectedtexts (strcat Selectedtexts (chr 10) texta))

i tried these;

 

(setq Selectedtexts (strcat Selectedtexts '\\\\.... \\p" texta))

(setq Selectedtexts (strcat Selectedtexts \\\\\\\\p texta))

(setq Selectedtexts (strcat Selectedtexts (\\\\\\\\p) texta))

(setq Selectedtexts (strcat Selectedtexts \\\\\\\\ texta))

(setq Selectedtexts (strcat Selectedtexts (chr10\\\\\\\\) texta))

....................

and some  more

 

but none of them worked 

 

it gives;

9 Entitys containing "CM"; error: bad argument type: fixnump: nil

9 Entitys containing "CM"; error: bad argument type: stringp nil

9 Entitys containing "CM"; error: no function definition: \\\\\\\\\\\\\\\\P

 

and such kind of errors.

Posted

try this one:

 

(setq Selectedtexts (strcat Selectedtexts "\\\\\\p" texta))

 

(your first one had a typo, a single quote mark, not double at the start of the \\\\ - the others needed that in there since you are typing in a string and not a variable )

Posted (edited)

and one more questiion ; when i want to arrange the attached sample3 dwg , (picture no:1)  i for exampla make 1-2-3 a group and 4-5-6 another group (picture no:2) then when i want to take them to word i use your ST lisp and it takes the output as picture no:3 but can we make the output datas as in picture no:4 , the first group (1-2-3) in the same line and he second group (4-5-6) in their lines and \\\\\ between each other

2.jpg

4.jpg

3.jpg

1.jpg

sample3.dwg

Edited by egilim123

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