Jump to content

Adding selection set Items to one set.


Recommended Posts

(setq ss1 (ssget "C" pt1 pt2 '((0 . "LWPOLYLINE")))); add all lw polylines to ss set
(setq ss2 (ssget "C" pt3 pt4 '((0 . "LWPOLYLINE")))); add all lw polylines to ss set

How can I add all items in SS1 and SS2 together

Link to post
Share on other sites
David Bethel

Maybe like this :

 

 

[b][color=BLACK]([/color][/b]defun combss [b][color=FUCHSIA]([/color][/b]ss1 ss2 / tmp i en[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq tmp [b][color=NAVY]([/color][/b]ssadd[b][color=NAVY])[/color][/b]
         i 0[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq en [b][color=MAROON]([/color][/b]ssname ss1 i[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]ssadd en tmp[b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq i [b][color=MAROON]([/color][/b]1+ i[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]setq i 0[b][color=FUCHSIA])[/color][/b]       
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq en [b][color=MAROON]([/color][/b]ssname ss2 i[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]ssmemb en tmp[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
            [b][color=MAROON]([/color][/b]ssadd en tmp[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq i [b][color=MAROON]([/color][/b]1+ i[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
tmp[b][color=BLACK])[/color][/b]

 

You easily could add some conditional testing of the entities.

 

-David

Link to post
Share on other sites
satishrajdev

My version :-

 

(defun mergeset	(sset dset / a)
 (repeat (setq i (sslength sset))
   (setq a (ssname sset (setq i (1- i))))
   (ssadd a dset)
 )
 dset
)


_$ (SETQ SS (SSADD))  ;[b] <- If SS is NIL then add this[/b]
<Selection set: 29e1>
_$ (MERGESET SS1 SS)
<Selection set: 29d7>
_$ (MERGESET SS2 SS)
<Selection set: 29d7>
_$ 

Link to post
Share on other sites

Heres for unlimited number of selection sets:

(defun MergeSelectionSets ( ListOfSSs / Lst nSS )
(if (apply 'and (mapcar '(lambda (x) (= 'PICKSET (type x))) ListOfSSs))
	(progn
		(setq nSS (ssadd))
		(mapcar 
			(function 
				(lambda (x / i) 
					(repeat (setq i (sslength x))
						(ssadd (ssname x (setq i (1- i))) nSS)
					)
				)
			)
			ListOfSSs
		)
	)
)
nSS
)

Example:

(defun C:test ( / SS ListOfSSs )

(while (and (setq SS (ssget "_:L")) (princ "\nSelect object(s) or press enter: "))
	(setq ListOfSSs (cons SS ListOfSSs))
)

(sssetfirst nil (MergeSelectionSets ListOfSSs))
(princ)
)

Link to post
Share on other sites
David Bethel
(command "_.select" ss1 ss2 "")
(setq ss3 (ssget "_P"))

 

 

Lee, I don't think I have ever been able to use (command "_.SELECT"...)

 

I just tried in 2004. Has this changed in newer releases ?

 

-David

Link to post
Share on other sites
Lee, I don't think I have ever been able to use (command "_.SELECT"...)

 

I just tried in 2004. Has this changed in newer releases ?

 

I can confirm it works in 2013 onwards, others may be able to confirm earlier versions.

Link to post
Share on other sites

Another (not so efficient) way:

; ListOfSSs - list of selection sets to merge
; Returns - merged selection set " RtnSS "
(defun MergeSSets ( ListOfSSs / RtnSS )
(if (apply 'and (mapcar '(lambda (x) (= 'PICKSET (type x))) ListOfSSs))
	(progn (setq RtnSS (ssadd))
		(mapcar 
			(function 
				(lambda ( SS / i )
					(setq i -1)
					(repeat (apply 'max (mapcar 'sslength ListOfSSs)) ; inneficient but I wanted to go this way
						(ssadd (ssname SS (rem (setq i (1+ i)) (sslength SS))) RtnSS) ; wanted to utilise (rem) function
					)
				)
			)
			ListOfSSs 
		)
	)
)
RtnSS
)

I just wanted to utilise the (rem) function.

Link to post
Share on other sites
  • 4 years later...

Hello to everyone,

I have a lisp that rotate objects. This lisp only allows me to select one object.

Can we add multiple object selection to this lisp?

Can you please help?

(defun c:flip ()
(setq asnp (getvar "autosnap"))
(setq osm (getvar "osmode"))
(setvar "osmode" 64)

(setq a (entsel "\nselect entity to rotate: "))

(setq b (cadr a))

(command "rotate" a "" b "180")
(setvar "autosnap" asnp)
(setvar "osmode" osm)
(setq a1 Nil)
(princ)
)

 

Link to post
Share on other sites
BIGAL

There is so many examples out there most use (repeat (sslength ss) ie repeat for all the items in a selection set, just have a look at other code posted here and you will find example very fast. A good homework question, you will learn that way.

 

hint (setq a (ssname ss x))

 

 

Link to post
Share on other sites

Thank you BIGAL for your reply. Actually, I don't know how and on which line to add the change you mentioned. I tried a few times but lisp gave an error. If it won't take much of your time, could you make this change for me? Thank you very much in advance.

Link to post
Share on other sites
zwonko

Tried to do Your homework :) but there is problem. Entget giving You entityname and point (where you clicked). SSget will not. The point is set now for startpoint.

 

(defun c:flip2 (/ a b c i en pt ptx pty a1)
(setq asnp (getvar "autosnap"))
(setq osm (getvar "osmode"))
(setvar "osmode" 64)


  (if (setq ss (ssget ))
    (repeat (setq i (sslength ss))
      (setq en (ssname ss (setq i (1- i))))

;(princ en)
;(setq b (cadr en)) ; this given you a point of clicked object
(setq c (entget en)); this will give DXF code
(setq b (assoc 10 c));this read first verticle of line or polyline
;(princ b)
(setq ptx (nth 1 b))
(setq pty (nth 2 b))
(setq pt (list ptx pty))
;(command "rotate" en "" "0,0" "180")  ;this will rotate by 0,0 point
(command "rotate" en "" pt "180")
;(princ (entget en))
) ;end repeat
)end if
(setvar "autosnap" asnp)
(setvar "osmode" osm)
(setq a1 Nil)
(princ)
)

 

Link to post
Share on other sites

Thank you for your hard work, zwonko. There is only one problem. Lisp does not ask for a reference point for the rotation. If this is fixed too, it will be a lisp that works just fine.

Link to post
Share on other sites
mhupp
1 hour ago, Husso said:

Thank you for your hard work, zwonko. There is only one problem. Lisp does not ask for a reference point for the rotation. If this is fixed too, it will be a lisp that works just fine.

 

The point is pulled from each entity with the 10 dxf code. No real reason to set snaps anymore. and the z doesn't really need to be stripped out.

 

(defun C:flip2 (/ ss en pt)
  (if (setq ss (ssget))
    (foreach en (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (if (= 0 (cdr (assoc 73 (entget en))))
        (setq pt (cdr (assoc 10 (entget en))))
        (setq pt (cdr (assoc 11 (entget en))))
      )
      (command "rotate" en "" pt "180")
    )
  )
  (princ)
)

Forgot what Ronjon posted

 

dxf code 10:

Primary point. This is the start point of a line or text entity, center of a circle, and so on.
DXF: X value of the primary point (followed by Y and Z value codes 20 and 30)
APP: 3D point (list of three reals)

Edited by mhupp
updated code with ronjon's for text that don't have dfx code 10
Link to post
Share on other sites
zwonko
1 hour ago, Husso said:

Lisp does not ask for a reference point for the rotation

Of course is doesn't. Read what I've written below.

 

On 10/18/2021 at 10:33 AM, zwonko said:

Entget giving You entityname and point (where you clicked). SSget will not.

So it can't be made like it was before, that object was fliped based to clicked point, because You do "selection set". If You wan't select another (extra) point for rotation of all objects it is simple. You can do it Yourself if You just want to.

 

  • Agree 1
Link to post
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
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...