Jump to content

Select all entities in working space


lido

Recommended Posts

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)
		)
	)
)

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...