Jump to content

Recommended Posts

Posted

I have a question, if it is even possible. For example, I want to select part of my drawing that contains lines and points (ssget_test). Is it possible to extract two selection sets, one with just lines (ss_lines) and other with points (ss_points), from that first selection set (ssget_test)? Basically to filter the selection set by cons 0

Posted

I have tried looking there, but didn't find needed. Or maybe I don't know what I need to look for exactly. The idea is to use only one ssget and select multiple objects (select only once). And then get selection sets, for example: sel1 (cons 0 "INSERT"), sel2 (cons 0 "LINE"), etc

Posted

Basic example for you to get start with.

(if (setq ss (ssget '((0 . "LINE,POINT"))))
  (repeat (setq i (sslength ss))
    (setq e (entget (ssname ss (setq i (1- i)))))
    (if (= (cdr (assoc 0 e)) "LINE")
      ;; then do your stuff here for lines
      ;; else is point object so do your stuff for points.
      )
    )
  )

 

  • Like 1
  • Agree 1
Posted
24 minutes ago, Tharwat said:

Basic example for you to get start with.


(if (setq ss (ssget '((0 . "LINE,POINT"))))
  (repeat (setq i (sslength ss))
    (setq e (entget (ssname ss (setq i (1- i)))))
    (if (= (cdr (assoc 0 e)) "LINE")
      ;; then do your stuff here for lines
      ;; else is point object so do your stuff for points.
      )
    )
  )

 


Ok thank you, that idea has crossed my mind, but I thought maybe I could get selection set from selection set based on "cons 0" filter.

Posted

This:

(ssget '((0 . "LINE,POINT")))

Similar to this :

(ssget (list (cons 0 "LINE,POINT")))

 

Posted (edited)

You can loop though the selectionset and create two new ones with the items filtered like this.

This is only better if you use the whole set later, otherwise its an extra step from the solution Tharwat posted

(if (setq ss (ssget '((0 . "LINE,POINT")))) (progn
	(setq lines (ssadd) ; Create empty selectionset
	      points (ssadd) ; Create empty selectionset
	      counter 0)
	(repeat (setq i (sslength ss)) ; Loop through selectionset and split into two sets
		(setq e (ssname ss (setq i (1- i))))
		(if (eq (cdr (assoc 0 (entget e))) "LINE") ; Decide which set to add to.
			(ssadd e lines)
			(ssadd e points)
		)
	)
	(setq ss nil) ; Remove origional set
    
	; So stuff with lines-selectionset and points-selectionset
    
))
Edited by dexus
  • Like 1
Posted
23 minutes ago, dexus said:

You can loop though the selectionset and create two new ones with the items filtered like this.

This is only better if you use the whole set later, otherwise its an extra step from the solution Tharwat posted


(if (setq ss (ssget '((0 . "LINE,POINT")))) (progn
	(setq lines (ssadd) ; Create empty selectionset
	      points (ssadd) ; Create empty selectionset
	      counter 0)
	(repeat (setq i (sslength ss)) ; Loop through selectionset and split into two sets
		(setq e (ssname ss (setq i (1- i))))
		(if (eq (cdr (assoc 0 (entget e))) "LINE") ; Decide which set to add to.
			(ssadd e lines)
			(ssadd e points)
		)
	)
	(setq ss nil) ; Remove origional set
    
	; So stuff with lines-selectionset and points-selectionset
    
))


Thanks! I'll try to use that method, since I am trying to modify my current code that has sets that are used later, and there are much more filters than just lines and points like I gave an example here. This way I don't have to change too much. Thanks again, hope it will work when I test it tomorrow

Posted

Like Dexus you can use a COND rather than a IF

 

(setq obj (cdr (assoc 0 (entget e))))
(cond 
((= obj "LINE")(ssadd e lines))
((= obj "POINT")(ssadd e points))
((= obj "LWPOLYLINE")(ssadd e plines))
other objects
)

 

 

  • Like 1

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