Strydaris Posted August 1, 2023 Posted August 1, 2023 Hi everyone, I am trying to do more work in lists and trying to understand how to get pull information for them. Currently I am trying to create a list that hold the entity name of selected objects. The way how the lisp routine that I am making needs to work is in a logical selection order of things. Basically, I want the user to select 1 polyline, assign it to an area, then select another polyline and assign it to be subtracted from the previous polyline area, but there may be more than 1 of the second type of polyline. For the first Polyline I am using Entget, since its a single object all the time. The second set I am using ssget so that I can select more that one of them. This action may happen a total of 4 times. What I am looking to do and need a little help in the right direction is this... How do you append a selection set or list within a loop? From my understanding you create a new empty list using (setq otb (ssadd)) Then you can use (ssadd *Somevarible* otb) and that will add to the last point on a list. If this is true, why can't I do this in a loop? Any thoughts? (while (/= n 5) (setq var (read (strcat "lvl" (itoa n) "_area"))) ;(setq otb (read (strcat "lvl" (itoa n) "_otb"))) (cond ((= n 1) (set var (car (entsel "\nSelect Level 1 Area Polyline or [ENTER for 0]: "))) (if (= var nil) (set var 0) ) );END COND1 ((and (> n 1)(/= var "N/A")) ;(> n 1)(< n 5) (set var (car (entsel (strcat "\nSelect Level " (itoa n)" Area Polyline or [ENTER to Exit]: ")))) ;(set var (entget (car ver)) (if (= var nil) (set var "N/A") (progn (prompt (strcat "\nSelect Level " (itoa n) " Open to Below Polyline(s) or [Enter] for 0: ")) (setq otb_new (ssget)) (ssadd otb otb_new) ;(set otb (car (entget otb))) (if (= otb nil) (ssadd 0 otb) ) ) ) ) );END COND (setq n (+ n 1)) );END WHILE Quote
Steven P Posted August 1, 2023 Posted August 1, 2023 SSAdd wants ename, such that you might get from (entsel) rather than a selection set (https://documentation.help/AutoLISP-Functions/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6942.htm). I find Lee Mac to be quite good, his code below will join selection sets together nicely, he sorts the lists in his code, but you can strip out the basics, something like: .... (setq otb_new (ssget)) (repeat (setq i (sslength otb_new)) (ssadd (ssname otb_new (setq i (1- i))) otb) ) .... Linked this one because there is some discussion in the thread about faster or slower methods - talking milliseconds here - and use of express tools acet-ss-union, not everyone will have that but that command is more directly aligned to what you wrote Quote
Strydaris Posted August 1, 2023 Author Posted August 1, 2023 Hi Steven P, I wanted to use Entsel, but it didnt make sense to ask the user to select an Open to below area polylines multiple times for the same floor. Thats where the ssget came in. I figured that someone would know how to process the list made from ssget and help me get the Entity Names from the items in the list. That is the part I am stuck on. I figure it would be something like this. (setq i 0) (repeat (sslength otb) (setq entname (nth i otb)) (setq i (1+ i)) ) Am I close? Maybe Quote
Steven P Posted August 1, 2023 Posted August 1, 2023 (edited) Yes, close!! Selection sets arn't normal lists - things are never that easy. To get the entity name from a selection set you want to use (ssname ss i) where ss is selection set and i is the item number Added in a line to add this entity name to new_otb (setq i 0) ;; A counter (repeat (sslength otb) ;; repeat for the length of selection set otb (setq entname (ssname otb i)) ;; get then entity name of position i in the selection set (ssadd entname new_otb) ;; add the entity to selection set new_otb - as an example (setq i (1+ i)) ;; Increase count ) ;; end repeat loop Edited August 1, 2023 by Steven P Quote
Strydaris Posted August 1, 2023 Author Posted August 1, 2023 Oh wow, I was really close. just the wrong function. Ok so I am starting to get it. The extra section you added (ssadd entname new_otb) , you are creating a new list to store just the Entity names for easy access later. (as you said already) THEN I can use the nth method I showed before to access the entity names. if I am correct on how I am seeing this. Quote
j2lstaples Posted August 1, 2023 Posted August 1, 2023 2 hours ago, Strydaris said: Oh wow, I was really close. just the wrong function. Ok so I am starting to get it. The extra section you added (ssadd entname new_otb) , you are creating a new list to store just the Entity names for easy access later. (as you said already) THEN I can use the nth method I showed before to access the entity names. if I am correct on how I am seeing this. You can also check it in AutoCAD if it was correctly selected using: (sssetfirst nil new_otb) It will highlight it like a normal selection set with ssget or window selection and not some funky color change. Quote
BIGAL Posted August 2, 2023 Posted August 2, 2023 If Your plines are contained within each other can use ssget "F" and get them in order. If like this a bit more complicated but a possible method done in a loop. Quote
Strydaris Posted August 2, 2023 Author Posted August 2, 2023 Hey BIGAL, So my polylines could be a like you said, contained in each other. I do residential housing so basically the polyline scenario would be like this... For the sake of ease I used levels as my terminology instead of floors to suit different scenarios. Level 1 is always the lowest floor whether that's a basement or slab on grade ground floor. Level 1 could have 0 or 1 polyline for the area. Level 2 would have 1 main area polyline and could have 0 or 1 within it. Level 3 would have 1 main with 0 to 4 within the main(let's call them subs) , never overlapping and never within each other. Level 4 would be the same as 3. All main areas (the largest polyline) will have the polylines within subtracted from it. All the polylines within the main need to be added up I need to return the value of Main - sub1 - sub2 etc as well as the total of the subs. Would using (ssget "F") always supply the main polyline first and the subs after? Quote
Strydaris Posted August 2, 2023 Author Posted August 2, 2023 Oh, just had a brain storm If I used entsel for the main polyline, could I then use something like (setq ent (entsel) ;select the main polyline (setq otblst (ssget "wp" ent) ;select all objects within the polyline 1 Quote
ronjonp Posted August 2, 2023 Posted August 2, 2023 15 hours ago, Strydaris said: Oh, just had a brain storm If I used entsel for the main polyline, could I then use something like (setq ent (entsel) ;select the main polyline (setq otblst (ssget "wp" ent) ;select all objects within the polyline Except 'ent' would need to be a list of coordinates. Quote
BIGAL Posted August 2, 2023 Posted August 2, 2023 Like ronjonp suggestion. (setq ent (entsel "\nPick Pline ")) (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car ent))))) (setq otblst (ssget "wp" co-ord)) ;select all objects within the polyline 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.