Script or Lisp to filter specific Text

Script or Lisp to filter specific Text

Anonymous
Not applicable
1,866 Views
11 Replies
Message 1 of 12

Script or Lisp to filter specific Text

Anonymous
Not applicable

Hello,

my task is to make a Script or Lisp, so we can just run this to filter all specific text´s (like "KS" "WT" "GS" "WM" "KL") out, move them 100 right, delete the rest of the text´s and move the filtered text´s 100 back. Problem is that I am an absolute noob with scripts and Lisps because i have never worked with them before. If it´s possible it sohuld be done in a way that we didnt have to do anything eles than loading the script.

I would apriciate your help in German or English.

-Simon

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

ВeekeeCZ
Consultant
Consultant

This code selects all those texts. What would you do with an active selection next, is up to you.

 

(sssetfirst nil (ssget "_X" '((0 . "*TEXT") (1 . "KS,WT,GS,WM,KL"))))

Add this as a macro to your toolpalette.

0 Likes
Message 3 of 12

Anonymous
Not applicable

Thx BeeKeeCZ for your reply,
before i had it like this in a .scr:

_move
all

 

0,0
100,0

thats to just move them 100 right ,
so i cant just copy your code infornt of it and use it like i tought it might work, can you explane my why 

0 Likes
Message 4 of 12

ВeekeeCZ
Consultant
Consultant
(sssetfirst nil (ssget "_X" '((0 . "*TEXT") (1 . "KS,WT,GS,WM,KL"))))
_move
0,0
100,0

But I wouldn't do that. Why to combine script and lisp if you can use just a lisp?

(defun c:MoveMyTextRight () (command "_move" (ssget "_X" '((0 . "*TEXT") (1 . "KS,WT,GS,WM,KL"))) "" "_non" '(0 0 0) "_non" '(100 0 0)) (princ))

How would you run the command? By name or using a toolpalette?

 

0 Likes
Message 5 of 12

Anonymous
Not applicable

We would like to use them with drag and drop them into the drawings.

 

But when i copy your code into a lisp save it and drop it on the drawing exectly nothing happens. maybe i´m making a mistake?, but idk.

 

thx for your patience ^^"

0 Likes
Message 6 of 12

ВeekeeCZ
Consultant
Consultant

It's not the way that people usually use, but possible... use just this part, save it as *.lsp and drag and drop it into dwg.

(command "_move" (ssget "_X" '((0 . "*TEXT") (1 . "KS,WT,GS,WM,KL"))) "" "_non" '(0 0 0) "_non" '(100 0 0))
(princ)

Or read HERE  how people usually use lisps.

 

0 Likes
Message 7 of 12

Anonymous
Not applicable

okey like that it works perfectly fine, now how about deleting the rest texts(is this posible without giving a "window" to mark them? and moving back the ones we moved out  ? 

0 Likes
Message 8 of 12

dlanorh
Advisor
Advisor
Why move the text, then move it back? If you reverse the filter and select all text not matching you can just delete them.

I am not one of the robots you're looking for

0 Likes
Message 9 of 12

Anonymous
Not applicable

it was thought as control, if we see yeah ther are 20 moved we know that everything is where it should be without having to watch directly over it. the rest of the texts is variable so i cant tell only from the deleted ones

0 Likes
Message 10 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

it was thought as control, if we see yeah ther are 20 moved we know that everything is where it should be without having to watch directly over it. the rest of the texts is variable so i cant tell only from the deleted ones


 

This does that, but it happens so fast that you probably won't really see the ones moved over and then moved back.

(command
"_.move" (setq ss (ssget "_X" '((0 . "*TEXT") (1 . "KS,WT,GS,WM,KL")))) "" "36,0" ""
"_.erase" (ssget "_X" '((0 . "*TEXT"))) "_remove" ss ""
"_move" ss "" "-36,0" ""
)

I tried putting a delay in, in a couple of places, but it seemed to delay the whole thing without delaying between operations.  But you could see which ones were kept afterward, easily enough:

(command
  "_.move" (setq ss (ssget "_X" '((0 . "*TEXT") (1 . "KS,WT,GS,WM,KL")))) "" "36,0" ""
  "_.erase" (ssget "_X" '((0 . "*TEXT"))) "_remove" ss ""
  "_move" ss "" "-36,0" ""
)
(sssetfirst nil ss)

 Which effectively could be done more simply, without the Moving since you don't really see that happen:

(setq ss (ssget "_X" '((0 . "*TEXT") (1 . "KS,WT,GS,WM,KL"))))
(command  "_.erase" (ssget "_X" '((0 . "*TEXT"))) "_remove" ss "")
(sssetfirst nil ss) 

 

Kent Cooper, AIA
0 Likes
Message 11 of 12

dlanorh
Advisor
Advisor

You could also just

(command  "_.erase" (ssget "_X" '((0 . "*TEXT") (-4 . "<NOT") (1 . "KS,WT,GS,WM,KL") (-4 .  "NOT>"))) "")

 

 

I am not one of the robots you're looking for

0 Likes
Message 12 of 12

Sea-Haven
Mentor
Mentor

Just for future drag and dropping, you may have a defun that you want to run more than once so how to run 1st time then again ?

 

Its easy if you add the defun name in full at the end of the code it will run. I do most of mine this way. NOTE C: must be included if defun name.

 

(alert "Type MoveMyTextRight to run again")
(c:MoveMyTextRight)
0 Likes