Jump to content

Recommended Posts

Posted

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

 

Posted
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") ..

Posted

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

 

  • Like 2
Posted
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?

Posted
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.

Posted
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 👍

Posted

Or just

(defun c:request ()
  (setq lay_tab (layoutlist))
  (if (member "Floor" lay_tab)
    	(alert "Layout ist created")
    		(alert "Layout is not created")
  	)
)

 

  • Like 1
  • Agree 1
Posted (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 by mhupp
missed the wildcards in the original post.
  • Like 1

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