Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Text filter by position

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
Anonymous
1027 Views, 14 Replies

Text filter by position

Hello,

 

i have a very large dwg with data field (a nautical depth chart), which i am trying to simply.

i managed to use object filter out and keep only depth rounded of to .0 and .5 meters

 

is there a way that autocad can select the first and last text in the x-direction for a array of texts ?

this is a small example what i have:

 

its arrays of text values representing the water depth at the giving location.

 

Saltlife212_3-1593432811707.png   

  Saltlife212_0-1593432495278.png      Saltlife212_1-1593432526861.png

  and this is what i am trying to achieve

Saltlife212_2-1593432705034.png

 

is there a way to achieve this by using object text: filter ? or any other tips/methods are welcome.

 

thanks

 

14 REPLIES 14
Message 2 of 15
ВeekeeCZ
in reply to: Anonymous

Some quite simple code could solve it. But post some sample dwg, some small section, to take a look first.

Message 3 of 15
Kent1Cooper
in reply to: Anonymous

An AutoLisp routine could do that.  It would mean selecting all of them, and it would step through and look at the X coordinate of the insertion point of each, comparing it to the least and greatest value found so far, and replacing if the current one is found to be farther in the given direction.  But first:

 

Do all of them have the same justification?

 

What should happen if more than one  share the same left-most or right-most X coordinate?  Are you looking for just that coordinate value, or for a specific Text object, and if the latter, how should it choose among multiples at the same X-wise position?

Kent Cooper, AIA
Message 4 of 15
Anonymous
in reply to: Kent1Cooper

@Kent1Cooper @ВeekeeCZ 

 

i have uploaded a sample part of the file, and yes all of the text's seems to have the same justification.

y was thinking maybe creating a contour with the outer texts might also work.

Saltlife212_0-1593446089230.png

 

my concern is when you have a gap within a row in the x direction. if it could still recognize that.

 

 

Message 5 of 15
ВeekeeCZ
in reply to: Anonymous

What's more interesting is that the texts are slightly off the 90°grid. Is the off-angle the same (or almost) all over the drawing? 

 

Message 6 of 15
Kent1Cooper
in reply to: ВeekeeCZ


@ВeekeeCZ wrote:

... the texts are slightly off the 90°grid. Is the off-angle the same (or almost) all over the drawing? 


That's important if the idea is to select the whole collection at once, because a Y-coordinate check will be needed to group things into rows.  If you're willing to select each row separately, then it's easier, and the differences in Y coordinate don't matter, but....

Kent Cooper, AIA
Message 7 of 15
Anonymous
in reply to: Kent1Cooper

@Kent1Cooper @ВeekeeCZ 

 

yes the whole drawing the texts are in the same offset rotation.

 

i probarly the data is an export from another programs, wich they have the given depth for the given coordinate

 

and this has than bin imported to the autocad geometry of the area

 

Coordinate                          depth

 

Saltlife212_0-1593451275082.png

selecting it all at once would be nice, but if autocad cant complile all the info at once we have to look into another possible.

Message 8 of 15
ВeekeeCZ
in reply to: Anonymous

Have a code that works nice but lost internet fcc connection. Not sure if pic helps but here it is.

You need to set UCS first that each text would be at grid 1,1 

Hth

Message 9 of 15
Anonymous
in reply to: ВeekeeCZ

Hi @ВeekeeCZ 

 

what do you mean with the UCS grid 1.1 ?

 

ive tried the code:

 

