Pre-defined find & replace SXH text in tables

Pre-defined find & replace SXH text in tables

msmith_ncl
Enthusiast Enthusiast
1,100 Views
11 Replies
Message 1 of 12

Pre-defined find & replace SXH text in tables

msmith_ncl
Enthusiast
Enthusiast

Hope someone can point me in the right direction, I need a simple tool to remove some values from tables.  I have an automated Bill of Materials using attributes in blocks, this generates 2 tables with objects sorted in a specific order, I also have some blocks that are used to create sub headings in these tables for types of equipment grouped together, these headings are sorted using a part code "TXTREP1" - "TXTREP6", all have a quantity of "999".  I just need want these values deleting from any table in the current drawing with 1 command,  I was using lee mac's bfind to edit these but is no longer working in 2021 with SHX text.  Also found some other tools online that worked using a script, these  were all for changing more than just tables and when running they were very slow, was quicker to just manually delete all 12 cells, attached drawing has the table as generated by the Bill of Materials and the required finished product.  Any advice is appreciated.

0 Likes
Accepted solutions (2)
1,101 Views
11 Replies
Replies (11)
Message 2 of 12

Kent1Cooper
Consultant
Consultant

Maybe not the perfect solution [because it leaves "content," though invisible, in those cells], but effective, is FIND.  Make sure Use wildcards and Table text are checked in the Options, and with a single space in the Replace with: slot, use # as the wildcard for the numbers at the end of TXTREP:

Kent1Cooper_1-1615900307304.png

and pick Replace All.  You can do the same with the 999's without caring about wildcards.

 

Kent Cooper, AIA
0 Likes
Message 3 of 12

msmith_ncl
Enthusiast
Enthusiast

Thanks, I knew this, trying to find a way of doing this without any extra input, 1 mouse click, the exact same thing is done multiple times every day, I just want 1 command to remove all.  Thanks

0 Likes
Message 4 of 12

Sea-Haven
Mentor
Mentor

Try this the only issue is the test TXT123 is different to txt123 and so on ie needs a bit more about caps and lower case.

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pre-defined-find-amp-replace-sxh-text-in-tables/td-p/10160547
; find a string in a table like txt123 and replace with blank
; By Alanh March 2021

(defun c:test ( / obj str row col x y txt)

(setq obj (vlax-ename->vla-object (car (entsel "pick table" ))))

(setq str (strcat (getstring "\nSearch string prefix ") "#*"))

(vla-put-regeneratetablesuppressed obj :vlax-true)

(setq row (vla-get-rows obj))
(setq col (vla-get-columns obj))
(setq x 1)
(repeat (- row 1)
  (setq y 0)
  (repeat col
    (setq txt (vla-gettext obj x y))
    (if (= (wcmatch txt str ) T)
      (vla-settext obj x y "") 
    )
    (setq y (+ y 1))
  )
  (setq x (+ x 1))
)
(vla-put-regeneratetablesuppressed obj :vlax-false)
(princ)
)
(c:test)
0 Likes
Message 5 of 12

msmith_ncl
Enthusiast
Enthusiast

Thanks for looking at this, I have tried the below, I can get this to remove the item numbers "TXTREP#" from each table but the "999" qty is still there, am I doing something wrong?

Also, I need to run the command twice to pick each table separately, if possible, I'd prefer to just run the command and it auto clears those cells in any table in the current drawing without needing to pick a table.

0 Likes
Message 6 of 12

pbejse
Mentor
Mentor
Accepted solution

@msmith_ncl wrote:

Also, I need to run the command twice to pick each table separately, if possible, I'd prefer to just run the command and it auto clears those cells in any table in the current drawing without needing to pick a table.


Use this if you want something  specific to same target, always "TXTREP#" and thq quantity column regardless

