Find an Replace - save object selection set

Find an Replace - save object selection set

thomas_schluesselberger
Advocate Advocate
1,704 Views
22 Replies
Message 1 of 23

Find an Replace - save object selection set

thomas_schluesselberger
Advocate
Advocate

Hi,

 

I'm looking for a lisp to improve on the standard "find and replace" command.


With the standard command, the object selection resets every time I close the command. That's pretty annoying because I have to mark the objects to be searched again every time.
So i need a lisp (or maybe a workaround) that saves the selection.

 

Just to make shure what i want, this is the workflow i have:

> Execute search command

> mark objects that are to be searched

> create a selection set from the list, depending on whether only individual objects or all objects

> make various changes > execute search command

> the same objects that are to be searched should be marked

(if objects have been deleted from them in the meantime, the search should still be done with the objects that still exist)

 

 

0 Likes
Accepted solutions (3)
1,705 Views
22 Replies
Replies (22)
Message 2 of 23

pendean
Community Legend
Community Legend
FIND command remembers the last selection while still in the same AutoCAD session, even between DWG files here: plus earlier selections through the pulldown selections.

Is that not the case for you? Or do you want this ability also between AutoCAD sessions (pick up this morning where you left off last week when you went on vacation)?
0 Likes
Message 3 of 23

Kent1Cooper
Consultant
Consultant