(defun c:RemoveInnerTexts (/ s p i e p x y l yl s)

(if (setq s (ssget '((0 . "TEXT"))))
(repeat (setq i (sslength s))
(setq e (ssname s (setq i (1- i)))
p (trans (cdr (assoc 11 (entget e))) 0 1)
x (atof (rtos (car p) 2 0))
y (rtos (cadr p) 2 0)
l (if (setq a (assoc y l))
(subst (append a (list (cons x e)))
a l)
(cons (list y (cons x e)) l)))))
(foreach yl l
(setq yl (vl-sort (cdr yl) '(lambda (x1 x2) (< (car x1) (car x2))))
s (list (car yl)))
(foreach x (cdr yl)
(if (equal (- (car x) (car s)) 1. 1.)
(setq s (cons x s))
(progn
(foreach e (cdr (reverse (cdr s)))
(entdel (cdr e)))
(set q s (list x)))))
(foreach e (cdr (reverse (cdr s)))
(entdel (cdr e))))
(princ)
)

 

but i am getting this error: bad argument type....

 

Saltlife212_0-1593502247991.png

 

 

 

Message 10 of 15
ВeekeeCZ
in reply to: Anonymous

You've done a pretty decent job... but two typos in the code. HERE is how to establish UCS.

 

(defun c:RemoveInnerTexts (/ s i e p x y l Yline x-of-Yline s)

  (if (setq s (ssget '((0 . "TEXT"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    p (trans (cdr (assoc 11 (entget e))) 0 1)
	    x (atof (rtos (car p) 2 0))
	    y (rtos (cadr p) 2 0)
	    l (if (setq a (assoc y l))
		(subst (append a (list (cons x e)))
		       a l)
		(cons (list y (cons x e)) l)))))
  (foreach yl l									; y-line list of all xs
    (setq yl (vl-sort (cdr yl) '(lambda (x1 x2) (< (car x1) (car x2))))		; sort y-line items by x
	  s (list (car yl)))							; start 1st section
    (foreach x (cdr yl)								; for each x of y-line
      (if (equal (- (car x) (caar s)) 1. 1.)					; if next is by 1 from previsous
	(setq s (cons x s))							; add x to section
	(progn
	  (foreach e (cdr (reverse (cdr s)))					; else: all inners of previous section
	    (entdel (cdr e)))							;       remove
	  (setq s (list x)))))							;       and start new section
    (foreach e (cdr (reverse (cdr s)))						; last section... all inner items
      (entdel (cdr e))))							;       remove 
  (princ)
  )

 

Message 11 of 15
Anonymous
in reply to: ВeekeeCZ

@ВeekeeCZ 

 

yes it worked, thank you very much!

Message 12 of 15
ВeekeeCZ
in reply to: Anonymous

BTW The routine works just in a horizontal direction.

 

It would not be too much trouble include vertical direction too - the same thing would be applied with switched X-Y coords. Then would be removed just those texts which are inner in both.

Message 13 of 15
Anonymous
in reply to: ВeekeeCZ

hi @ВeekeeCZ 

 

i am reaching out again maybe you have an idea,

the macro you gave me is working good, but still i have a pretty big drawing to compile, and a bit more simplification would be appreciated, if you can help me out.

 

my question,

the current data (depth texts) are now in an array representing 1m distance between each measurement/coordinate.

 

is there a way that i can filter out or run a macro that wil simply the drawing, and remove info that at the end it will be arrays representing 5m ( or even with edit later 10m) ? and then that i can change the text height from 0.20 to a bigger one, to get a better overview ?

 

like this:

(see attached example 2 dwg)

Saltlife212_3-1593704190127.pngSaltlife212_4-1593704203252.png

Saltlife212_5-1593704222634.png

 

 

 

 

i had something like this in mind

Saltlife212_1-1593703234453.png

 

i've attached a example dwg of the original data, maybe you understand at what step it is best to perform each sort of simplification.

 

and this is the filter i am using to isolate the .0 and .5 values

Saltlife212_2-1593703383236.png

 

regards,

 

Message 14 of 15
ВeekeeCZ
in reply to: Anonymous

 

(defun c:RemoveOffGrid (/ s g f i e p)

  (if (and (setq s (ssget '((0 . "TEXT"))))
	   (setq g (cond ((getdist "\nGrid <5.0>: "))
			 (5.0)))
	   (setq f (cond ((getreal "\nFuzz <0.4>:"))
			 (0.4)))
	   )
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    p (trans (cdr (assoc 11 (entget e))) 0 1))
      (if (not (and (equal (rem (car  p) g) 0 f)
		    (equal (rem (cadr p) g) 0 f)))
	(entdel e))))
  (princ)
  )

 

Notes:

- again, adjust UCS same way as before

- considering the scale, UCS goes off with distance. So added fuzz to partially accommodate that. 

- learn about the REM function HERE  The routine removes text if a reminder of Xucs/grid AND Yucs/grid is NOT 0+- fuzz. 

Message 15 of 15
Anonymous
in reply to: ВeekeeCZ

Thanks @ВeekeeCZ 

it seems to be working, i am going to try it out on the main document.

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report