Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
Karol-Or
Posts: 265
Registered: ‎11-28-2011
Message 1 of 9 (489 Views)

How to retrieve the SSGET output

489 Views, 8 Replies
01-09-2013 03:34 AM

I am a novice to AutolIsp.

I try to use the SSGET function, and it returnes a string.

How to access the data?

Which function to use?

*Expert Elite*
pbejse
Posts: 2,511
Registered: ‎11-24-2009
Message 2 of 9 (485 Views)

Re: How to retrieve the SSGET output

01-09-2013 03:43 AM in reply to: Karol-Or

Karol-Or wrote:

I am a novice to AutolIsp.

I try to use the SSGET function, and it returnes a string.

How to access the data?

Which function to use?


The SSGET function returns a PICKSET. to access the info from there you need SSNAME Pickset Index number and in return SSNAME will give you ENAME . and to access the data from the ename you use ENTGET

 

Example <one of the many approach>

(setq index 0);<----- indexed at 0 
(Setq selectionset (ssget))
(repeat (sslength selectionset)
(setq Data (ssname selectionset index)):<-- wherein 0 is the first element on the selectionset
(setq EntityData (entget DATA)):<---- Entity properties data
(print EntityData)
(setq index (1+ index))):<--- increment index number for next loop

 

HTH

 

Also i would advice you to read SSGET on autocad help file <F1>  under "Developers ..." [cant remember what that is :smileyvery-happy: .... ]

 

see attached file: [ssget.txt] 

 

Active Member
jpucilow
Posts: 8
Registered: ‎11-12-2003
Message 3 of 9 (471 Views)

Re: How to retrieve the SSGET output

01-09-2013 04:12 AM in reply to: Karol-Or

ssget returns a list of entity names. You step thru the list and process each entity as required. This example the user makes a selection and all but lines are filtered out. It then checks for an empty selectsion set, and if the set is not empty it processes the set:

 

(setq ss (ssget (list (cons 0 "LINE"))))  ;useer selects entities, everything is filtered out except lines

 

;is the set nil? If so, don't process the set

 

(if (not ss)           ;check for nil selection set
   (progn
     (alert "No lines in selection set.")
     (exit)
    )
 )

 

;process each entity in the set

 

(setq i 0)                                   ;ss counter

 

(repeat (sslength ss)            ;loop for every entity in the set
  (setq en (ssname ss i))       ;get entity name
  (setq ed (entget en))           ;get entity definition

   ... do processing here ...
  (setq i (+ i 1))                       ;increment the counter

)

 

The entities in ss are numbered stariting with 0. So if ss contains 3 entities, they'll be numbered 0, 1, 2.

 

Valued Mentor
stevor
Posts: 891
Registered: ‎12-26-2005
Message 4 of 9 (452 Views)

Re: How to retrieve the SSGET output

01-09-2013 09:34 AM in reply to: Karol-Or

And you can use those posted methods to put the ENAMEs into a list, which is handy.

 

S
*Expert Elite*
Kent1Cooper
Posts: 5,871
Registered: ‎09-13-2004
Message 5 of 9 (444 Views)

Re: How to retrieve the SSGET output

01-09-2013 10:10 AM in reply to: Karol-Or

Karol-Or wrote:

....

I try to use the SSGET function, and it returnes a string.

How to access the data?

Which function to use?


That depends on what you want to do with what has been selected.  To expand on and/or clarify some things in others' replies....

 

The reply from jpucilow said that (ssget) "returns a list of entity names."  That's not correct -- it returns a selection set [that's what the "ss" in (ssget) stands for], which is a kind of "collection" of entities, but is not the same as a "list," which has a very specific [and different] meaning in AutoLISP.  As stevor said, a selection set can be converted into a list of entity names, which makes it easier to do certain things to what's in it, for instance using (foreach) instead of stepping through with (ssname).

 

Both pbejse and jpucilow talked about stepping through the entities in a selection set, whether to get information from them or to process them in some way, but there are many things you can do to what's in one without stepping through it, and/or without converting it to a list of entity names.  For instance, you can give a selection set to most editing commands [e.g. Erase, Move, Copy, Rotate, Scale, Chprop, etc., though Explode is complicated] directly in answer to an object-selection prompt, if you want to do the same thing to all of the entities in the set.