(defun c:deltextrep (/ ss i evt n)
  (if
    (setq ss (ssget "_X" '((0 . "ACAD_TABLE"))))
     (repeat (setq i (sslength ss))
       (Setq evt (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
       (vla-put-regeneratetablesuppressed evt :vlax-true)
       (repeat (- (setq n (vla-get-rows evt)) 2)
	 (if
	   (wcmatch (vla-gettext evt (setq n (1- n)) 0) "TXTREP#*")
	   (progn
	     (vla-settext evt n 0 "")
	    (vla-settext evt n 3 "")
	     )
	 )
       )
       (vla-put-regeneratetablesuppressed evt :vlax-false)
     )
  )
)

 HTH

 

0 Likes
Message 7 of 12

Sea-Haven
Mentor
Mentor

Like pbe I have updated the code, what do you mean by "999" not changing if you want specific value need to change code for  prefix or actual..

 

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pre-defined-find-amp-replace-sxh-text-in-tables/td-p/10160547
; find a string in a table like txt123 and replace with blank
; By Alanh March 2021

(defun c:test ( / ss obj str row col x y txt)

(setq str (strcat (getstring "\nSearch string prefix ") "#*"))

(setq ss (ssget "_X" '((0 . "ACAD_TABLE"))))

(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(vla-put-regeneratetablesuppressed obj :vlax-true)
(setq row (vla-get-rows obj))
(setq col (vla-get-columns obj))
(setq x 1)
(repeat (- row 1)
  (setq y 0)
  (repeat col
    (setq txt (vla-gettext obj x y))
    (if (= (wcmatch txt str ) T)
      (vla-settext obj x y "") 
    )
    (setq y (+ y 1))
  )
  (setq x (+ x 1))
)
)
(vla-put-regeneratetablesuppressed obj :vlax-false)
(princ)
)
(c:test)

 

 

 

0 Likes
Message 8 of 12

msmith_ncl
Enthusiast
Enthusiast

This is perfect, thanks again

0 Likes
Message 9 of 12

msmith_ncl
Enthusiast
Enthusiast

Sorry to be a pain, I have just run into another issue and hoping it can easily be included in this routine.  My bill of materials tool uses external text support files to add items into the tables, I have just started using items with inch symbol in the part number and description and for some unknown reason the " symbol is being doubled every time and appearing in the table as "".  Would be a massive help if those double quotes in the table can all be replaced with single quotes using the same tool that already empties other cells.

 

support text file below

msmith_ncl_0-1616079089709.png

Result from Bill of materials tool

msmith_ncl_1-1616079274827.png

 

0 Likes
Message 10 of 12

pbejse
Mentor
Mentor
Accepted solution

@msmith_ncl wrote:

Sorry to be a pain, ...

the table can all be replaced with single quotes using the same tool that already empties other cells.

 


(defun c:deltextrep (/ ss i evt n)
  (if
    (setq ss (ssget "_X" '((0 . "ACAD_TABLE"))))
     (repeat (setq i (sslength ss))
       (Setq evt (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
       (vla-put-regeneratetablesuppressed evt :vlax-true)
       (repeat (- (setq n (vla-get-rows evt)) 2)
	 (if
	   (wcmatch (vla-gettext evt (setq n (1- n)) 0) "TXTREP#*")
	    (progn
	      (vla-settext evt n 0 "")
	      (vla-settext evt n 3 "")
	    )
	 )
	 (if (wcmatch  (setq str (vla-gettext evt n 1)) "*\"\"*" )
	   (progn
	   	(While (vl-string-search "\"\"" str)
		  	(setq str (Vl-string-subst  "\"" "\"\"" str))
		  )
	     (vla-settext evt n 1 str)
	     )
	   )
       )
       (vla-put-regeneratetablesuppressed evt :vlax-false)
     )
  )
)

HTH

 

0 Likes
Message 11 of 12

msmith_ncl
Enthusiast
Enthusiast

Thanks again, that's awesome

0 Likes
Message 12 of 12

pbejse
Mentor
Mentor

@msmith_ncl wrote:

Thanks again, that's awesome


 

Cool beans , You are welcome.

 

 

0 Likes