Hello,
I have a drawings that need a variable number of a single block to be selected and put in numerical order for further processing (The blocks are numbered rectangles representing intended viewports).
I tried getting them as a selection set and then exporting them to another selection set in order, but that didn't work. From what I've been reading it won't work, so I'm trying to order them via a vlax safearray. I'm making slightly more progress, but still isn't getting anywhere fast.
I'm wondering if I'm just barking up the wrong tree completely.
I've attached the current (unfinished) code, but the relevant subfunctions are here:
(defun SelectBlocks ( / d name n out Blklst Log1)
(if (setq name "GRIDSHEET_1500" ;;selecting all dynamic blocks of this name
Blklst (ssget "_X" '((0 . "INSERT")))
n -1
LytSS (ssadd)
)
(while (setq Blck (ssname Blklst (setq n (1+ n))))
(if (= :vlax-true (vla-get-IsDynamicBlock (vlax-ename->vla-object Blck)))
(if (= (strcase (vla-get-Effectivename (vlax-ename->vla-object Blck))) (strcase name))
(ssadd Blck LytSS)
)
)
)
)
)
(defun Sortblocks ( / first att i ArryIndx x Lb) ; creating an ordered list from the selected blocks
(setq LytArry (vlax-make-safearray vlax-vbObject '(0 . 50))) ; create array
(setq ArryIndx 0) ; set index 0
;; __________________________________________________it gets this far then errors out
(foreach x LytSS ; looking through the sset for the first value
(setq first (LM:vl-getattributevalue x VTag))
(if (eq first 3) ; if attribute is 3
(setq LytArry (vlax-safearray-put-element LytArry ArryIndx x)) ; make first value in array
(princ)
)
)
(setq ArryIndx 1)
(setq Lb 3)
(while (< ArryIndx (sslength LytSS)) ; while current indexs less than the total length
(foreach i LytSS ; check each block for next attibute value
(setq SL (ssname LytSS ArryIndx))
(setq VSL (vlax-ename->vla-object SL)) ; make each entry a vla object
(setq AVal (LM:vl-getattributevalue VSL VTag)) ; get the sheet number attribute
(if (eq AVal (+ Lb 1)) ; If sheet number is 1 higher than current Lb
(progn
(vlax-safearray-put-element LytArry ArryIndx VSL) ; add the block to the array
(setq ArryIndx (+ ArryIndx 1))
(setq Lb (+ Lb 1))
(alert "added to array")
)
(progn
(alert "not added to array")
)
) ; end if
) ; end foreach
) ;end while
(setq SrtdLst (vlax-safearray->list LytArry)) ; create list from Array
)
I'm currently getting a bad argument type: consp <Selection set: e5> when I try to get the first foreach loop going.
Mostly I'm just wondering this approach will work at all before I sink more time into it.
Thanks,
Gorra