Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

deleting text that is 10 values long or less??

20 REPLIES 20
Reply
Message 1 of 21
Anonymous
1855 Views, 20 Replies

deleting text that is 10 values long or less??

I often have DXF files that contain very many short (10 digits or less) instances of text, and only a few long instances of text (11 digits or more)....

 

I would like to use AutoLISP to delete all of the short text in my DXF file, but leave the longer text. 

 

Can anyone tell me a good way to go about doing this???

 

Beginning to intermediate-ish user.

20 REPLIES 20
Message 2 of 21
Lee_Mac
in reply to: Anonymous

Here's a quick example for you:

 

 

(defun c:delshorttxt ( / e i s )
    (if (setq s (ssget "_X" '((0 . "TEXT"))))
        (repeat (setq i (sslength s))
            (setq e (ssname s (setq i (1- i))))
            (if (<= (strlen (cdr (assoc 1 (entget e)))) 10)
                (entdel e)
            )
        )
    )
    (princ)
)
Message 3 of 21
alanjt_
in reply to: Lee_Mac

(defun c:deleteTheShorties (/ ss i e)
  (if (setq ss (ssget "_X" '((0 . "TEXT") (-4 . "<NOT") (1 . "???????????*") (-4 . "NOT>"))))
    (repeat (setq i (sslength ss)) (entdel (ssname ss (setq i (1- i)))))
  )
  (princ)
)

 

EDIT: I can't belive they don't filter smilies in code blocks.

Message 4 of 21
Lee_Mac
in reply to: Anonymous

Nice use of the filter list Alan.

 

I initially considered using:


 

(1 . "??????????,?????????,????????,??????? ....")

 

But hadn't thought of using the reverse logic.

 

And yeah, the code panes on this forum are useless.

Message 5 of 21
3wood
in reply to: Anonymous

You can also try ALTEXT.vlx which can replace any numbers less than a certain number with a blank " ".

In the settings, select "New", "Number", "New text" = " ", and define "Start from" and "End at".

 

3wood

CAD KITS

Message 6 of 21
alanjt_
in reply to: Lee_Mac


@Lee_Mac wrote:

Nice use of the filter list Alan.

 

I initially considered using:


 

(1 . "??????????,?????????,????????,??????? ....")

 

But hadn't thought of using the reverse logic.

 

And yeah, the code panes on this forum are useless.




 

Smiley Happy

Message 7 of 21
Kent1Cooper
in reply to: alanjt_


@alanjt_ wrote:
(defun c:deleteTheShorties (/ ss i e)
  (if (setq ss (ssget "_X" '((0 . "TEXT") (-4 . "<NOT") (1 . "???????????*") (-4 . "NOT>"))))
    (repeat (setq i (sslength ss)) (entdel (ssname ss (setq i (1- i)))))
  )
  (princ)
)

....


If there aren't complications of multiple Layouts or something [can DXF files even have those?], you can get rid of them all in one shot, instead of individually:

 

(defun c:deleteTheShorties (/ ss)
  (if (setq ss (ssget "_X" '((0 . "TEXT") (-4 . "<NOT") (1 . "???????????*") (-4 . "NOT>"))))
    (command "_.erase" ss "")
  )
  (princ)
)

 

Yes, the (command) approach may "take longer" measured perhaps in small fractions of a second depending on the quantity of Text entities.  Could it be that, with enough of them, the fact that one operation gets rid of them all, rather than a separate operation for each, would make up the difference?

 

But the real reason I'm replying is:  I don't generally deal with DXF files, but that's what the original question is about.  Would this require opening each file as a drawing [or perhaps DXFINing it into one], running the routine, and DXFOUTing it, or SAVEASing it as a DXF, to overwrite the original file?  Or can such a thing be applied to a DXF file without actually opening it?  Or is there another way to do that?

Kent Cooper, AIA
Message 8 of 21
alanjt_
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@alanjt_ wrote:
(defun c:deleteTheShorties (/ ss i e)
  (if (setq ss (ssget "_X" '((0 . "TEXT") (-4 . "<NOT") (1 . "???????????*") (-4 . "NOT>"))))
    (repeat (setq i (sslength ss)) (entdel (ssname ss (setq i (1- i)))))
  )
  (princ)
)

....


If there aren't complications of multiple Layouts or something [can DXF files even have those?], you can get rid of them all in one shot, instead of individually:

 

(defun c:deleteTheShorties (/ ss)
  (if (setq ss (ssget "_X" '((0 . "TEXT") (-4 . "<NOT") (1 . "???????????*") (-4 . "NOT>"))))
    (command "_.erase" ss "")
  )
  (princ)
)

 

Yes, the (command) approach may "take longer" measured perhaps in small fractions of a second depending on the quantity of Text entities.  Could it be that, with enough of them, the fact that one operation gets rid of them all, rather than a separate operation for each, would make up the difference?




You may not being iterating through the selectionset, but the ERASE command is.

Message 9 of 21
pbejse
in reply to: alanjt_


@alanjt_ wrote:
(defun c:deleteTheShorties (/ ss i e)
  (if (setq ss (ssget "_X" '((0 . "TEXT") (-4 . "<NOT") (1 . "???????????*") (-4 . "NOT>"))))
    (repeat (setq i (sslength ss)) (entdel (ssname ss (setq i (1- i)))))
  )
  (princ)
)

 

EDIT: I can't belive they don't filter smilies in code blocks.


This line does the same thing

(1 . "~???????????*") without the NOT

 

Whats the diffrenece?

 

Message 10 of 21
alanjt_
in reply to: pbejse


@pbejse wrote:

This line does the same thing

(1 . "~???????????*") without the NOT

 

Whats the diffrenece?

 



Six in one, half a dozen in the other.

Message 11 of 21
pbejse
in reply to: alanjt_


@alanjt_ wrote:


Six in one, half a dozen in the other.


 

 

Indeed it is

 

Cheers

 

Message 12 of 21
alanjt_
in reply to: pbejse

🙂

Message 13 of 21
john.uhden
in reply to: alanjt_

This discussion was soooo cute!  Thank you for brightening my day.

John F. Uhden

Message 14 of 21
pbejse
in reply to: john.uhden


@john.uhden wrote:

This discussion was soooo cute!  Thank you for brightening my day.


How do you find time digging around old post on your OOSRBTW [ Out-OF-Semi-Retirement Back To Working Class ] status?  I would think you'll be spending less time on the forum for nowadays

 

Lean back on your chair, look up in the ceiling and read the message I posted there. 

 

Made you look!

 

But if I  would've posted a message there, it would be like this

 

((4 1) (3 2) (8 1) (0 1) (2 2) (2 1) (2 3) (5 2) (0 1) (8 1) (6 3) (0 1) (9 1) (6 3) (7 3) (5 2) (0 1) (9 3) (6 3) (8 2) (0 1) (7 4) (5 3) (2 1) (2 3) (5 2) (3 2) (7 3))

or

((4) (3 3) (8) (0) (2 2) (2) (2 2 2) (5 5) (0) (8) (6 6 6) (0) (9) (6 6 6) (7 7 7) (5 5) (0) (9 9 9) (6 6 6) (8 8) (0) (7 7 7 7) (5 5 5) (2) (2 2 2) (5 5) (3 3) (7 7 7))

 

Hint:


nokia keypad.jpg

 

To make this more interesting, write a lisp code to decipher the message.

 

 

 

 

 

 

 

 

Have fun John.

 

Message 15 of 21
john.uhden
in reply to: pbejse

"get?abc?k?t..............."

 

Whuh?

 

BTW, I am having fun.  I am at work waiting for the Russian gal to show me how to get into C3D 2014 on another machine.  Mine has only C3D 2010.

John F. Uhden

Message 16 of 21
pbejse
in reply to: john.uhden


@john.uhden wrote:

"get?abc?k?t..............."

 

Whuh?


Haha 😄

 

But If you are still interested because I see you get the general idea..

 

((4 1) (3 2) <-- The second element is the number of times you press the key

(8 1) (0 1)  <-- 0 usually represents a space |__|  where i came from

or

((4) (3 3)<- two times

(8) (0)

 

Cant say I blame you, guess its too much to ask a guy to ignore a Russian gal just to put a little effort in writing a code for fun 🙂

Anyhoo... 

 

Cheers

 

Message 17 of 21
john.uhden
in reply to: pbejse

She's not that kind of a Russian gal.  She's over 60 and I really can't understand what she is trying to say.  Yeah, I know, 60 is like a kid to me, but she still doesn't qualify.  I'll look at your secret code another time.

John F. Uhden

Message 18 of 21
alanjt_
in reply to: pbejse

That was fun.

 

(defun nokiaDays1 (message)
  ((lambda (keyPad)
     (apply 'strcat (mapcar (function (lambda (x) (nth (cadr x) (assoc (car x) keyPad)))) message))
   )
    '((2 "A" "B" "C")
      (3 "D" "E" "F")
      (4 "G" "H" "I")
      (5 "J" "K" "L")
      (6 "M" "N" "O")
      (7 "P" "Q" "R" "S")
      (8 "T" "U" "V")
      (9 "W" "X" "Y" "Z")
      (0 " ")
     )
  )
)
(defun nokiaDays2 (message)
  ((lambda (keyPad)
     (apply 'strcat (mapcar (function (lambda (x) (nth (length x) (assoc (car x) keyPad)))) message))
   )
    '((2 "A" "B" "C")
      (3 "D" "E" "F")
      (4 "G" "H" "I")
      (5 "J" "K" "L")
      (6 "M" "N" "O")
      (7 "P" "Q" "R" "S")
      (8 "T" "U" "V")
      (9 "W" "X" "Y" "Z")
      (0 " ")
     )
  )
)
Message 19 of 21
alanjt_
in reply to: john.uhden

BTW, John, my introduction to CAD was drawing surveys for my Dad.

They were running AutoCAD 14 with Cadvantage (CPlus?) loaded. Great piece of software.

Message 20 of 21
john.uhden
in reply to: alanjt_

Thanks for the compliment.  What was the name of the company for whom you worked?  Where were they located?  I don't understand "CPlus."

John F. Uhden

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report