Jump to content

Append to Selection set in a loop


Strydaris

Recommended Posts

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

 

 

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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 by Steven P
Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

If Your plines are contained within each other can use ssget "F" and get them in order. 

 

image.png.6ec31059f19e8d8d5e58b2a2ffa27e5f.png

 

If like this a bit more complicated but a possible method done in a loop.

 

image.png.f3487c5cebab5873fd620c2067bafb55.png

 

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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

 

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

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