CAD Forum - Database of tips, tricks and utilities for AutoCAD, Inventor and other Autodesk products [www.cadforum.cz]
CZ | EN | DE
Login or
registration
  Visitors: 8992
RSS channel - CAD tips RSS tips
RSS discussions

Discussion Discussion forum

 

HelpCAD discussion

 
CAD Forum - Homepage CAD discussion forum - ask any CAD-related questions here, share your CAD knowledge on AutoCAD, Inventor, Revit and other Autodesk software with your peers from all over the world. To start a new topic, choose an appropriate forum.

Please abide by the rules of this forum.

How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic Closedselect several mtext contains same letters

 Post Reply Post Reply
Author
Sandervp View Drop Down
Groupie
Groupie


Joined: 02.Jun.2014
Location: Netherlands
Using: Autocad 2015 and older
Status: Offline
Points: 30
Direct Link To This Post Topic: select several mtext contains same letters
    Posted: 17.Feb.2015 at 10:58
Hello everybody,

I have got a drawing with a lot of mtext objects. These objects are also different layers.

But the most of these mtext objects have something in common. They are containg the same letter combination. For example: "example 001", "example 149", "example 572" etc.

How can I select all those objects containing these letter combination?

I want to change these into one layer.

Thanks!
Back to Top
John Connor View Drop Down
Senior Member
Senior Member


Joined: 01.Feb.2011
Location: United States
Using: AutoCAD 2018
Status: Offline
Points: 7175
Direct Link To This Post Posted: 17.Feb.2015 at 11:20
Could possibly be done using a custom lisp routine.
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>

Back to Top
Kent Cooper View Drop Down
Senior Member
Senior Member


Joined: 12.Mar.2013
Location: United States
Using: AutoCAD2020, 2023
Status: Offline
Points: 631
Direct Link To This Post Posted: 17.Feb.2015 at 16:19
Using (ssget) to find a selection set, searching the entire drawing with a selection filter including wildcards [read about the (wcmatch) function] should do it:
 
(command
  "_.chprop"
  (ssget "_X" '((0 . "MTEXT") (1 . "*example 001*")))
  ""
  "_layer" "YourDesiredLayer"
  ""
)
 
If they might not all be in the current space, you would need to do it differently [the CHPROP command won't "find" those not in the current space], but it can be done -- write back.


Edited by Kent Cooper - 17.Feb.2015 at 16:22
Back to Top
Sandervp View Drop Down
Groupie
Groupie


Joined: 02.Jun.2014
Location: Netherlands
Using: Autocad 2015 and older
Status: Offline
Points: 30
Direct Link To This Post Posted: 18.Feb.2015 at 09:07
Thank you Kent Cooper.

Your solution works!

Is it also possible to create a toolbar button with this command string, and after putting this button, I need to put a letter combination in my commandbar? So I can select different mtext objects time after time. And change the layer time after time?

The reason why;
The drawing that I have is from a huge industirial area. This area contains a lot of buildings. Every building has got his own letter. And every building has got a lot of details. These details are other dwg's. All the windows, doors and several other objects in building A are having their own (detail)letter combination. These letter combination starts with "A__".
It is the same in the other building, only the first letter is the letter from the building.

Thank you

Back to Top
Kent Cooper View Drop Down
Senior Member
Senior Member


Joined: 12.Mar.2013
Location: United States
Using: AutoCAD2020, 2023
Status: Offline
Points: 631
Direct Link To This Post Posted: 18.Feb.2015 at 15:04
A routine can ask the User for input of a variety of different kinds, and then use it appropriately.  For example, to change all Mtext starting with a letter followed by two underscore characters to a specific Layer, where the User specifies the first letter and the Layer, something like:
 
(defun C:YourCommandName (/ first lay)
  (setq
    first (getstring "\nInitial letter: ")
    lay (getstring "\nLayer to move to: ")
  ); setq
  (command
    "_.chprop"
    (ssget "_X" (list '(0 . "MTEXT") (cons 1 (strcat first "__*"))))
    ""
    "_layer" lay
    ""
  ); command
); defun
 
A menu button to call that command would contain:
(C:YourCommandName)
 
or you could type the command name in.
 
That's case-sensitive about the initial letter, but it's possible to have it allow them to designate the letter either way.  It could also be made to do other fancy things, such as ask again if they type in more than one letter or a non-alphabetic character, or a Layer name that doesn't exist in the drawing.  If the Layer to move things to is always the same except for that same initial letter, it could construct that itself, rather than ask the User for a Layer name.
 
It sounds like you may be talking about doing something with Blocks or Xrefs, rather than Mtext, which would of course be a little different, but the approach would be similar.
 
Read up on the (list) and (quote) functions to understand the different construction of the (ssget) filter list from the earlier version.
Back to Top
Sandervp View Drop Down
Groupie
Groupie


Joined: 02.Jun.2014
Location: Netherlands
Using: Autocad 2015 and older
Status: Offline
Points: 30
Direct Link To This Post Posted: 24.Feb.2015 at 09:41
Hello Kent,

Sadly, your solution didn't work.

I've made a lisp file, called "Test", which contains your routine.

I'd load this lisp with apppload.

The intention was to move every mtext object containing the 0, to the layer 0.

The first 2 steps were oké, but after that, it went wrong.
You can see the consequence below: 


Command: test
Initial letter: 0

Layer to move to: 0
_.chprop
Select objects:
Command: TEST
Unknown command "TEST".  Press F1 for help.

Command: _layer
Current layer:  "OWT"
Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: 0
Invalid option keyword.
Function cancelledEnter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:


What went wrong, during this routine?

Thank yoyu
Back to Top
Kent Cooper View Drop Down
Senior Member
Senior Member


Joined: 12.Mar.2013
Location: United States
Using: AutoCAD2020, 2023
Status: Offline
Points: 631
Direct Link To This Post Posted: 24.Feb.2015 at 15:26
Originally posted by Sandervp Sandervp wrote:

...Sadly, your solution didn't work.
....
The intention was to move every mtext object containing the 0, to the layer 0.
....
Layer to move to: 0
_.chprop
Select objects:
Command: TEST
Unknown command "TEST".  Press F1 for help.
Command: _layer
....
 
The routine is written to find [if you give it "0" for the initial letter] any Mtext not merely containing "0", but specifically beginning with "0" followed by two underscore characters, in keeping with your original description [' These letter combination starts with "A__". '].  It works for me.
 
The fact that it returns to the Command: prompt after after only one Select objects: prompt suggests to me that there are no Mtext objects in the drawing that begin with "0__", that is, the (ssget) function returns nil.  The "" [Enter] that is there to complete the selection [which should be fed in at a second Select objects: prompt] then instead recalls the last command entered at the Command: prompt ["TEST"], but inside a (command) function it won't recognize a (defun)'d command name, only native AutoCAD command names, which is why it gives the Unknown command message.  Then the _layer that is there to be an option within the CHPROP command coincidentally happens to also be a command name that it recognizes, so it inappropriately begins that command.
 
Ensure that there is at least one Mtext object whose text content begins with "0__", and see whether it works.  It could easily be made to check whether it finds any Mtext that starts with the right sub-string before proceeding, if you like.  It could also be made to find any Mtext that begins with the initial character without necessarily having "__" following it, if that's appropriate, or with the initial character + "__" but not necessarily at the beginning.  [It could also be made to find all Mtext that merely contains the initial character anywhere in it, if that's what you really want, but that seems likely to change more Mtext than you want to a different Layer, especially if the initial character is a letter].


Edited by Kent Cooper - 24.Feb.2015 at 15:33
Back to Top

Related CAD tips:


 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,398 seconds.