Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to retrieve the SSGET output

8 REPLIES 8
Reply
Message 1 of 9
Karol-Or
4073 Views, 8 Replies

How to retrieve the SSGET output

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?

8 REPLIES 8
Message 2 of 9
pbejse
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 😄 .... ]

 

see attached file: [ssget.txt] 

 

Message 3 of 9
jpucilow
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.

 

Message 4 of 9
stevor
in reply to: Karol-Or

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

 

S
Message 5 of 9
Kent1Cooper
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, AIA
Message 6 of 9
jpucilow
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 "")

Message 7 of 9
Karol-Or
in reply to: Kent1Cooper

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

Message 8 of 9
Kent1Cooper
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, AIA
Message 9 of 9
pbejse
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost