Select blocks by attribute range

Select blocks by attribute range

yu85.info
Collaborator Collaborator
1,507 Views
10 Replies
Message 1 of 11

Select blocks by attribute range

yu85.info
Collaborator
Collaborator

Hello, I have a file (attached) with many blocks. I need to select some of them by a range of a specific attribute (POINT). For exemple 36-56.

Is there a simple way to do this?

Thanks in advance.

0 Likes
Accepted solutions (1)
1,508 Views
10 Replies
Replies (10)
Message 2 of 11

pbejse
Mentor
Mentor
Accepted solution

@yu85.info wrote:

Hello, I have a file (attached) with many blocks. I need to select some of them by a range of a specific attribute (POINT). For exemple 36-56.

Is there a simple way to do this?

Thanks in advance.


 

 

(defun c:range ( / ss rl rh range data f numresult i)
       (if (and
	     (setq rl (getint "\nEnter Range (low): "))
	     (setq rh (getint "\nEnter Range (high): "))
	     (setq result (ssadd)
		  ss (ssget "_x" '((0 . "INSERT")(66 . 1))))
	     )
	 (progn
	   (setq range (vl-sort  (list rl rh) '<));<-- because some user are really strubborn
	(repeat (setq i (sslength ss))
	  (setq data (mapcar '(lambda (at)
				(cons (vla-get-tagstring at)(vla-get-textstring at)))
				(Vlax-invoke (vlax-ename->vla-object (ssname ss (Setq i (1- i)))) 'GetAttributes)))
	  (and
		(setq f (assoc "POINT" data))
		(numberp (setq num (read (cdr f))))
		(<= (Car range) num (cadr range))
	    	(ssadd (ssname ss i)  result)
		)
	  )
	   )
	 )
  (sssetfirst nil result)
  )

 

 

HTH

Message 3 of 11

yu85.info
Collaborator
Collaborator
Thank you very much for your help. I have another question please. If the
name of the block Is A1 and the attribute is POINT, which line in the lisp
I need to change.
Thank you again friend
0 Likes
Message 4 of 11

pbejse
Mentor
Mentor

@yu85.info wrote:
Thank you very much for your help. I have another question please. If the
name of the block Is A1 and the attribute is POINT, which line in the lisp
I need to change.
Thank you again friend

You can remove this [ highlighted in blue ]

(ssget "_x" '((0 . "INSERT")(2 . "POINT")(66 . 1))))

 So it works in any block as long as "POINT" tag is found

 

HTH

 

0 Likes
Message 5 of 11

yu85.info
Collaborator
Collaborator
I must done something wrong. This what I inserted but is seems something is
wrong:
(defun c:range ( / ss rl rh range data f numresult i)
(if (and
(setq rl (getint "\nEnter Range (low): "))
(setq rh (getint "\nEnter Range (high): "))
(setq result (ssadd)
ss
)
(progn
(setq range (vl-sort (list rl rh) '<));<-- because some user are really
strubborn
(repeat (setq i (sslength ss))
(setq data (mapcar '(lambda (at)
(cons (vla-get-tagstring at)(vla-get-textstring at)))
(Vlax-invoke (vlax-ename->vla-object (ssname ss (Setq i (1- i))))
'GetAttributes)))
(and
(setq f (assoc "POINT" data))
(numberp (setq num (read (cdr f))))
(< (Car range) num (cadr range))
(ssadd (ssname ss i) result)
)
)
)
)
(sssetfirst nil result)
)
0 Likes
Message 6 of 11

pbejse
Mentor
Mentor

@yu85.info wrote:
I must done something wrong. This what I inserted but is seems something is
wrong:


Not the whole line but only this (2 . "POINT")

Anyway, i updated the code at post # 2

 

HTH

 

0 Likes
Message 7 of 11

yu85.info
Collaborator
Collaborator
Perfect. Works greate!
LOL
I am a stubborn user 🙂
Thank you!
0 Likes
Message 8 of 11

pbejse
Mentor
Mentor

@yu85.info wrote:
Perfect. Works greate!
LOL
I am a stubborn user 🙂
Thank you!

 

Well there you go. You are welcome.

Not stubborn, confuse thats all 😉

 

0 Likes
Message 9 of 11

tauzer_t
Explorer
Explorer

This lisp it also suits my needs..but is there easy way to take into account numbers with a suffix ?! Some numbers in the range has a letter in suffix usually letters X and Y.. tia

0 Likes
Message 10 of 11

pbejse
Mentor
Mentor

@tauzer_t wrote:

This lisp it also suits my needs..but is there easy way to take into account numbers with a suffix ?! Some numbers in the range has a letter in suffix usually letters X and Y.. tia


Sure we can, change this

 

(numberp (setq num (read (cdr f))))

 

to

 

(setq num (atoi (cdr f)))

 

HTH

 

Message 11 of 11

vladimir_michl
Advisor
Advisor

For an example of a complete app, see the SelByAttr freeware tool at:

https://www.cadforum.cz/en/how-to-select-blocks-by-attribute-values-selbyattr-tip13337

 

Vladimir Michl, www.arkance-systems.cz - www.cadforum.cz

 

[video]

 

 

 

0 Likes