Jump to content

LISP - select objects of specific type


Vittorio

Recommended Posts

Hello Everybody, this is my first post and I'd like to know a little bit more about the ssget command.

 

I already searched the world wide web for various search keywords, but couldn't find references / lists, especially of the Associative codes and object types.

 

I also read a lot of articles about that command, but most of them use these Associative codes:

http://www.lee-mac.com/ssget.html

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2017/ENU/AutoCAD-AutoLISP/files/GUID-0F37CC5E-1559-4011-B8CF-A3BA0973B2C3-htm.html

http://www.afralisp.net/autolisp/tutorials/selection-sets.php

They

 

Since I am a total newbie with AutoLISP please explain things easily.

 

What I would like to do in the first place is selecting objects via LISP, since there seems to be no command line version of SELECT, QSELECT etc.

 

and therefore I need:

 

  • a list of "names" of object types that exist in AutoLISP (eg. TEXT, LINE, etc)
  • all neccessary parameters for the ssget function

 

 

Let's say I want to select a table in a drawing, how can this be done?

What if there are more than one tables?

 

Many thanks in advance

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • BIGAL

    8

  • Vittorio

    6

  • ronjonp

    3

  • Aftertouch

    3

Welcome to CADTutor Vittorio. :)

 

If you have already studied the documentation for the ssget function as found on my site, or in the Autodesk documentation, then you should already be familiar with the parameters which may be supplied to the function: the mode string argument to determine the type of selection, the point & point list arguments when specifying a selection window/polygon, and the filter list argument to filter the properties of objects which may be selected.

 

Since your question is predominantly asking about the filter list argument and the various entity types which may be filtered, I would first suggest that you refer to a DXF Reference.

 

To understand the entity types available, refer to the ENTITIES section of the reference.

 

For example, for a Table, the DXF reference shows that the entity type (DXF group 0) is "ACAD_TABLE". Therefore, to obtain a selection of all tables in the drawing, you might use:

