get block values by "Y" coordinate

get block values by "Y" coordinate

aliozcicek
Contributor Contributor
956 Views
9 Replies
Message 1 of 10

get block values by "Y" coordinate

aliozcicek
Contributor
Contributor

hi everyone,

 

I try to get some value from block and I want to creat a text with this values. but I want to sort it. I mean top block (by the y coordinate must be first). if there is 5 block I will create 5 text. I am done with values from blocks but cant solved sorting issue. will be great if can help.

 

thanks in advance.

 

soru.jpg

0 Likes
957 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

@aliozcicek wrote:

....

I try to get some value from block and I want to creat a text with this values. but I want to sort it. I mean top block (by the y coordinate must be first). ....


You should be able to use BlockSSSort.lsp, available >here<.  It stands for "Block Selection Set Sort." Given a selection of Blocks, it will sort them into a list of entity names in the directional order you specify of the insertion points.  Note that it doesn't define a command, but a function that takes arguments -- see the Usage example in the comments at the top [and you must include the parentheses].  If yours are all at different Y-coordinate values, then there will be only rows, and no columns, so whether you ask for left-to-right or right-to-left in the rows won't make any difference -- either (bsss "t" "l") or (bsss "t" "r") would give you the list with the uppermost Block's entity name first.

Kent Cooper, AIA
0 Likes
Message 3 of 10

aliozcicek
Contributor
Contributor

hi Kent1Cooper,

thanks for fast answer. I think I understand your solution and I am working on it.  I will write when I done or if I fail... 

 

 

 

0 Likes
Message 4 of 10

aliozcicek
Contributor
Contributor

Hi Kent1Cooper,

your codes give me a entity name list. this is good I can use it. I try to get it with this

"(setq blist (bsss "t" "l"))"

and I will use entity names one by one. in first try codes turn,

"(<Entity name: 7fffe0872b0> <Entity name: 7fffe087180> <Entity name: 7fffe087040> <Entity name: 7fffe088ea0> <Entity name: 7fffe0873d0>)"

but when I try second time it turns,

"error: bad argument type: consp <Entity name: 7fffe0872b0>"...

 

I couldn't understand why... 

 

0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

@aliozcicek wrote:

.... when I try second time it turns, "error: .... 


That's because the 'blsort2' variable is [intentionally] not localized -- see Message 19 on that same thread.  Do this:

(setq blsort2 nil)

 

and try it again.

Kent Cooper, AIA
0 Likes
Message 6 of 10

aliozcicek
Contributor
Contributor

hi again,

I got the point. but now I have another problem. 

(setq blist (bsss "t" "l")) this code forced me to make selection. I want use it in loop. many beams I have. I must use my selection set for each beam. 

maybe I couldn't explain my aim good. as you see there is a rectangle around blocks. I want to use this rectangle object in my loop and I want to creat texts in the rectangle with values which taken from blocks. and I want to sort it by block's Y coordinate values. maybe I go to wrong way. 

 

thanks for your patience...soru.jpg

0 Likes
Message 7 of 10

Kent1Cooper
Consultant
Consultant

I'll assume the rectangle is a Polyline, and those Blocks are either the only Blocks in it or have some distinction from any other Blocks [such as the Layer they're on, or their Block names].  The routine can be altered [I suggest making a separate file, ideally with a different function name, dedicated to this specific usage] to take a selection set other than by the User -- change this line:

 

  (setq bss (ssget '((0 . "INSERT")))); = Block Selection Set by user

 

to this:

  (setq bss

    (ssget "_W" (vlax-curve-getStartPoint pl) (vlax-curve-getPointAtParam pl 2) '((0 . "INSERT")))

  )

 

[Add other things to the filter list to narrow down what it finds, if appropriate.]

 

Than you can select any number of Polyline rectangles, put into a selection set [here, 'ss'], and step through it:

(repeat (setq n (sslength ss))

  (setq pl (ssname ss (setq n (1- n)))

  (setq blist (bsss "t" "l"))

  … do whatever with the resulting list ...

); repeat

 

 

Kent Cooper, AIA
Message 8 of 10

aliozcicek
Contributor
Contributor

Hi Kent1Cooper,

 

probably you gave me all right. just I couldn't focus on this direction. I will try them as soon as possible. now I keep going with this.

 

(repeat (sslength donlist)
(setq ename (ssname donlist i))
(setq xp (car (cdr (cdr (assoc 10 (entget ename))))))
(setq lst (cons (cons xp ename) lst))
(setq sym (read (strcat "E" (itoa (setq i (1+ i))))))
(setq symlst (cons sym symlst))
)
(setq genlist
(mapcar 'set (reverse symlst)
(mapcar 'cdr
(vl-sort lst '(lambda (x y) (> (car x) (car y))))
))
)

 

this helped me to sort all block by y yoordinate.  but after I work enough I will check your solutions. I am sure they will work better. 

 

I appreciate that you help

0 Likes
Message 9 of 10

pbejse
Mentor
Mentor

Do you really need the list of symbol names E#  ( symlst) ? I do not see a need for that as the first element of genlist will eventually be E1 and so forth.

 

Also no need to retrieve the Y value within the  repeat  function as you can do that inside vl-sort predicate function.

 You can shorten the  code

(repeat	(setq i (sslength donlist))
  	(setq lst (Cons
		    (ssname donlist (setq i (1- i)))  lst)))
(setq genlist
	(vl-sort
	  lst
	  '(lambda (x y)
	     (<	(Caddr (assoc 10 (entget x)))
		(Caddr (assoc 10 (entget y)))
	     )
	   )
	)
      )

or 

(setq genlist
	(vl-sort
	  (vl-remove-if 'listp (mapcar 'cadr (ssnamex donlist)))
	  '(lambda (x y)
	     (<	(Caddr (assoc 10 (entget x)))
		(Caddr (assoc 10 (entget y)))
	     )
	   )
	)
      )

 

Also FYI, this 

(car (cdr (cdr (assoc 10 (entget ename)))))

as 

(caddr (assoc 10 (entget ename)))))

HTH

0 Likes
Message 10 of 10

aliozcicek
Contributor
Contributor

thanks for advices. you right I don't need it. I try to delet this line but codes doens't work how I want then. so I left it in lines 🙂 first aim codes which work good. after I improve myself I upgrate them. ( slooowlyyyy... :)) but with your advices I get better faster.... thanks.

0 Likes