Jump to content

ENTSEL to cycle through selection set...


lamensterms

Recommended Posts

Hi guys,

 

I'm not even sure I am going about this the right way, but let me try to explain what I'm trying to achieve, and the method I am trying to achieve it.

 

I have a ProSteel command (PS_CREATE_SPEZPART) that I would like to pass each element of a selection set to - one by one. From what I understand, this ProSteel command will accept selections in the form of ENTSEL, but not single item selection sets.

 

So I had a thought to create a selection set, and cycle through it using the REPEAT & SSNAME functions.

 

(defun c:tmi ()
(prompt "\nSelect item:")
(setq ss (ssget))
(setq num (sslength ss))
(setq con 0)
(repeat num  
(setq ent3A (ssname ss con))
(command "PS_CREATE_SPEZPART" ent3A nil)
(setq con (1+ con))
)
)

 

... which does not work.

 

I think what I am struggling with is... SSNAME returns the name of an entity - rather than selects that entity. Is this correct or am I missing something?

 

So my question is, is it possible to pass each element to this ProSteel command, in the same manner as ENTSEL would?

 

Thanks a lot for any help.

Link to comment
Share on other sites

Since entsel returns a list of two items (the selected entity and the center of the cursor pickbox), try something like the following:

(defun c:tmi ( / num sel )
   (prompt "\nSelect item: ")
   (if (setq sel (ssget))
       (repeat (setq num (sslength sel))
           (command "_.PS_CREATE_SPEZPART" 
               (list (ssname sel (setq num (1- num))) '(0 0 0))
           )
       )
   )
   (princ)
)

 

Depending on how the command operates, the point supplied with the entity may need to be located on or near to the object.

Link to comment
Share on other sites

Hi Lee and BigAl,

 

Thanks a lot for your help. You have, once again, nailed it.

 

Lee - your routine works great, I have tested it on a few types and combinations of elements, and it has worked every time. To further my education though, could you please explain the logic/philosophy behind the "(1- num)". I understand it is being used to work through the selection set (being the index for SSNAME). I just can't get my head around "1-"... is it the same as "num - 1" (but in the correct syntax)?

 

Haha, BigAl - Lee sure is quick, thanks for your suggestion.

Link to comment
Share on other sites

Thanks a lot for your help. You have, once again, nailed it.

 

Lee - your routine works great, I have tested it on a few types and combinations of elements, and it has worked every time.

 

Excellent to hear! Thank you lamensterms :)

 

To further my education though, could you please explain the logic/philosophy behind the "(1- num)". I understand it is being used to work through the selection set (being the index for SSNAME). I just can't get my head around "1-"... is it the same as "num - 1" (but in the correct syntax)?

 

Exactly -

 

The 1- & 1+ functions are just convenient & quick functions which simply increment or decrement a given numerical value by one:

(1+ x) is the same as (+ x 1)

(1- x) is the same as (- x 1)

Therefore, my code is iterating over the selection set starting with the entity at the (sslength-1)th position and decrementing the index to zero (since selection set indexes are zero-based). For more information on this topic, you might find my tutorial on Selection Set Processing of interest.

 

It's not actually Lee, he set up a lisp routine to answer questions for him.

 

:lol: :lol: What can I say, LISP was originally intended for developing A.I. ;)

Link to comment
Share on other sites

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