Jump to content

Delete lowest numeric text values out of group


Mitch Leach

Recommended Posts

Hi all, 

I was hoping to get some LISP help with a survey file editing challenge. I have a dwg with multiple groups of numeric text values, alongside corresponding Point Cross blocks, each group having anywhere between 2 to 20 values and crosses. I was hoping to find a LISP routine that I could run that would allow me to;
- select the group of individual text values
- run routine

- routine deletes all but the highest value

And maybe a separate LISP that would allow me to select in the same group the cross blocks and it would delete all but the block with the highest z value. 

 

Basically I have long service string lines, with 2 to 20 survey spot levels taken every 10m or so. I would like to clean up the dwg, showing only the highest block and numeric text value out of each group of shots. The block is only made up of two lines, there is no text. The text is separate and only contains numeric values. 

Any help on this would be greatly appreciated. 

Link to comment
Share on other sites

3 hours ago, Mitch Leach said:

 multiple groups of numeric text values, alongside corresponding Point Cross blocks, each group having anywhere between 2 to 20 values and crosses.

What does it mean "corresponding"? How are associated the block and the text? Are you talking about attributes?

Link to comment
Share on other sites

This will delete all the selected (m)text entities, excepted the one with the biggest number.

(defun c:pp()
  (setq ss (ssget "I" (list '(0 . "*TEXT"))) 
	lst nil)
  (repeat (setq i (sslength ss))
    (setq lst (cons (ssname ss (setq i (1- i))) lst)))
  (setq lst (cdr  (vl-sort lst '(lambda (a b) (> (cdr (assoc 1 (entget a))) (cdr (assoc 1 (entget b))))))))
  (setq ss nil)
  (foreach x lst (entdel x))
  )

 

Link to comment
Share on other sites

fuccaro, thank you so much. That code works perfectly. 
 

You asked about what I meant by "corresponding" blocks. Technically they are unrelated, the only thing matching them is their z value. I received a dwg output from a Survey Calc program, with strings, points and text containing the z values of the points. No blocks and no attributes. Because this file will be used in other programs than AutoCad, I couldn't simply change the point style via PTYPE, so I inserted a simple cross block I made onto all the points via Lee Mac's Point Manager routine. Worked a treat. What I would love to be able to do is the same as what you have done for me with the text code;

- select a group of blocks, anywhere between 2 and 20

- run LISP routine

- routine removes all except the one with the highest z value.

Hope that clears it up.

PS side note, not important for now, but in case I need it in the future. Is it easy to adapt the above code to do the same, but remove the lowest number instead of the highest? 

Thanks again for all your help. With the text routine, I have plenty to already save me loads of time!

  • Like 1
Link to comment
Share on other sites

Thanks for the feedback, I am glad to help!

It is not big deal to change the Lisp, but I will let you to walk alone that route.

The program sorts the texts descending by their values, it removes the first one from the sorted list and it deletes from the drawing the remaining ones. Just sort them ascending to keep only the smallest one. The sort is performed by the (vl-sort...). So in that line, change in the lambda function the ">" sign with "<" and you are done.

Also you can change the program to manipulate blocks. First of all, at the beginning, instruct the ssget to search for blocks (inserts) instead of texts. Replace "*TEXT" with "INSERT".

Next, change the lambda function. Replace the whole line with this one:

 (setq lst (cdr  (vl-sort lst '(lambda (a b) (> (cadddr (assoc 10 (entget a))) (cadddr (assoc 10 (entget b))))))))

It should work...

  • Like 1
Link to comment
Share on other sites

Many thanks fuccaro! 
I haven't tried to change the lamda function to lowest yet, but I did change the code to manipulate the blocks and it works great. I changed the "defun c:pp" to "bd" standing for "Block Delete" and no probs whatsoever. 

Again, thanks for your help on this. 

Link to comment
Share on other sites

1 hour ago, Mitch Leach said:

Many thanks fuccaro!

Let me quote myself:

3 hours ago, fuccaro said:

 I am glad to help!

Congrats for successfully changing the lisp! 

The next challenge: make the two lisps to work at once. Meaning you select only once the blocks and texts, start ONE program and you get deleted all the unneeded texts and blocks.

Link to comment
Share on other sites

On 15/02/2024 at 13:51, fuccaro said:

The next challenge: make the two lisps to work at once. Meaning you select only once the blocks and texts, start ONE program and you get deleted all the unneeded texts and blocks.

Ha, sounds perfect, but might be beyond my programming skills and also the time needed to learn them! It seems too easy to just be a case of copying and pasting one set of code into the same file as the first one??  

Edited by Mitch Leach
Link to comment
Share on other sites

Kind of...

Just copy, paste and... make small changes to fit :)

Are the text and the corresponding block at the same Z value? I mean *really* at the same level, and that level is also the content of the text?

 

Link to comment
Share on other sites

When using the Vl-sort the list is sorted so very first item is (car lst) the last item is just that (last lst) the use of "last" is a hidden talent in lisp programming. So just work with < or > then you have a max min or min max.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...