gsc Posted July 8, 2020 Posted July 8, 2020 Hi, I want to List specific existing layer names for viewport freeze. The layer names always start with "29-barge-*" The * is a sequenced number starting at 1. How do I do that? Quote
gsc Posted July 8, 2020 Author Posted July 8, 2020 Thanx, but then I would not post my topic on the Lisp forum Quote
ronjonp Posted July 8, 2020 Posted July 8, 2020 Not sure where this thread is going but are you familiar with layer property filters? 1 Quote
Jonathan Handojo Posted July 8, 2020 Posted July 8, 2020 If you really must use a LISP code, (defun ListLayerByPattern (pat / ly nm rtn) (while (setq ly (tblnext "layer" (null ly))) (if (wcmatch (setq nm (cdr (assoc 2 ly))) pat) (setq rtn (cons nm rtn)) ) ) (reverse rtn) ) so you can call it like: (ListLayerByPattern "29`-barge`-[1-9]*") Or apply a function to every matching layer ;; pat - matching pattern by layer name ;; fnc - function accepting one argument that represents the layer name (defun ApplyToLayerByPattern (pat fnc / ly nm) (while (setq ly (tblnext "layer" (null ly))) (if (wcmatch (setq nm (cdr (assoc 2 ly))) pat) (eval (list fnc nm)) ) ) ) For example, this one freezes all layers of the matching pattern except for the current layer: (defun c:test ( / cur lys) (setq lys (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) cur (getvar 'clayer)) (ApplyToLayerByPattern "29`-barge`-[1-9]*" '(lambda (x) (and (not (wcmatch cur "29`-barge`-[1-9]*")) (vla-put-Freeze (vla-item lys x) :vlax-true) ) ) ) ) 1 Quote
Dadgad Posted July 9, 2020 Posted July 9, 2020 13 hours ago, ronjonp said: Not sure where this thread is going but are you familiar with layer property filters? That is how I'd do it too, and the same suggestion which I made, but later deleted as the OP seemed disinterested in an analog approach. Another analog approach might be to include such layer names, pre-viewport frozen, and Grouped into a filter in the Layer Properties Manager in your customized default QNEW template. Old school. Looks like @Jonathan Handojo has gotten it sorted out though, cool. Quote
gsc Posted July 9, 2020 Author Posted July 9, 2020 11 hours ago, Jonathan Handojo said: If you really must use a LISP code, (defun ListLayerByPattern (pat / ly nm rtn) (while (setq ly (tblnext "layer" (null ly))) (if (wcmatch (setq nm (cdr (assoc 2 ly))) pat) (setq rtn (cons nm rtn)) ) ) (reverse rtn) ) so you can call it like: (ListLayerByPattern "29`-barge`-[1-9]*") Or apply a function to every matching layer ;; pat - matching pattern by layer name ;; fnc - function accepting one argument that represents the layer name (defun ApplyToLayerByPattern (pat fnc / ly nm) (while (setq ly (tblnext "layer" (null ly))) (if (wcmatch (setq nm (cdr (assoc 2 ly))) pat) (eval (list fnc nm)) ) ) ) For example, this one freezes all layers of the matching pattern except for the current layer: (defun c:test ( / cur lys) (setq lys (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) cur (getvar 'clayer)) (ApplyToLayerByPattern "29`-barge`-[1-9]*" '(lambda (x) (and (not (wcmatch cur "29`-barge`-[1-9]*")) (vla-put-Freeze (vla-item lys x) :vlax-true) ) ) ) ) Nice solution man, thanx! I guess the ` in (ListLayerByPattern "29`-barge`-[1-9]*") is an escape character for the dash? The [1-9] numbers (layers) are ascending (not infinite) in number during steps in my main routine. And I actually only want to VP freeze the last 2 numbers (layers 8 and 9 in your example): number 9 in the Viewport on the last Layout number and number 8 in the Viewport of the second to last Layout number. My layout names have numbers like 01, 02, etc. and are also ascending in number I list those Viewports with: (setq vport_1 (ssget "x" (list (cons 0 "VIEWPORT") (cons 410 (nth 0 (reverse (layoutlist))))))) (setq vport_2 (ssget "x" (list (cons 0 "VIEWPORT") (cons 410 (nth 1 (reverse (layoutlist))))))) Quote
Recommended Posts
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.