Jump to content

Recommended Posts

Posted

Hello to all.

In the program through the function I choose the polyline:

(defun Select1obj (objName msg)
  (while
    (not
      (and
	(setq ent (car (entsel msg)))
	(if ent (wcmatch (cdr (assoc 0 (entget ent))) objName) ) ) )
    (princ "\nSelect Again: ")    )
  ent  
)

Like this: 

(setq pick (Select1obj "LWPOLYLINE" "\nSelect polyline number 1 ->>"))

But in the program I have to choose another polyline (or there may not be one). Now it looks like this:

(setq ssEle (ssget (list (cons 0 "LWPOLYLINE"))))

Please tell me how to do the following:

I select the first polyline through the function "Select1obj", then if i don't select another polyline through function "ssget", then the variable "ssEle" is assigned 

the polyline I selected through the function  "Select1obj" (programmatically, without re-selection in the drawing).

Thanks to everyone who will help me!

Posted

When using ssget you make a selection set with at least 1 item, you use (sslength ss) to find out how many items, (ssname ss x) where x is the item number to be retrieved. Normally used with a repeat.

 

You can also do a SSADD which adds items so you could keep doing entsel and add more items to a selection set.

  • Like 1
Posted (edited)
1 hour ago, BIGAL said:

When using ssget you make a selection set with at least 1 item, you use (sslength ss) to find out how many items, (ssname ss x) where x is the item number to be retrieved. Normally used with a repeat.

 

You can also do a SSADD which adds items so you could keep doing entsel and add more items to a selection set.

Thank you very much, this is what I need!

I did it like this:

  (setq pick (Select1obj "LWPOLYLINE" "\nSelect polyline number 1 ->>"))
  (setq ssEle (ssget (list (cons 0 "LWPOLYLINE"))))
  (if (not ssEle)
  (setq ssEle (ssadd pick))
  )

 

Edited by dilan
Posted (edited)

Since the and function uses short-circuit evaluation, your select1obj function may be reduced to:

(defun select1obj ( typ msg / ent )
    (while
        (and (setq ent (car (entsel msg)))
             (not (wcmatch (cdr (assoc 0 (entget ent))) typ))
        )
        (princ "\nInvalid object selected, please try again.")
    )
    ent
)

This also allows the user to dismiss the prompt in order to exit the function (with the function returning nil), without having to force an error by pressing Esc.

 

You might also want to consider the following for a filtered single selection:

(ssget "_+.:E:S" '((0 . "LWPOLYLINE")))

 

Edited by Lee Mac
  • 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...