Jump to content
lido

Select all entities in working space

Recommended Posts

lido

Hello all.

I try to create a selection set to include all objects of the current working space.

Using vanilla (Variant 1) the snippet is very slow for a dwg with dozens of layers and thousands of objects.

With VLisp (Variant 2) is an improvement in speed but Is not enough because I filter the selection in 2 steps.

All that I need is to apply the filter selection in one step, by modifying the correct way to set the arguments of vlax-safearray-fill function (F_VALE variable).

;;Variant 1;;;;;;;;;;;;;;;Vanilla;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq ACDC	(vla-get-activedocument (vlax-get-acad-object))
	CTAB	(getvar "CTAB")
)
(vlax-for
	Obj
	(vla-get-layers ACDC)
		(if (and ;;Filter out objects on locked, frozen and off layers
				(eq (vla-get-lock    Obj) :vlax-false)
				(eq (vla-get-freeze  Obj) :vlax-false)
				(eq (vla-get-layeron Obj) :vlax-true)
			)
			(setq L_FILTER (append (list (cons 8 (vla-get-name Obj))) L_FILTER))
		)
)
(sslength
(ssget "X"
	(list
		(cons -4 "<and")
		(cons 410 CTAB)
		(cons -4 "<or")
		L_FILTER
		(cons -4 "or>")
		(cons -4 "and>")
	)
)
)
(setq SS_ALLO (vla-get-activeselectionset ACDC)
;;Variant 2 ;;;;;;;;;;;;;;;VLisp;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq ACDC		(vla-get-activedocument (vlax-get-acad-object))
		CTAB	(getvar "CTAB")
		SS_ALLO	(vla-add (vla-get-selectionsets ACDC) (itoa (getvar "MILLISECS")))
		F_CODE	(vlax-make-safearray vlax-vbinteger (quote (0 . 1)))
		F_VALE	(vlax-make-safearray vlax-vbvariant (quote (0 . 1)))
)
(vlax-safearray-fill F_CODE (quote (8 410)))
(vlax-for
	Obj
	(vla-get-layers ACDC)
	(if (and ;;Filter out objects on locked, frozen and off layers
			(eq (vla-get-lock    Obj) :vlax-false)
			(eq (vla-get-freeze  Obj) :vlax-false)
			(eq (vla-get-layeron Obj) :vlax-true)
		)
		(progn
			(vlax-safearray-fill F_VALE  (list (vla-get-name Obj) CTAB))
			(vla-select SS_ALLO acSelectionSetAll nil nil F_CODE F_VALE)
		)
	)
)

 

Share this post


Link to post
Share on other sites
Lee Mac

Rather than applying a 'positive' layer filter which includes all layers which are turned on, thawed, and unlocked in a drawing (which is likely to comprise of many layers), I would instead suggest applying a 'negative' layer filter to exclude those layers which are turned off, frozen, or locked (which is likely to comprise of fewer layers).

 

The following example code also accounts for viewing Modelspace through an active Paperspace viewport, and accounts for wildcard operators (such as "#") present in layer & layout names:

(defun c:sa ( / l s x )
    (while (setq x (tblnext "layer" (not x)))
        (if
            (or
                (< 0 (logand 5 (cdr (assoc 70 x))))
                (minusp (cdr (assoc 62 x)))
            )
            (setq l (cons (cons 8 (LM:escapewildcards (cdr (assoc 2 x)))) l))
        )
    )
    (if
        (setq s
            (ssget "_X"
                (cons
                    (if (= 1 (getvar 'cvport))
                        (cons 410 (LM:escapewildcards (getvar 'ctab)))
                       '(410 . "Model")
                    )
                    (if l (append '((-4 . "<NOT") (-4 . "<OR")) l '((-4 . "OR>") (-4 . "NOT>"))))
                )
            )
        )
        (sssetfirst nil s)
    )
    (princ)
)

;; Escape Wildcards  -  Lee Mac
;; Escapes wildcard special characters in a supplied string

(defun LM:escapewildcards ( str )
    (vl-list->string
        (apply 'append
            (mapcar
               '(lambda ( c )
                    (if (member c '(35 64 46 42 63 126 91 93 45 44))
                        (list 96 c)
                        (list c)
                    )
                )
                (vl-string->list str)
            )
        )
    )
)

(princ)

The above uses my Escape Wildcards function.

  • Like 1

Share this post


Link to post
Share on other sites
lido

@Lee Mac

A solution in the unmistakable Lee Mac style.
I fully agree with your approach and the observations made.

Thank you very much.

Share this post


Link to post
Share on other sites
Lee Mac
3 hours ago, lido said:

A solution in the unmistakable Lee Mac style.
I fully agree with your approach and the observations made.

Thank you very much.

 

Thank you @lido :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×