distance selection set

distance selection set

Anonymous
Not applicable
838 Views
4 Replies
Message 1 of 5

distance selection set

Anonymous
Not applicable

How do I create a matched selection set against a previously selected block?
For example, Select block01 and store the attribute value in a variable.
From here I want to select another block that is at most 5m away and write the value stored in my variable.

examples of my attempts.

 

Capt.JPG

;;--------------------- { Get Attribute Value  -  Lee Mac } --------------------;;
;;                                                                              ;;
;;------------------------------------------------------------------------------;;
;;  Autor: Lee Mac                                                              ;;
;;------------------------------------------------------------------------------;;
;;  Argumentos:                                                                 ;;
;;   blk - [vla] VLA Block Reference Object                                     ;;
;;   tag - [str] Attribute TagString                                            ;;
;;------------------------------------------------------------------------------;;

(defun LM:vl-getattributevalue ( blk tag )
  (setq tag (strcase tag))
  (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke blk 'getattributes))
)

;;--------------------- { Set attributevalue  -  Lee Mac- } --------------------;;
;;                                                                              ;;
;;------------------------------------------------------------------------------;;
;;  Autor: Lee Mac                                                              ;;
;;------------------------------------------------------------------------------;;
;;  Argumentos:                                                                 ;;
;;   blk - [vla] VLA Block Reference Object                                     ;;
;;   tag - [str] Attribute TagString                                            ;;
;;   val - [str] Attribute Value                                                ;;
;;------------------------------------------------------------------------------;;


(defun LM:vl-setattributevalue ( blk tag val )
  (setq tag (strcase tag))
    (vl-some '(lambda ( att )(if (= tag (strcase (vla-get-tagstring att))) (progn (vla-put-textstring att val) val)))(vlax-invoke blk 'getattributes))
)

;;------------------------------------------------------------------------------;;


(defun c:TEST (/ ss id iv blk blk2 )
  (setq ss (ssget ":L" '((0 . "INSERT")(66 . 1)))) ;; Select blk 
  (repeat (setq id (sslength ss))
    (setq blk (vlax-ename->vla-object (ssname ss (setq id (1- id)))))
    (setq iv (LM:vl-getattributevalue blk "ATTBLK01"))
    ;; >> Select block within 5m of distance
    (setq blk2 (vlax-ename->vla-object ;|(car (entsel))))|;;;<< I don't know how the selection will be
    (LM:vl-setattributevalue blk "ATTBLK02" blk2)
  )
 (princ) 
)
0 Likes
Accepted solutions (1)
839 Views
4 Replies
Replies (4)
Message 2 of 5

marko_ribar
Advisor
Advisor

Are you sure you are selecting blocks with only source attributes that are to be transfered to near (5m) destination blocks... I suppose you have to filter your selection set better - (66 . 1) and something more specific to source blocks, perhaps layer(s), or color(s), or ... Next selection set could be created separately with destination blocks, but then maybe this is not necessity... All in all, if you select all at once, you have to create 2 groups : sources and destinations from that selection - how? : well, like I said you have to have something specific - some property that makes sources sources and destinations destinations... After that you can iterate through sources and collect only destinations 5m or less away... The rest is simple - put attribs from source to destination(s) attribute(s)...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 3 of 5

Anonymous
Not applicable

I was already aware of this issue (new selection set)

(setq ss (ssget ": L" '((0. "INSERT") (66.1) (8 . "layername") (2 . "blockname"))))

but my main question is:
How to select the block at a maximum distance of 5m from the first selection set?

Thanks for the answer !!

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... From here I want to select another block that is at most 5m away ....

....
(setq blk (vlax-ename->vla-object (ssname ss (setq id (1- id))))) (setq iv (LM:vl-getattributevalue blk "ATTBLK01")) ;; >> Select block within 5m of distance ....

(setq

  ip (vlax-get blk 'insertionpoint)

  ss2 (ssget "_C" (mapcar '+ ip '(5 5)) (mapcar '- ip '(5 5)) '((0 . "INSERT")))

); setq

(if (= (sslength ss2) 1); found only one?

  (setq blk2 (vlax-ename->vla-object (ssname ss2 0))); then -- it's the one you're looking for

  ;;;;; else -- if more than one Block found, decide how to narrow it down -- by name?

); if

 

That assumes your drawing unit is a meter.  If it's a millimeter, replace the 5's with 5000's.

 

That makes a crossing window extending 5 [or 5000] units away from the insertion point  of the starting Block, so that needs to have a meaningful relationship to the Block's contents [such as in the middle, as the Dimension in your image suggests].  If it should be within that distance of any part  of that Block, that can be found, using its bounding box.  If something lies near a corner  of that window, it could be more than  5m from the starting Block by direct measure.  And it finds Blocks with any part  of them touching that window [also suggested by your image].  If it must have its insertion point  within that distance, that would require more figuring.

Kent Cooper, AIA
Message 5 of 5

Anonymous
Not applicable

Exactly!!
I was almost (look at my attempts)

 

(ssget "_X" (list '(0 . "INSERT")(66 . 1)(2 . "Block02") '(-4 . ">=,>=,*") (cons 10 ss) '(-4 . "<=,<=,*") (cons 10 (mapcar '+ ss (list 5.00 5.00 0.0)))))

Thanks!! and apologies for disturbing you again !!

0 Likes