Kent Cooper
Active Member
jpucilow
Posts: 8
Registered: ‎11-12-2003
Message 6 of 9 (442 Views)

Re: How to retrieve the SSGET output

01-09-2013 10:31 AM in reply to: Karol-Or

The previous reply is correct. A selection set, strictly speaking, is not a list. Hence, you cannot use list processing fuctiions on a selection set (cons, car, cdr, etc.). Your original question sounded like you wanted perform some type of process on each entity in the ss. If not, as the other poster said, you can pass it to a command that uses selection sets. Very simple example, no error checking, but you get the idea:

 

(setq ss (ssget))  ;pick something

 

(command "erase" ss "")

Distinguished Contributor
Karol-Or
Posts: 265
Registered: ‎11-28-2011
Message 7 of 9 (434 Views)

Re: How to retrieve the SSGET output

01-09-2013 12:23 PM in reply to: Kent1Cooper

Thanks, and, how do i convert a selection set to a list?

*Expert Elite*
Kent1Cooper
Posts: 5,871
Registered: ‎09-13-2004
Message 8 of 9 (428 Views)

Re: How to retrieve the SSGET output

01-09-2013 01:51 PM in reply to: Karol-Or

Karol-Or wrote:

Thanks, and, how do i convert a selection set to a list?


Even that depends, on how the selection set was acquired.  Generally you can use (ssnamex) on the selection set, and take the entity names out of what it returns, but that's what varies depending on how you got the set.

 

If it's a set that looked at the whole drawing to find things, then the entity name will always be in the same position in what (ssnamex) returns for each object, and you can do something like this example that finds all Circles:

 

(setq

  ss (ssget "_X" '((0 . "CIRCLE")))

  CircleList (mapcar 'cadr (ssnamex ss))

); setq

 

Then the CircleList variable will contain a list of the entity names of all the Circles, and you can do something to each of them with (foreach), or move through the list with (nth), or do other list-based operations.

 

But if (ssget) called for User selection, the nature of the return from (ssnamex) varies with the selection method [pick, window, fence, etc.] for each object.  Here's one way to get a list of entity names out of it [general idea by SomeBuddy from a few years back]:

 

(setq

  ss (ssget)

  EntList (vl-remove-if '(lambda (x) (listp x)) (mapcar 'cadr (ssnamex ss)))

); setq

 

You could also do something like this, and not care how things were selected, because it's without the use of (ssnamex), stepping through and adding each entity name to the list as it goes:

 

(repeat (sslength ss)

  (setq EntList (cons (ssname ss 0) EntList)); put first object's entity name in list

  (ssdel (ssname ss 0) ss); remove that object from set

); repeat

 

But don't do it that way if you are still going to want the selection set whole for something else afterwards.  If so, use an incrementer and count through, without removing each object from the set as you go, e.g.:

 

(setq inc 0)

(repeat (sslength ss)

  (setq

     EntList (cons (ssname ss inc) EntList); put object's entity name in list

     inc (1+ inc); change incrementer to look at next object

  ); setq

); repeat

Kent Cooper
*Expert Elite*
pbejse
Posts: 2,511
Registered: ‎11-24-2009
Message 9 of 9 (403 Views)

Re: How to retrieve the SSGET output

01-10-2013 02:41 AM in reply to: Karol-Or

Karol-Or wrote:

how do i convert a selection set to a list?


How's about telling us what you're planning to do with the selection Karol-Or.

 

I believe your question was:

 

<<< How to access the data? Which function to use? >>>

 

If you mean "use" the data from SSGET selection, you can do that on the fly even without assigning a variable name especially if you need to filter the objects to be selected, like how Kent describe it on his post

 

But you wrote ACCESS the data, then 

 

ssname/entget 

 

ssnamex is cool too. but its slow compared to other methods

 

Anyhoo. Holler if you need help more help or info.

 

Cheers

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.