Manuel_Kunde Posted August 27, 2021 Posted August 27, 2021 Hi all, I want to create a simple request whether a layout named "Floor" is there or not. What am I doing wrong here? In the layoutlist all named layouts are listed. I have defined them as variables and query them with wcmatch. Can someone explain? (vl-load-com) (defun c:request () (setq lay_tab (layoutlist)) (if (wcmatch lay_tab "*Floor*") (alert "Layout ist created") (alert "Layout is not created") ) ) Quote
Manuel_Kunde Posted August 27, 2021 Author Posted August 27, 2021 1 hour ago, Steven P said: Is layoutlist a list or a string? The lisp command. It returns a list of all layouts in the current drawing ("Layout1") ("Layout2") .. Quote
Jonathan Handojo Posted August 27, 2021 Posted August 27, 2021 As you said, 'lay_tab' is a list, not a string. wcmatch accepts a string as an argument. You would need to iterate through every item in the list. This should do it (untested). (defun c:request () (if (vl-some (function (lambda (a) (wcmatch a "*Floor*") ) ) (layoutlist) ) (alert "Layout is present") (alert "Layout is not present") ) ) 2 Quote
Manuel_Kunde Posted August 27, 2021 Author Posted August 27, 2021 9 minutes ago, Jonathan Handojo said: As you said, 'lay_tab' is a list, not a string. wcmatch accepts a string as an argument. You would need to iterate through every item in the list. This should do it (untested). Just what I need, thanks. What does vl-some / function / lambda (a) mean in this context? Quote
Jonathan Handojo Posted August 27, 2021 Posted August 27, 2021 1 minute ago, Manuel_Kunde said: Just what I need, thanks. What does vl-some / function / lambda (a) mean in this context? vl-some takes in a list of items and passes every item inside that list into a function (which is defined by lambda). After which, vl-some will return the first evaluation from the list that successfully results to any non-nil value. In the above, 'a' represents each string in the list (which are your layout names). If the first layout doesn't have "Floor", wcmatch returns nil and thus the function returns nil. Therefore, the next item from the list will be processed, and this continues until the function manages to return any non-nil value. Quote
Manuel_Kunde Posted August 27, 2021 Author Posted August 27, 2021 25 minutes ago, Jonathan Handojo said: vl-some takes in a list of items and passes every item inside that list into a function (which is defined by lambda). After which, vl-some will return the first evaluation from the list that successfully results to any non-nil value. In the above, 'a' represents each string in the list (which are your layout names). If the first layout doesn't have "Floor", wcmatch returns nil and thus the function returns nil. Therefore, the next item from the list will be processed, and this continues until the function manages to return any non-nil value. This is much better explained than on AutodeskHELP. Thanks Quote
tombu Posted August 27, 2021 Posted August 27, 2021 Or just (defun c:request () (setq lay_tab (layoutlist)) (if (member "Floor" lay_tab) (alert "Layout ist created") (alert "Layout is not created") ) ) 1 1 Quote
mhupp Posted August 27, 2021 Posted August 27, 2021 (edited) Another way, this is case sensitive. (defun C:foo (/ layexists) (vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))) (if (vl-string-search "Floor" (vla-get-name lay)) (setq layexists lay) ) ) (if (= layexists nil) (alert "\nLayout \"Floor\" missing") (alert "\nFloor layout in Drawing") ) (princ) ) Edited August 27, 2021 by mhupp missed the wildcards in the original post. 1 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.