I am looking for a LISP routine that would delete a string of text before or after a DASH.
I have looked everywhere for such a thing and not sure if this exists, or not sure if there is an easy way to do this otherwise.
I have attached a drawing to better explain.
Any help is very appreciated.
Thanks in advance!
Solved! Go to Solution.
Solved by doni49. Go to Solution.
I would think this could be done fairly quickly with FIND.
You would have to do it in two groups - one for the prefix removal, one for the suffix removal.
In the "Find what" field use question marks as placeholders for the letters, followed by a dash.
For the prefix removal, use ?????-.
For the suffix, use -?????.
(Note: be sure to set the "use wildcards" search option; click the More Options arrow at the lower-left to access.)
This will do what you've asked for but be careful as there's no error checking. I'm not sure what it'll do if there is no dash in the selected text. Run REMB to remove the BEFORE portion and run REMA to remove the AFTER portion. And select the appropriate text elements.
;; ;; By Don Ireland ;; ;; Takes two arguments: A String to search for and a string to search in. ;; Usage: (charfind "ST" "TEST") ; This will return 3. ;; ;; Example: (if (> (setq pos (charfind "S" "TEST")) 0)(princ "Found the letter S at position: " . pos)(Princ "One or both search parameters was blank")) ;; ;; Return Values: ;; -1 = character not found within given string. ;; -2 = Search string is empty. (srch) ;; -4 = Test String is empty. (str) ;; -6 = Search String and Test String are both empty. (defun strfind(srch str / pt pt2 cnt) (setq cnt 0 pt 0 pt2 nil) (if (EQ (strlen srch) 0) (setq pt -2)) (if (EQ (strlen str) 0) (setq pt (+ pt (- 0 4)))) (if (EQ pt 0)(setq pt -1)) (while (and (< pt 0) (> (strlen str) 0)(< cnt (strlen str))) (if (eq srch (substr str (setq cnt (1+ cnt)) (strlen srch)))(setq pt cnt)) ) (setq pt2 pt) ) (defun remTxt(ba) (setq ent(ssget '( (-4 . "<OR") (0 . "TEXT")(0 . "MTEXT") (-4 . "OR>") )) ) (setq cnt -1) (repeat (sslength ent) (setq cent (entget (ssname ent (setq cnt (1+ cnt))))) (setq cur (cdr(assoc 1 cent))) (setq pos (strfind "-" cur)) (if (EQ ba 1) (setq new (substr cur 1 (1- pos))) (setq new (substr cur (1+ pos) (strlen cur))) ) (setq cent(subst (cons 1 New) (cons 1 cur) cent)) (entmod cent) ) ) (defun c:remA() (remTxt 1) ) (defun c:remB() (remTxt 0) )
Don Ireland
Engineering Design Technician
@Anonymous wrote:
Thanks to all of you! All of your solutions worked great!
Glad to be of assistance. But for future knowledge, you'd be better served posting questions about AutoLISP over in the AutoLISP forum. There is a greater concentration of people who know how to use it over there.
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/bd-p/130
Don Ireland
Engineering Design Technician
Here is another workaround to get what you are looking for, I am using the free tool called LayoutManager available to download from Autodesk Exchange Apps store
To remove the string at right side of the - which ends with "-ABB, set the below conditions using command "Text-Find & Replace
To remove strings which starts with ABZ and - in between, set the below conditions using command "Text-Find & Replace
hi don
your lisp is pretty so good but i have a problem with your lisp. why deleting after or before a dash. there is no solution like that (12/12). i would like to need this " this is a text" i would like to delete "this is" could you make for us. it would really appreciate.
@thajmul2501 wrote:
.... why deleting after or before a dash. ....
Because that is the Subject of this thread. If you need a different function, Search for a thread about what you are trying to do, or start a new one.
@Kent1Cooper wrote:
@thajmul2501 wrote:.... why deleting after or before a dash. ....
Because that is the Subject of this thread. If you need a different function, Search for a thread about what you are trying to do, or start a new one.
hi kent
thank you so much for kind reply.
i don't know how to start. i would like to need delete text suffix or prefix because i have no text with dash some time might be come. i want to delete txt suffix or prefix example "THIS IS A WORD" i would like to delete "THIS IS" only. how to make it. you are familiar with lisp that i was posted here.
i hope you could help me. many thanks
best regards
hussain
hi Family 🙂
can we have this command do the same for (~) instead of (-)?
i have the same task of removing text before we give to our customer but i have to remove everything after (~).
for example:
IN: 328' 3/C #2BC 12KV (TO 2045E) ~ZOHC 709
IN: 328' 3/C #2BC 12KV (TO 2045E)
thanks Family!
Hello Good sir!
i love the lisp!!
is there a way to add block attributes? i want this to work but i have to burst the block first then use the lisp you created.
either way its AWESOME lisp!! just a little change (i assume little lol, i have no clue) to better suit my needs
i want to select the block with attributes to work the same as selecting text strings im crossing my fingers!
;;
;; By Don Ireland
;;
;; Takes two arguments: A String to search for and a string to search in.
;; Usage: (charfind "ST" "TEST") ; This will return 3.
;;
;; Example: (if (> (setq pos (charfind "S" "TEST")) 0)(princ "Found the letter S at position: " . pos)(Princ "One or both search parameters was blank"))
;;
;; Return Values:
;; -1 = character not found within given string.
;; -2 = Search string is empty. (srch)
;; -4 = Test String is empty. (str)
;; -6 = Search String and Test String are both empty.
(defun strfind(srch str / pt pt2 cnt)
(setq cnt 0 pt 0 pt2 nil)
(if (EQ (strlen srch) 0) (setq pt -2))
(if (EQ (strlen str) 0) (setq pt (+ pt (- 0 4))))
(if (EQ pt 0)(setq pt -1))
(while (and (< pt 0) (> (strlen str) 0)(< cnt (strlen str)))
(if (eq srch (substr str (setq cnt (1+ cnt)) (strlen srch)))(setq pt cnt))
)
(setq pt2 pt)
)
(defun remTxt(ba)
(setq ent(ssget '(
(-4 . "<OR")
(0 . "TEXT")(0 . "MTEXT")
(-4 . "OR>")
))
)
(setq cnt -1)
(repeat (sslength ent)
(setq cent (entget (ssname ent (setq cnt (1+ cnt)))))
(setq cur (cdr(assoc 1 cent)))
(setq pos (strfind "~" cur))
(if (EQ ba 1)
(setq new (substr cur 1 (1- pos)))
(setq new (substr cur (1+ pos) (strlen cur)))
)
(setq cent(subst (cons 1 New) (cons 1 cur) cent))
(entmod cent)
)
)
(defun c:remA()
(remTxt 1)
)
(defun c:remB()
(remTxt 0)
)