Vittorio Posted March 4, 2018 Posted March 4, 2018 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 Quote
Lee Mac Posted March 5, 2018 Posted March 5, 2018 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"))) Quote
Vittorio Posted March 5, 2018 Author Posted March 5, 2018 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) Quote
BIGAL Posted March 6, 2018 Posted March 6, 2018 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 Quote
Vittorio Posted March 6, 2018 Author Posted March 6, 2018 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? Quote
BIGAL Posted March 7, 2018 Posted March 7, 2018 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. Quote
Aftertouch Posted March 7, 2018 Posted March 7, 2018 If i understand the question... SSGET create a selection SET If you want to actualy SELECT them.. your looking for the sssetfirst function. Have a look at this: https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-AutoLISP/files/GUID-4076CD9D-1C66-4C73-ACC0-3A6CD0B0D2D8-htm.html Quote
BIGAL Posted March 7, 2018 Posted March 7, 2018 (edited) 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 March 8, 2018 by BIGAL Quote
rlx Posted March 7, 2018 Posted March 7, 2018 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 Quote
BIGAL Posted March 8, 2018 Posted March 8, 2018 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")))) Quote
Vittorio Posted March 14, 2018 Author Posted March 14, 2018 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 Quote
ronjonp Posted March 14, 2018 Posted March 14, 2018 Here's how you'd run your code in a script. _.model _.laythw _.layon _.regenall _.zoom e (c:nameofyourcodealreadyloaded) _.save _.quit Quote
Vittorio Posted March 14, 2018 Author Posted March 14, 2018 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 Quote
BIGAL Posted March 15, 2018 Posted March 15, 2018 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) Quote
Vittorio Posted March 15, 2018 Author Posted March 15, 2018 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? Quote
Grrr Posted March 15, 2018 Posted March 15, 2018 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. Quote
ronjonp Posted March 15, 2018 Posted March 15, 2018 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...") ) Quote
BIGAL Posted March 16, 2018 Posted March 16, 2018 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. Quote
Dfriedel89 Posted September 17, 2019 Posted September 17, 2019 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. Quote
Recommended Posts
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.