Author Topic: block selection  (Read 2623 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
block selection
« on: July 18, 2016, 01:45:02 PM »
Hi all,..

before making the code...
do you know if there is a easy way to select Blocks an then, tree position by vertical or horizontal selection ?
maybe somehting exist that I don'T know...I hope.  :rolleyes2:

Thank you.
Keep smile...

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: block selection
« Reply #1 on: July 18, 2016, 02:08:22 PM »
select Blocks an then, tree position by vertical or horizontal selection ?

What do you mean by this?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: block selection
« Reply #2 on: July 18, 2016, 04:13:41 PM »
Just to start:
Code: [Select]
; Marc'Antonio Alessi, Italy - http://xoomer.virgilio.it/alessi
;
; Function: ALE_Block_GetInsertByPos
;
; Version 1.00 - 02/05/2008
;
; Arguments:
;   LayNam: Layout name > "Model"
;   LyrNms: Layer names > "Layer1,Layer2*"    or "*" for all - [Wcmatch string]
;   BlkNam: Block  name > "Block001"
;   Prmlst: (Function Coord) > '(> cadr) = find the block with the higher value of Y (of insert point)
;                            > '(<  car) = find the block with the lower  value of X (of insert point)
;
; Return Values: VLA obj
;
; Example:
;   (ALE_Block_GetInsertByPos *AcAcDwg* "Model" "*" "Block001" '(> cadr))
;
; Custom functions: ALE_Utl_GetItem
;
(defun ALE_Block_GetInsertByPos (VlaDoc LayNam LyrNms BlkNam PrmLst / VlaObj LayObj BlkObj TmpCrd LstCrd Ss_Tmp Countr EntNam)
  (if (= ">" (vl-symbol-name (car PrmLst))) (setq LstCrd -1e99) (setq LstCrd 1e99))
  (cond
    ( (not (= 'VLA-OBJECT (type VlaDoc))) )
    ( (and
        (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-ActiveLayer (list VlaDoc)))
        (setq LayObj (ALE_Utl_GetItem (vla-get-layouts VlaDoc) LayNam))
      )
      (vlax-for ObjFor (vla-get-block LayObj)
        (and
          (= (vla-get-objectname ObjFor) "AcDbBlockReference") ; Block Reference (Insert)
          (not (vlax-property-available-p ObjFor 'Path))       ; not Xref - UNICA DIFFERENZA -
          (wcmatch (strcase (vla-get-Layer ObjFor)) (strcase LyrNms))
          (=       (strcase (vla-get-Name  ObjFor)) (strcase BlkNam))
          ( (eval (car PrmLst))
            (setq TmpCrd ((eval (cadr PrmLst)) (safearray-value (vlax-variant-value (vla-get-InsertionPoint ObjFor)))))
            LstCrd
          )
          (setq LstCrd TmpCrd BlkObj ObjFor)
        )
      )
    )
    ( (setq Ss_Tmp (ssget "_X" (list '(0 . "INSERT") (cons 410 LayNam) (cons 8 LyrNms) (cons 2 BlkNam) '(66 . 1))))
      (repeat (setq Countr (sslength Ss_Tmp))
        (and
          (setq VlaObj (vlax-ename->vla-object (setq EntNam (ssname Ss_Tmp (setq Countr (1- Countr))))))
          (not (vlax-property-available-p VlaObj 'Path))       ; not Xref - UNICA DIFFERENZA -
          ( (eval (car PrmLst))
            (setq TmpCrd ((eval (cadr PrmLst)) (safearray-value (vlax-variant-value (vla-get-InsertionPoint VlaObj)))))
            LstCrd
          )
          (setq LstCrd TmpCrd BlkObj VlaObj)
        )
      )
    )   
  )   
  BlkObj 
)
; Function: ALE_Utl_GetItem
;
; Arguments:
;   VlaCol = Collection Object > ex. (vla-get-Layers *AcAcDwg*)
;   KeyNam = String            > "0"
;
; Return Values:
;   VLA-OBJECT or nil if (vla-item) fails
;
; Note:
;   the Item method is case-sensitive when used with the SelectionSets
;   collection it is not case-sensitive for other collections.
;
; Example:
;  (ALE_Utl_GetItem
;    (vla-get-Layers (vla-get-ActiveDocument (vlax-get-Acad-Object)))
;    "0"
;  )
;
(defun ALE_Utl_GetItem (VlaCol KeyNam / VlaObj)
  (vl-catch-all-apply
   '(lambda ( )
      (setq VlaObj (vla-item VlaCol KeyNam))
    )
  )
  VlaObj
)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: block selection
« Reply #3 on: July 19, 2016, 08:21:11 AM »
Gracie Marc Antonio...
I keep this code for reference. :)

however,..it is not exactly what I need...
in fact,...I have to select block via crossing windows and then get an SSGET in order of the specification...Horizontal or Vertical..

Below,..few blocks selected via crossing windows...

Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: block selection
« Reply #4 on: July 19, 2016, 11:06:49 AM »
ok nevermind....;)
I did something..


Code: [Select]
;| Order Block Selection by Andrea Andreetti ;;
;;
parameter: ;;
ssblocks = ssget filter ;;
Xfilter  = T=reverse ;;
Yfilter = T=reverse ;;
|;

;tests
(defun c:t1 ()
(Orderselection (ssget) t T)
  )

(defun c:t2 ()
(Orderselection (ssget) nil T)
  )

(defun c:t3 ()
(Orderselection (ssget) t nil)
  )

(defun c:t4 ()
(Orderselection (ssget) nil nil)
  )

(defun Orderselection (ssblocks Xfilter Yfilter / c10list xcoordinates ycoordinates Newc10list c10list nc10list c10 getent )

(repeat (setq ss# (sslength ssblocks))
  (setq getent (entget (setq getitem (ssname ssblocks (setq ss# (1- ss#))))))
  (setq c10 (cdr (assoc 10 getent)))
(setq xcoordinates (vl-sort (append xcoordinates (list (car c10))) '<))
(setq ycoordinates (vl-sort (append ycoordinates (list (cadr c10))) '>))
(setq c10list (append c10list (list (list getitem c10))))
)

 
(foreach i xcoordinates
  (foreach n c10list
    (if (eq (caadr n) i)
      (progn
(setq c10list (vl-remove n c10list))
(setq nc10list (append (list n) nc10list))
)
      )
    )
  )

(if Xfilter
  (setq c10list (reverse nc10list))
  (setq c10list nc10list)
)
(setq nc10list nil)
 
(foreach i ycoordinates
  (foreach n c10list
    (if (eq (cadadr n) i)
      (progn
(setq c10list (vl-remove n c10list))
(setq nc10list (append (list n) nc10list))
)
      )
    )
  )


(if Yfilter
  (setq c10list (reverse nc10list))
  (setq c10list nc10list)
)
(setq nc10list nil)


;|for test only,..TT block contain 1 attribute.
(setq f 0)
(foreach z (reverse c10list)
  (command "_-insert" "TT" "_NON" (cadr z) "" "" "" (itoa (setq f (1+ f))))
  )
|;
  (princ)
)

« Last Edit: July 19, 2016, 11:10:26 AM by Andrea »
Keep smile...

HandyDandy

  • Guest
Re: block selection
« Reply #5 on: July 23, 2016, 06:05:17 AM »
I don't mean to hijack your post but how did you create these animated image screenshots? They are awesome.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: block selection
« Reply #6 on: July 23, 2016, 08:47:26 AM »
I don't mean to hijack your post but how did you create these animated image screenshots? They are awesome.

I use this, suggested by MP...
https://getsharex.com/
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: block selection
« Reply #7 on: July 24, 2016, 01:31:00 AM »
pretty cool!

ok nevermind....;)
I did something..


Code: [Select]
;| Order Block Selection by Andrea Andreetti ;;
;;
parameter: ;;
ssblocks = ssget filter ;;
Xfilter  = T=reverse ;;
Yfilter = T=reverse ;;
|;

;tests
(defun c:t1 ()
(Orderselection (ssget) t T)
  )

(defun c:t2 ()
(Orderselection (ssget) nil T)
  )

(defun c:t3 ()
(Orderselection (ssget) t nil)
  )

(defun c:t4 ()
(Orderselection (ssget) nil nil)
  )

(defun Orderselection (ssblocks Xfilter Yfilter / c10list xcoordinates ycoordinates Newc10list c10list nc10list c10 getent )

(repeat (setq ss# (sslength ssblocks))
  (setq getent (entget (setq getitem (ssname ssblocks (setq ss# (1- ss#))))))
  (setq c10 (cdr (assoc 10 getent)))
(setq xcoordinates (vl-sort (append xcoordinates (list (car c10))) '<))
(setq ycoordinates (vl-sort (append ycoordinates (list (cadr c10))) '>))
(setq c10list (append c10list (list (list getitem c10))))
)

 
(foreach i xcoordinates
  (foreach n c10list
    (if (eq (caadr n) i)
      (progn
(setq c10list (vl-remove n c10list))
(setq nc10list (append (list n) nc10list))
)
      )
    )
  )

(if Xfilter
  (setq c10list (reverse nc10list))
  (setq c10list nc10list)
)
(setq nc10list nil)
 
(foreach i ycoordinates
  (foreach n c10list
    (if (eq (cadadr n) i)
      (progn
(setq c10list (vl-remove n c10list))
(setq nc10list (append (list n) nc10list))
)
      )
    )
  )


(if Yfilter
  (setq c10list (reverse nc10list))
  (setq c10list nc10list)
)
(setq nc10list nil)


;|for test only,..TT block contain 1 attribute.
(setq f 0)
(foreach z (reverse c10list)
  (command "_-insert" "TT" "_NON" (cadr z) "" "" "" (itoa (setq f (1+ f))))
  )
|;
  (princ)
)