(ssget "_X" '((0 . "ACAD_TABLE")))

Link to comment
Share on other sites

For example, for a Table, the DXF reference shows that the entity type (DXF group 0) is "ACAD_TABLE".

Therefore, to obtain a selection of all tables in the drawing, you might use:

(ssget "_X" '((0 . "ACAD_TABLE")))

 

I did, but nothing happened. Here's a copy of the ACAD Text Window:

Command: APPLOAD
selectTable.lsp successfully loaded.

Command: SELECTTABLE
<Selection set: 18867>

Command: SELECTTABLE
<Selection set: 1888d>

Command: SELECTTABLE
<Selection set: 1888f>

Command: (ssget "_X" '((0 . "ACAD_TABLE")))
<Selection set: 188ca>

Command: SELECTTABLE
<Selection set: 188d4>

 

here is the LISP selectTable.lsp

(defun c:selectTable nil
 (vl-load-com)
(ssget "_X" '((0 . "ACAD_TABLE")))
)

 

As I already said, I'm a total noob in AutoLISP.

 

 

 

Since your question is predominantly asking about the filter list argument and the various entity types which may be filtered, I would first suggest that you refer to a DXF Reference.

 

To understand the entity types available, refer to the ENTITIES section of the reference.

 

So here is what I am understanding:

 

The ssget syntax as described on your site or at Autodesk Help:

(ssget [mode-string] [pt1 [pt2]] [pt-list] [filter-list])

 

ssget - required

[mode-string] - "_X" (Extended Search - Entire Drawing Database)

[pt1 [pt2]] - "" (Point 1, Point 2, ...) => empty: no points selected

[pt-list] - "" (Point List) => empty: no point list

[filter-list] - here we go... I just don't get this part

 

 

  • Why is the whole thing eclosed in double parentheses?
  • Why is there an apostroph before the first parenthesis?
  • Why is there a dot between the group code and the entity name?
  • What exactly does the "0" stand for? Group Code? There are many 0s in the reference.
  • Is the "0" bound to the entity name? If so, why is there no "0" or entity name for the LINE object?

 

Here is a part of the Reference:

Table group codes:

Group code / Description

0 / Entity name (ACAD_TABLE)

 

Line group codes:

Group code / Description

100 / Subclass marker (AcDbLine)

Link to comment
Share on other sites

A couple more hints you can filter more than one type of entity in one go

 

(ssget "_X" '((0 . "Line,Lwpolyline"))) finds lines and poly lines

(ssget "_X" '((0 . "Text,Mtext")))  finds text and mtext
(ssget "_X" '((0 . "*Text")))  finds text and mtext

(ssget "_X" '((0 . "Insert"))) one that is not obvious this finds blocks.

(ssget "_X" '((0 . "*Text")(8 . "123")))  finds text on layer 123

Link to comment
Share on other sites

I tried and pasted the code into command line, but all that AutoCAD tells me is: "" with XY being an incremented number / letter

 

There is nothing selected after applying (ssget "_X" '((0 . "Line,Lwpolyline"))) for example...

 

How can I actually select objects in AutoLISP?

Link to comment
Share on other sites

At its most simplest (setq SS (ssget)) you then have a selection set of objects. Note the SS this the variable name that is holding our selection of objects. All the above are examples of ssget but we all forgot to save the selection to a variable. In saying that there are situations where you dont need to assign to a variable. Like move copy erase etc.

Link to comment
Share on other sites

Again you need to explain what is it your trying to do, ignore the ssget for the moment do you want to pick objects and do something with them ? Explain what it is you want to do.

 

an example 
(command "Erase" (ssget "X" '((8 . "0"))) "") erase objects on layer "0"

 

(setq ss (ssget "X" '((0 . "TEXT")))) 
(repeat (setq x (sslength ss))
(setq obj (ssname ss x))
... do stuff here like
.... get insertion point
(setq x (+ x 1))
)

Edited by BIGAL
Link to comment
Share on other sites

maybe OP just want to use the select command in combo with ssget?

 

 

 (command "select" ss) 

 

 

But I agree he has to give more info in what he is trying to do...

 

 

gr. Rlx

Link to comment
Share on other sites

An example of selecting all objects on one layer without knowing layer name.

 

(setq ent (entget (car (entsel))))
(setq layname (cdr (assoc 8 ent)))
(setq  ss (ssget "x" (list (cons 8  layname))))
(alert (strcat (rtos (sslength ss) 2 0) " Objects found"))))

Link to comment
Share on other sites

Thanks for all the replies!

 

What I actually want to do ist some batch scripting with a set of input files (eg. drawing001.dwg, drawing002.dwg, drawing003.dwg, etc.)

 

The script may look like this:

 

_.model _.laythw _.layon _.regenall _.zoom e 
[i][color="red"]... some code here (calling the LISP to select the desired objects) ...[/color][/i]
[i][color="green"]... some code here (manipulating the selected objects) ...[/color][/i]
_.save  _.quit  

Link to comment
Share on other sites

Here's how you'd run your code in a script.

_.model _.laythw _.layon _.regenall _.zoom e

(c:nameofyourcodealreadyloaded)

_.save _.quit

Link to comment
Share on other sites

Thanks!

 

The problem is not how to include a LISP in a Script (nevertheless, thanks for the answer how to do it),

but the LISP routine itself

 

What I actually need is a LISP to select objects of a given type.

 

For example, a LISP to select all Tables in a drawing or all Blocks in a drawing or any Polylines... anyway, you get the point

Link to comment
Share on other sites

1st add the starting steps into the lisp makes the script a bit easier

 

open dwg1
(load "myfixuppperlisp")
open dwg2
(load "myfixuppperlisp")
.............

 

; myfixerupper
(defun myfixer ( / ss )
(setvar 'ctab "Model")
(command "_.laythw" "_.layon" "_.regenall" "_.zoom" "e") 
(setq ss (ssget "X" '((0 . "INSERT")))) ; select all block objects
(command "chprop" ss "" "la" "0" "") ; change to layer 0
(command "close" "Y")
)

(myfixer)

Link to comment
Share on other sites

1st add the starting steps into the lisp makes the script a bit easier

 

open dwg1
(load "myfixuppperlisp")
open dwg2
(load "myfixuppperlisp")
.............

 

; myfixerupper
(defun myfixer [color="red"][b]( / ss )[/b][/color]
(setvar [color="red"][b]'ctab "Model"[/b][/color])
(command "_.laythw" "_.layon" "_.regenall" "_.zoom" "e") 
(setq ss (ssget "X" '((0 . "INSERT")))) ; select all block objects
(command "chprop" ss "" "la" "0" "") ; change to layer 0
(command "close" "Y")
)

(myfixer)

 

Thanks!

 

Could you please explain a few things to me? As I already said, I am a LISP newbie with no experience at all :(

 

defun myfixer defines the function, but what does (/ss) exactly do?

And setvar somehow sets a variable, but your syntax differs from the Autodesk KB/Help.

 

Now, let me try:

...
(setq txt (ssget "X" '((0 . "TEXT")))) ; select all single line text objects
(command "_.erase" txt "") ; erase them all!
...

Is that correct?

Link to comment
Share on other sites

Thanks!

 

Could you please explain a few things to me? As I already said, I am a LISP newbie with no experience at all :(

 

defun myfixer defines the function, but what does (/ss) exactly do?

 

Localising Variables

 

 

Now, let me try:

...
(setq txt (ssget "X" '((0 . "TEXT")))) ; select all single line text objects
(command "_.erase" txt "") ; erase them all!
...

Is that correct?

 

Yes.

Link to comment
Share on other sites

You might want to check that there is a selection or your command call will fail:

(if (setq txt (ssget "X" '((0 . "TEXT")))) ; select all single line text objects
 (command "_.erase" txt ""); erase them all!
 (print "No text to erase...")
)

Link to comment
Share on other sites

Good idea ronjonp most of the stuff I do for work expects the user to know what they are doing and pick a text when thats what they are being asked to do. When learning putting in error checking is a very good idea for the sake of 5 characters (if ) something I dont do often enough look at Lee's and Tharwats code always have error checks.

Link to comment
Share on other sites

  • 1 year later...

Is there anyway to select a specific type of 3D solid in a lisp. I am trying to find a way to select spheres that are on different layers and delete them but I can't seem to figure out how to accomplish it.

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