supertruper1988 Posted Wednesday at 01:06 PM Posted Wednesday at 01:06 PM Hello, Long time reader and implementer but I have just signed up because I have hit a wall. What I need to do is check to see if any layer that starts with HPF exists and then do some stuff after. Here is what I have tried (if (= (tblsearch "LAYER" "HPF*") nil) (princ "\nTrue.") (princ "\nFalse.") ) I have simplified it down to just testing because I know I can get it to work if I ask for a specific layer name but I need it to be a wildcard if possible. I think instead of a simple test like is this not nil I rather need to test if the list of layers has HPF but my google fu is failing me to find out what that function is called in autolisp. Thanks in advance. Quote
supertruper1988 Posted Wednesday at 01:36 PM Author Posted Wednesday at 01:36 PM After doing some reading, I remembered that ChatGPT exists and could help me. It did and this is the code it gave: (defun c:CheckHPFLayers () (setq found nil) ; Assume no layers are found initially (setq layerTable (tblnext "LAYER" T)) ; Get first layer (while layerTable (if (wcmatch (cdr (assoc 2 layerTable)) "HPF*") ; Check if layer name starts with "HPF" (setq found T) ; Set found to true if a match is found ) (setq layerTable (tblnext "LAYER")) ; Get next layer ) (if found (princ "TRUE\n") ; Print "TRUE" if a layer was found (princ "FALSE\n") ; Print "FALSE" if no layer was found ) (princ) ; Suppress extra return values ) I hope this can help anyone further with a similar issue Quote
Lee Mac Posted Wednesday at 05:21 PM Posted Wednesday at 05:21 PM FWIW, the code can be condensed to: (defun c:checkhpf ( / def fnd ) (while (and (not fnd) (setq def (tblnext "layer" (not def)))) (setq fnd (wcmatch (strcase (cdr (assoc 2 def))) "HPF*")) ) (if fnd (princ "\nLayer found.") (princ "\nLayer not found.") ) (princ) ) 1 Quote
supertruper1988 Posted Wednesday at 06:02 PM Author Posted Wednesday at 06:02 PM On 4/2/2025 at 5:21 PM, Lee Mac said: FWIW, the code can be condensed to: (defun c:checkhpf ( / def fnd ) (while (and (not fnd) (setq def (tblnext "layer" (not def)))) (setq fnd (wcmatch (strcase (cdr (assoc 2 def))) "HPF*")) ) (if fnd (princ "\nLayer found.") (princ "\nLayer not found.") ) (princ) ) Expand Many thanks Lee! 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.