ssget to add entities to already highlighted selection

ssget to add entities to already highlighted selection

svucic
Advocate Advocate
3,646 Views
10 Replies
Message 1 of 11

ssget to add entities to already highlighted selection

svucic
Advocate
Advocate

Hi everyone,

 

I'm trying to figure out how to use ssget (or any other method) to select objects but I don't want it to deselect objects that are already highlighted before the ssget command starts.

 

I was looking at the PICKFIRST and PICKADD system variables but I can't figure out how to do it.

 

Any help will be highly appreciated.

 

Srdjan Vucic 

0 Likes
Accepted solutions (2)
3,647 Views
10 Replies
Replies (10)
Message 2 of 11

ВeekeeCZ
Consultant
Consultant
Accepted solution

Using the SELECT command it is easy to solve...

 

(defun c:test ()
  (setq sp (ssget))
  (command "_.SELECT" sp)
  (while (> (getvar 'CMDACTIVE) 0) (command PAUSE))
  (setq ss (ssget "_P"))
  (command "_.CHPROP" ss "" "c" "YELLOW" "")
  )

(defun c:test2 ()
  (ssget)
  (command "_.SELECT" "_P")
  (while (> (getvar 'CMDACTIVE) 0) (command PAUSE))
  (command "_.CHPROP" "P" "" "c" "YELLOW" "")
  )

 

Not sure about (ssget), how did you achieved your current highlighted objects? Using the previous ssget, or sssetfirst or grdraw??

Message 3 of 11

DannyNL
Advisor
Advisor

Why don't you just select the additional objects before running your LISP? If filtering is needed you can use QSELECT to add them.

That way the (ssget) will pickup all the selected objects at once without you requiring to select the additional ones in LISP after starting your routine.

 

But if necessarily it would be possible although you will need to merge two selection sets (one the already selected objects, two the new selected objects) in your routine to get the same result and highlight them as one selection set.

 

This is my possible solution. No filtering or anything, but just adding new objects to your already prior selected object set. Basically the same as selecting additional objects without this routine, but if needed you can add your object filtering to the SSGET and/or your actions to perform on the selection set.

Please note that the already selected objects before running this routine are only highlighted (to indicate which ones are already included) but you cannot deselect and remove them.

 

(defun c:AddSelect (/ AS_CurrentSelection AS_NewSelection AS_PFMode AS_Count)
   (setq AS_CurrentSelection (nth 1 (ssgetfirst)))
   (setq AS_PFMode (getvar "PICKFIRST"))
   (setvar "PICKFIRST" 0)
   (if
      AS_CurrentSelection
      (progn
         (setq AS_Count 0)
         (repeat (sslength AS_CurrentSelection)
            (vla-Highlight (vlax-ename->vla-object (ssname AS_CurrentSelection AS_Count)) :vlax-true)
            (setq AS_Count (1+ AS_Count))
         )
      )
   )   
   (setq AS_NewSelection (ssget))
   (setvar "PICKFIRST" AS_PFMode)
   (cond
      (
         (and 
            AS_CurrentSelection
            AS_NewSelection
         )
         (progn
            (setq AS_Count 0)
            (repeat (sslength AS_NewSelection)
               (ssadd (ssname AS_NewSelection AS_Count) AS_CurrentSelection)
               (setq AS_Count (1+ AS_Count))
            )
            (sssetfirst nil AS_CurrentSelection)
         )
      )
      (
         AS_CurrentSelection
         (sssetfirst nil AS_CurrentSelection)
      )
      (
         AS_NewSelection
         (sssetfirst nil AS_NewSelection)
      )
      (
         T
         nil
      )
   )
   (vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
   (princ)
)

 

 

Message 4 of 11

svucic
Advocate
Advocate

Thank you @ВeekeeCZ! Select did what I needed. Yes, I used ssget and sssetfirst to get the first selection.

0 Likes
Message 5 of 11

svucic
Advocate
Advocate

Thank you @DannyNL for your help. I'll have a closer look at your code. For now I found a solution that satisfies.

0 Likes
Message 6 of 11

svucic
Advocate
Advocate

Hi @ВeekeeCZ, I would like to ask another question regarding your test example.

 

Why do I need this line ?

 

(setq sp (ssget))

 

 

I noticed something strange in my code below. If I have the "(setq sp (ssget))" line and I go into the Opt1 only the "(command "_.SELECT" borderline1)" prompts for selection and everything is fine. If I go to Opt2 and then back to Opt1 I am prompted to select objects by both,  ssget and  (command "_.SELECT" borderline1).

But if I comment out the "(setq sp (ssget))" line than the following happens. If i go directly into Opt1 I'm not prompted for selection. If I go into Opt2 and than into Opt1 it works fine.

 

I hope you can understand what I mean, if not please let me know I will try to express myself better.

 

Thank you for your help! 🙂 

 

 

(setq KK nil)
	(while (/= KK 13)
	
	(initget "Opt1 Opt2")
	(setq x (getkword "\nSome text ...[Opt1 / Opt2] <Opt1 >: "))
	
	(if (= x "Opt1 ")
		(progn
					(setq sp (ssget))
					(command "_.SELECT" borderline1)
					(while (> (getvar 'CMDACTIVE) 0) (command PAUSE))
					(setq ss (ssget "_P"))
					(setq mapborderlist1 (acet-ss-union (list mapborderlist)))
					(sssetfirst nil ss)

		)
		(progn
			(if (= x "Opt2 ")
				(progn
					(sssetfirst nil borderline1)
					(setq K nil)
					(while (/= K 13)
					(prompt "\nSome text again!")
					(setq mb (car (entsel)))
					(if (assoc -3 (entget mb '("map_border")))
						(progn
							(setq mapborderlist1 (acet-ss-union (list mapborderlist)))
							(ssdel mb mapborderlist1)
							(setq ptl nil)
							(setq entlist (entget mb))
							(foreach dxfcode entlist
							(if (= (car dxfcode) 10) (setq ptl (cons (cdr dxfcode) ptl)))
							)
				
							(setq ss (ssget "_CP" ptl))
							(setq cnt1 (sslength ss))
							(setq i1 0)
							
							(while (/= cnt1 i1)
							(ssdel (ssname ss i1) borderline1)
							(setq i1 (1+ i1))
							(princ)
							)
							(sssetfirst nil borderline1)
							(setq ss borderline1)
							
						)
						(progn
							(exit)
							(command "._UNDO" "_End")
						)
					)
					(prompt "\nSome text ... press  ENTER.")
					(setq K nil K (last (grread)))
					)
				)
			)
		)
	)
	(prompt "\nTo do ... press ENTER otherwise press SPACE.")
	(setq KK nil KK (last (grread)))
	)

 

0 Likes
Message 7 of 11

ВeekeeCZ
Consultant
Consultant

Hi... you certainly don't need that line!

 

It was just for a test purpose - I just needed to get a previous highlighted selection somehow, since you did not offered your own code.

0 Likes
Message 8 of 11

svucic
Advocate
Advocate

I still don't understand why the PAUSE command is not working if I choose Opt1, but if I choose Opt2 and then Opt1 it works. 

0 Likes
Message 9 of 11

svucic
Advocate
Advocate

I still don't understand why the PAUSE command is not working.

 

If "(setq sp (ssget))" is commented:

if I choose Opt1 it doesn't work, but if I choose Opt2 and then Opt1 it works. 

 

If "(setq sp (ssget))" is active / not commented:

if I choose Opt1 it  works, but if I choose Opt2 and then Opt1 I'm prompted twice to select.

0 Likes
Message 10 of 11

ВeekeeCZ
Consultant
Consultant

It may have something to do with pre-selection (implied selection).

(sssetfirst nil (ssget))
(command "select" pause) ; it takes the preselection and ignores the pause.

 

So... you may need to clear preselection (sssetfirst nil nil) or do regen.
Also you may need to test if there is one by (if (ssget "I")...

0 Likes
Message 11 of 11

svucic
Advocate
Advocate
Accepted solution

Just for the record or anyone who might have the same problem, here is the solution I found. I just added 

(setvar "PICKFIRST" 1)

before 

(command "_.SELECT" borderline1)

Even though, when debugging in VLIDE, PICKFIRST is already set to 1 at this point.

 

The final code looks like this: 

 

(setq KK nil)
	(while (/= KK 13)
	
	(initget "Opt1 Opt2")
	(setq x (getkword "\nSome text ...[Opt1 / Opt2] <Opt1 >: "))
	
	(if (= x "Opt1 ")
		(progn
					(setvar "PICKFIRST" 1)
					(command "_.SELECT" borderline1)
					(while (> (getvar 'CMDACTIVE) 0) (command PAUSE))
					(setq ss (ssget "_P"))
					(setq mapborderlist1 (acet-ss-union (list mapborderlist)))
					(sssetfirst nil ss)

		)
		(progn
			(if (= x "Opt2 ")
				(progn
					(sssetfirst nil borderline1)
					(setq K nil)
					(while (/= K 13)
					(prompt "\nSome text again!")
					(setq mb (car (entsel)))
					(if (assoc -3 (entget mb '("map_border")))
						(progn
							(setq mapborderlist1 (acet-ss-union (list mapborderlist)))
							(ssdel mb mapborderlist1)
							(setq ptl nil)
							(setq entlist (entget mb))
							(foreach dxfcode entlist
							(if (= (car dxfcode) 10) (setq ptl (cons (cdr dxfcode) ptl)))
							)
				
							(setq ss (ssget "_CP" ptl))
							(setq cnt1 (sslength ss))
							(setq i1 0)
							
							(while (/= cnt1 i1)
							(ssdel (ssname ss i1) borderline1)
							(setq i1 (1+ i1))
							(princ)
							)
							(sssetfirst nil borderline1)
							(setq ss borderline1)
							
						)
						(progn
							(exit)
							(command "._UNDO" "_End")
						)
					)
					(prompt "\nSome text ... press  ENTER.")
					(setq K nil K (last (grread)))
					)
				)
			)
		)
	)
	(prompt "\nTo do ... press ENTER otherwise press SPACE.")
	(setq KK nil KK (last (grread)))
	)
0 Likes