Extract from selection set, add and remove objects

Extract from selection set, add and remove objects

etilley327KA
Advocate Advocate
1,136 Views
10 Replies
Message 1 of 11

Extract from selection set, add and remove objects

etilley327KA
Advocate
Advocate

Please help, I cant figure out how to write this piece of code. The user will select a set from multiple layers. Layer "00formline" contains lines that I need to create a new polyline out of and then remove the "00formline" objects from the initial selection set and add the new polyline to the initial selection set.

 

(setq form_ss (ssget '((8 . "00-FORM,00-RE-FORM,SHOT,00FORMLINE"))))
      (cond
        ((and form_ss)
          (setq  sel_ss (ssadd) i -1)
          (while (< (setq i (1+ i)) (sslength form_ss)
            (setq e (ssname form_ss i) lname (cdr (assoc 8 (entget e))))
            (cond
              ((wcmatch lname "OOFORMLINE*")
                (setq sel_ss (ssadd (ssname form_ss i) sel_ssl))))
      )
      )
    )
             (setq sel_ss (ssadd (ssname form_ss i) sel_ss))
             (setq form_ss (ssdel (ssname form_ss i) form_ss))
             )
0 Likes
Accepted solutions (1)
1,137 Views
10 Replies
Replies (10)
Message 2 of 11

komondormrex
Mentor
Mentor

hey,

check that

 

(setvar 'pickfirst 1)
(sssetfirst nil (setq form_ss (ssget '((8 . "00-FORM,00-RE-FORM,SHOT,00FORMLINE")))))
(foreach formline (vl-remove-if 'listp (mapcar 'cadr (ssnamex (setq sel_ss (ssget '((8 . "00FORMLINE")))))))
	(ssdel formline sel_ss)
)
0 Likes
Message 3 of 11

Kent1Cooper
Consultant
Consultant

Does this approach do it for you?  It just pulls Lines on that Layer from the initial set.  Then when PEDIT Joined together, they no longer exist, so do you need to remove them?

(defun C:TEST (/ ss1 ss2)
  (if
    (and
      (setq ss1 (ssget '((8 . "00-FORM,00-RE-FORM,SHOT,00FORMLINE"))))
      (setq ss2 (ssget "_P" '((0 . "LINE") (8 . "00FORMLINE")))); contains Lines on that Layer
    ); and
    (progn
      (command "_.pedit" "_multiple" ss2 "" "_join" 0 "")
      (ssadd (entlast) ss1)
    ); progn
  ); if
  (prin1)
)

It assumes PEDITACCEPT is set to 1, and that you really meant LINE objects specifically that are to be made into a Polyline, not more generic "linework."

Kent Cooper, AIA
0 Likes
Message 4 of 11

etilley327KA
Advocate
Advocate
Thanks, I changed it a little, but it's joining the original lines with the copy. How could I change it to where it doesn't effect the original objects?
(defun C:TEST (/ ss1 ss2)
  (if
    (and
      (setq ss1 (ssget '((-4 . "<OR")(0 . "INSERT")(8 . "00FORMLINE")(-4 . "OR>"))))
      (setq ss2 (ssget "_P" '((8 . "00FORMLINE")))); contains Lines on that Layer
    ); and
    (progn
      (command "_.pedit" "_multiple" ss2 "" "" "_join" 0 "")
      (ssadd (entlast) ss1)
    ); progn
  ); if
  (command "_.copy" SS1 "")
  (prin1)
)
0 Likes
Message 5 of 11

Kent1Cooper
Consultant
Consultant

I took "lines that I need to create a new polyline out of" in Message 1 to mean to convert those Lines into a Polyline, but are you saying you want to convert copies of those Lines into a Polyline, so that the original Lines remain?

Kent Cooper, AIA
0 Likes
Message 6 of 11

etilley327KA
Advocate
Advocate

Yes sir, sorry for the confusion.

0 Likes
Message 7 of 11

etilley327KA
Advocate
Advocate

What is the easiest way to copy a selection set? That way converting it to a polyline wont effect the original objects.

0 Likes
Message 8 of 11

Kent1Cooper
Consultant
Consultant

Would it be acceptable to Copy them, and then convert the originals into a Polyline, so that the copies are what remain as Lines?  That would be very much easier than converting the copies, from the point of view of object selection in PEDIT.

Kent Cooper, AIA
0 Likes
Message 9 of 11

etilley327KA
Advocate
Advocate

Genius! Yeah, that would work!

0 Likes
Message 10 of 11

Moshe-A
Mentor
Mentor

@etilley327KA ,

 

here is (getNewCopied) function to do what you want but i agree with @Kent1Cooper 

it does not matter which group you pick to join, this is full copy, it's exactly the same objects - no?!  😀

 

Moshe

 

 

(defun getNewCopied (s0 / s1 ename)
 (if (and s0  			  ; make sure argument not nil
	  (eq (type s0) 'PICKSET) ; make sure this is a sset
	  (> (sslength s0) 0)	  ; has some objects?
     )
  (progn
   (setq ename (entlast))
   (command "._copy" "_si" s0 "0,0,0" "0,0,0")
   (setq s1 (ssadd))
   (while (setq ename (entnext ename))
    (ssadd ename s1)
   )
   s1
  ); progn
 ); if
); getNewCopied

(defun c:test (/ ss0 ss1)
 (if (setq ss0 (ssget))
  (setq ss1 (getNewCopied ss0))
 )

 (princ)
)

 

0 Likes
Message 11 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

@etilley327KA wrote:

Genius! Yeah, that would work!


But I'm realizing, looking at Message 4, that the COPYing of SS1 would need to happen before the PEDITing, because some of what's in SS1 will no longer exist after that.

Kent Cooper, AIA
0 Likes