FIND has that ability, over on the right [after you've hit the Find button and it has some result(s)]:

Kent1Cooper_0-1688734863250.png

That pop-up is about the lower of the two red-circled options; the upper also leaves the selection highlighted/gripped.  It doesn't name the selection set as an AutoLisp variable, but you can do that by following it with:

(setq ss (ssget "_P"))

Kent Cooper, AIA
0 Likes
Message 4 of 23

andkal
Collaborator
Collaborator

Under those links you can find a plugin that I wrote some time ago for selecting various objects that contain a desired phrase of text. It features also a selection manager where you can save a selection for the future use.

https://apps.autodesk.com/ACD/pl/Detail/Index?id=8683372876092716848&appLang=en&os=Win32_64 

https://autolisps.blogspot.com/p/findandselectbytextcontent.html 

 

FIND_AND_SELECT_BY_TEXT_CONTENT_screenshot.jpgSELECTION_MANAGER_v1_00.jpg


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Message 5 of 23

thomas_schluesselberger
Advocate
Advocate
Hi, for me it only remembers the selection if i dont close the find command.
Only when i search something and then instantly search for another phrase it rembers the selection.

So when i do this workflow it doesnt rember: SEARCH command -> entering phrase and search -> select results (after this, the search command closes and the selection of objects is made) -> change some stuff -> SEARCH command -> and now the selection of the previous search should still be the same
0 Likes
Message 6 of 23

thomas_schluesselberger
Advocate
Advocate
Hi,

the possibility to mark the found objects is known to me. My problem is that the selection of which objects should be searched is reset after restarting SEARCH.
0 Likes
Message 7 of 23

thomas_schluesselberger
Advocate
Advocate
Hi,

i tried the testversions of both lisps but both just give out nil when entering the command.

Maybe my german version has something to do with that. English commands don't work on my German version. So if you have coded direct commands somewhere in the LISP, that's where the error comes from.
It could work, if the commands have an underscore before (e.g.: "_move"), then it gets translated automatically.
0 Likes
Message 8 of 23

pendean
Community Legend
Community Legend

@thomas_schluesselberger wrote:
...My problem is that the selection of which objects should be searched is reset after restarting SEARCH.

Greetings: can you share with us a screenshot of your ABOUT command pop-up and confirm your OS version please?

0 Likes
Message 9 of 23

andkal
Collaborator
Collaborator

Hello Thomas
Thak you for your reply.
Actually there are no direct commands built in those particular lisps. Maybe try using it on some other file or in a new drawing.
At work I also use a german version, becouse I live in Austria from some time, but no such error occurs on my PC.


• www.autolisps.blogspot.com - Productivity plugins for Autocad and Autocad MEP
• Autodesk AppStore
0 Likes
Message 10 of 23

thomas_schluesselberger
Advocate
Advocate
Hello!

What exactly should I take a screenshot of? What do you mean by "ABOUT command pop-up" and what is OS (do you mean my AutoCAD version?).
0 Likes
Message 11 of 23

komondormrex
Mentor
Mentor

hello,

if you'll keep selection set of entities within which you want to perform search and replace, you may try this code.

 

(defun c:find_in_selected nil
	(if (cadr (ssgetfirst))
		(command "_.find")
		(progn
			(if search_within_sset 
				(if (= 7 (acet-ui-message "There is previously made selection set.\nActivate it <Yes> or make new <No>\nto search within?"
										  "Selection set found" 4
					     )
					)
						(progn
							(prompt "Select enames to find within")
							(sssetfirst nil (setq search_within_sset (ssget)))
						)
						(sssetfirst nil search_within_sset)
				)
			)
			(command "_.find")
		)
	)
	(if search_within_sset (sssetfirst nil search_within_sset))
	(princ)
)

 

 

0 Likes
Message 12 of 23

pendean
Community Legend
Community Legend

@thomas_schluesselberger wrote:
What exactly should I take a screenshot of? What do you mean by "ABOUT command pop-up" and what is OS (do you mean my AutoCAD version?).

ABOUT command in AutoCAD presents a pop-up/dialog box: I would like to see what exact variant you are running when you get a chance.

 

OS=Operating System.

0 Likes
Message 13 of 23

thomas_schluesselberger
Advocate
Advocate

Hello,

 

I attached a video for you by trying to visualize it.
I'm searching for objects that contain "1". I marked the ones I found and then ended the selection and moved a symbol. Then I start the search again and had to mark the same objects again.

 

 

I'm working with "AutoCAD 2023" and with "Windows 10 Pro for Workstations"

 

0 Likes
Message 14 of 23

thomas_schluesselberger
Advocate
Advocate
Hello,

sadly thats not working for me.

I need to search -> select objects which shoud be searched -> change found objects (attribute changes, position changes, etc.) -> start new search with same objects as previous.
0 Likes
Message 15 of 23

pendean
Community Legend
Community Legend
OK, so you want FIND command to automatically reselect objects for you when you start it back up then add newer selections? That's not how FIND has ever worked, looks like you need to be using QSELECT or FILTER instead. FIND command is the incorrect tool for your need.

Thanks for the video.
0 Likes
Message 16 of 23

Kent1Cooper
Consultant
Consultant
Accepted solution

@pendean wrote:
.... you want FIND command to automatically reselect objects for you when you start it back up then add newer selections? That's not how FIND has ever worked, looks like you need to be using QSELECT or FILTER instead. FIND command is the incorrect tool for your need. ....

As far as I know, neither QSELECT nor FILTER can locate all the different object types that might contain the specified text content in whole or in part, together, the way FIND can, so what they're hoping for is at least understandable.  Whether there's a way to accomplish that goal is another question....

 

EDIT:  An approach I tried, that should be automatable to some degree:

FIND, of course with List results checked, do your thing.

With the findings in the list all selected, pick either of the Create selection set icons on the right; you'll be left with them all selected/gripped/highlighted.

Put them into a variable:  (setq ss (ssget "_I"))

Do what you want with some of them [Attribute and/or Text/Mtext content changes, position changes, etc.].

Re-select/grip/highlight the same selection:  (sssetfirst nil ss)

FIND again, and in the Find where: pull-down at upper right, Selected objects will already be chosen since there is a pre-selection, so all you need to do is pick on the Find button near bottom center again.

 

When I did that with it finding 11 objects, and I changed the content of one so it didn't match any more, on the follow-up it found 10 objects.

 

A Tool Palette button or a little command name definition could do the putting of FIND's current selection into the variable, and another could do the re-selecting of that selection and the recalling of the FIND command.

 

Further EDIT:

(defun C:FF ()
  (setq *FFss* (ssget "_I"))
)

(defun C:FFF ()
  (sssetfirst nil *FFss*)
  (command "_.find")
  (prin1)
)

Load those in [assuming you don't already use those command names].  Do FIND, select all its findings [or only some of them if you want] in the list, and pick on one of the Create selection set icons.  Type FF.

Do what you want with stuff.  Type FFF, and just pick on the Find button in the dialog box again.  Assuming you have not used FIND with other settings in the meantime, the same Find options will be applied to the same selection, and whatever still fits the criteria will be found.

Kent Cooper, AIA
0 Likes
Message 17 of 23

thomas_schluesselberger
Advocate
Advocate

Hello,

 

thank you very much, this is working great.

 

There is just one small improvement that would prevent mistakes:

If I accidentally type FF instead of FFF, the selection gets reset. Is it possible to adjust the LISP so that FF only creates a new objectselection when objects are actually selected?

So if: No objects are selected and I type FF, then a message with "no objects selected" appears and the object selection should remain at the previous one.

 

0 Likes
Message 18 of 23

komondormrex
Mentor
Mentor

hmmm, it was supposed to do exactly that. and it does.

0 Likes
Message 19 of 23

pendean
Community Legend
Community Legend
>>>...If I accidentally type FF instead of FFF...<<<
@thomas_schluesselberger Any reason you opted not to rename them from FF / FFF to something unrelated? Don't call everything an apple if you don't want apples all the time 🙂
0 Likes
Message 20 of 23

Kent1Cooper
Consultant
Consultant
Accepted solution

@thomas_schluesselberger wrote:

.... Is it possible to adjust the LISP so that FF only creates a new objectselection when objects are actually selected?

So if: No objects are selected and I type FF, then a message with "no objects selected" appears and the object selection should remain at the previous one.


(defun C:FF ()
  (if (ssget "_I")
    (setq *FFss* (ssget "_I")); then
    (prompt "\nNo object(s) selected."); else
  )
)

 

Kent Cooper, AIA
0 Likes