YZ Posted March 29, 2016 Share Posted March 29, 2016 I am attempting my first lisp routine today. I have practiced a little with loading in some samples, and reading them. I can follow (somewhat) the syntax. I don't expect any one to do it for me, but I wonder if someone could steer me in the right direction for which command to use. I want a routine that, among other things, can enquire a particular layer and return true or false whether or not that layer is empty. Thanks! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 29, 2016 Share Posted March 29, 2016 I want a routine that, among other things, can enquire a particular layer and return true or false whether or not that layer is empty. Hi, I guess you have started with a bit long codes to check that out if the your would dive into Blocks as well otherwise it is a good start But anyway, here are the steps for you to start coding them: Search for your layer name if it is existed in a drawing. Make a global selection set with the layer name only. If the selection set is not nil , so it is equal to True otherwise it is False. NOTE: the above direction points can not test out if the layer name is used by blocks. Quote Link to comment Share on other sites More sharing options...
YZ Posted March 29, 2016 Author Share Posted March 29, 2016 Thanks Tharwat! I can ignore blocks. How would I make a selection, and target only a certain layer? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 29, 2016 Share Posted March 29, 2016 You need to check out if the layer name is already existed into your drawing. Did you write or know how to code this first ? Quote Link to comment Share on other sites More sharing options...
YZ Posted March 29, 2016 Author Share Posted March 29, 2016 I know that the layer will already exist in the drawing, so that is fine. Although, if it was easier, I could purge the drawing, and then get the lisp to ask if the layer exists. If the layer exists, that is proof enough that it is TRUE that something is on that layer. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 29, 2016 Share Posted March 29, 2016 Okay, To check if a layer "MyLayer" is existed and notice that the name of your layer is a string type. (tblsearch "LAYER" "MyLayer") This should return dxf data that ensure "MyLayer" is already existed otherwise nil which means not found or not existed. After guarantying that our layer "MyLayer" is existed then we make a global selection set filtering for our layer name only. (setq ss (ssget "_X" '((8 . "MyLayer")))) So the above line of codes should return a selection set of object(s) if object(s) found on our layer name "MyLayer" otherwise would return nil. Quote Link to comment Share on other sites More sharing options...
YZ Posted March 29, 2016 Author Share Posted March 29, 2016 Okay, this is a huge help, thanks! I will put together some code based on what you have started for me. Is there a good place to read some helpful codes to get started? (Apart from the AutoCAD Help full list!) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted March 29, 2016 Share Posted March 29, 2016 You are welcome. Let me know how you get on with the codes and just ask if you have any question. I think firstly you need to read about the basics about functions in AutoLISP and after diving into codes and what they do and return you can search for any task / codes in this forum and if you did not find what you are looking forward , you can ask your question here as you did with this thread and many helpful users would not hesitate to help you out as long as your task is possible to be coded and don't need lots of codes to get the job done. Hit this link => AutoLISP FUNCTIONS Quote Link to comment Share on other sites More sharing options...
YZ Posted April 5, 2016 Author Share Posted April 5, 2016 Thanks again Thawart. I have watched a bunch of videos and read heaps of examples. Things are becoming much clearer! The code I ended up using is: (setq checkwater (ssget "_A" '((8 . "water")))) I don't know what the "8 ." is for, but it works. Another example replaced that with "0 ." but that doesn't work in this case. Also, the "_A" selects everything in the any layout of that drawing. Is there a way to focus the selection on only the active layout? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 5, 2016 Share Posted April 5, 2016 Hi, The number 8 represent the DXF code for Layer name see THIS LINK To focus a selection set on current active layout , you need to use the DXF 410 with Layout name like this; (setq checkwater (ssget "_A" (list '(8 . "water") (cons 410 (getvar 'CTAB))))) Notice that the System Variable CTAB get the Active layout name that is current and to know how the DXF 410 works have a look again in the previous link that I posted above and search for DXF 410 on the left side hand. Quote Link to comment Share on other sites More sharing options...
YZ Posted April 5, 2016 Author Share Posted April 5, 2016 Wow, that is a helpful link! Thanks. So how would I use that if instead of layers ( I wanted to focus a selection on all the points in a dwg? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 5, 2016 Share Posted April 5, 2016 Wow, that is a helpful link! Thanks. You're welcome. So how would I use that if instead of layers ( 8 ) I wanted to focus a selection on all the points in a dwg? Just remove the complete filter DXF codes that is for Layer name (8 . "Mylayer") Quote Link to comment Share on other sites More sharing options...
YZ Posted April 5, 2016 Author Share Posted April 5, 2016 (ssget "_X" '((0 . "Point"))) Yes, this seems to work. And if I needed to perform an action on that selection set? Like erase them? Or move them in to another layer? The ssget might not be the best command to use? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 5, 2016 Share Posted April 5, 2016 And if I needed to perform an action on that selection set? Like erase them? You have two options. first use the command call erase or iterate through the selection set and delete each entity with the use of function entdel. ...... Or move them in to another layer? Also you need to iterate through the selection set then move the entity name to any layer name that MUST be existed into your drawing. The ssget might not be the best command to use? What makes you to think so? Quote Link to comment Share on other sites More sharing options...
YZ Posted April 5, 2016 Author Share Posted April 5, 2016 Wait! I got it: (command "erase" (ssget "_X" '((0 . "Point")))"") You've been super helpful. Thanks again! Quote Link to comment Share on other sites More sharing options...
YZ Posted April 5, 2016 Author Share Posted April 5, 2016 ssget is the correct command, once I worked out to house it inside another command. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 5, 2016 Share Posted April 5, 2016 Wait! I got it: (command "erase" (ssget "_X" '((0 . "Point")))"") You've been super helpful. Thanks again! That should work if you have Point objects into your drawing. But if there isn't, an error should occur. Try this instead to check first if points are available then delete them with erase command as in your example. (if (setq ss (ssget "_X" '((0 . "Point")))) (command "erase" ss "") ) Quote Link to comment Share on other sites More sharing options...
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.