Author Topic: Create a selection set with some objects pre-selected  (Read 2482 times)

0 Members and 1 Guest are viewing this topic.

PrinceLISPalot

  • Newt
  • Posts: 35
  • perfectionist trapped inside the mind of an idiot.
Create a selection set with some objects pre-selected
« on: April 17, 2014, 01:35:44 AM »
I'm trying to find if there is a way to allow a user to create selection set that for convenience already has some objects pre-selected. The user would then have the option to add/remove objects as they see fit.

The following code example illustrates what I'm trying to do. It pre-selects any red circles on the drawing, then allows the user to add any other circles they see fit.

Code: [Select]
(defun c:selcirc ( / presset sset)
(princ "\nPick circles to make RED")
(setq presset (ssget "x" '((-4 . "<and")(0 . "CIRCLE")(62 . 1)(-4 . "and>")))) ; Select all existing Circles that are red
(if (= (type presset) 'PICKSET)
(progn
(command "._CHPROP" presset "" "_C" "_bylayer" "")
(command "._SELECT" presset (ssget '((0 . "CIRCLE"))) "")
(setq sset (ssget "_P"))
)
(setq sset (ssget '((0 . "CIRCLE"))))
)
(if (= (type sset) 'PICKSET)
(command "._CHPROP" sset "" "_C" 1 "")
)
)

I say illustrate, as the code doesn't actually do what I want, is not exactly a robust approach, and causes issues when you run it in BricsCAD.  ^-^

NICK_VNV

  • Newt
  • Posts: 63
Re: Create a selection set with some objects pre-selected
« Reply #1 on: April 17, 2014, 03:24:30 AM »
Look help topics with "ssadd" and "ssdel" functions
« Last Edit: April 17, 2014, 03:27:56 AM by NICK_VNV »
Sorry for my English...

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create a selection set with some objects pre-selected
« Reply #2 on: April 17, 2014, 03:47:07 AM »
NICK_VNV is right of course. :-)

Two remarks regarding the code:
1.
There is no need for (-4 . "<and") and (-4 . "and>") in the first ssget filter.
2.
(ssget) will return a pickset or nil. So this:
Code: [Select]
(if (= (type presset) 'PICKSET) ...)Can be:
Code: [Select]
(if presset ...)
The fact that (ssget) can return nil is the main reason for the problems with the code.
The code is interesting because it gives visual feedback to the user.

My version below is still not ideal. To cancel you have to use escape twice for example.

Code: [Select]
(defun c:selcirc_roy ( / presset sset)
  (princ "\nPick circles to make RED")
  (setq presset  (ssget "X" '((0 . "CIRCLE")(62 . 1))))
  (if presset
    (command "._SELECT" presset (cond ((setq sset (ssget '((0 . "CIRCLE"))))) (ssadd)) "")
    (command "._SELECT" (cond ((setq sset (ssget '((0 . "CIRCLE"))))) (ssadd)) "")
  )
  (if (or presset sset)
    (command "._CHPROP" (ssget "P") "" "_color" 1 "")
  )
  (princ)
)




PrinceLISPalot

  • Newt
  • Posts: 35
  • perfectionist trapped inside the mind of an idiot.
Re: Create a selection set with some objects pre-selected
« Reply #3 on: April 17, 2014, 05:51:19 AM »
Thanks Roy & Nick_VNV,

It was the visual feedback to the user that I was pursuing. As far as I can see SSADD & SSDEL work in a non graphical way. If it was possible I would use ssget combined with the preselect option e.g.
Code: [Select]
(setq sset (ssget '((0 . "CIRCLE")) presset))
I resorted to using the SELECT command, as it was the only way I could think of to do it graphically. The code also doesn't work how I intended. You can add objects to the pre-selected ones, but you cannot remove any of the pre-selected ones from the selection set. This is why I was changing the colour to bylayer to give a visual cue

Is there any difference to using SSADD in the condition statement? I would of thought you would just return the variable.

Code: [Select]
(defun c:selcirc ( / presset sset)
  (princ "\nPick circles to make RED")
  (setq presset  (ssget "X" '((0 . "CIRCLE")(62 . 1))))
  (if presset
    (command
    "._CHPROP" presset "" "_C" "_bylayer" ""
    "._SELECT" presset (cond ((setq sset (ssget '((0 . "CIRCLE"))))) sset) "")
    (command "._SELECT" (cond ((setq sset (ssget '((0 . "CIRCLE"))))) sset) "")
  )
  (if (or presset sset)
    (command "._CHPROP" (ssget "P") "" "_color" 1 "")
  )
  (princ)
)

I did start to re-write using vla-select, but it looks like this wouldn't offer anything different than what I could achieve with ssget?



roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create a selection set with some objects pre-selected
« Reply #4 on: April 17, 2014, 06:48:20 AM »
Oops! There is an error in the function in my previous post.
Extra parentheses around (ssadd) are required.
Code: [Select]
(defun c:selcirc_roy_corrected ( / presset sset)
  (princ "\nPick circles to make RED")
  (setq presset  (ssget "X" '((0 . "CIRCLE") (62 . 1))))
  (if presset
    (command "._SELECT" presset (cond ((setq sset (ssget '((0 . "CIRCLE"))))) ((ssadd))) "")
    (command "._SELECT" (cond ((setq sset (ssget '((0 . "CIRCLE"))))) ((ssadd))) "")
  )
  (if (or presset sset)
    (command "._CHPROP" (ssget "P") "" "_color" 1 "")
  )
  (princ)
)

This code segment:
Code: [Select]
(cond
  ((setq sset (ssget '((0 . "CIRCLE")))))
  ((ssadd))
)
Equals:
Code: [Select]
(cond
  ((setq sset (ssget '((0 . "CIRCLE"))))
    sset
  )
  ((setq ssetEmpty (ssadd))
    ssetEmpty
  )
)
It is there to avoid a nil value instead of a pickset.

Removing preselected items is indeed not possible.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create a selection set with some objects pre-selected
« Reply #5 on: April 17, 2014, 07:02:00 AM »
Jason (you are Jason right?) any particular reason for preselecting entities? I have never seen it before.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Create a selection set with some objects pre-selected
« Reply #6 on: April 17, 2014, 10:22:06 AM »
I do that by my menu's toolbar:

**ARCH_SSET
[_Toolbar("Selection Set", _Floating, _hide,  225, 200, 1)]
[_Button("Selection Set A", ARCH_SELECTA, ARCH_SELECTA)]^p(if (/= sela nil)(setq sela sela)(progn (setq sela (ssget))+
(ARCH:ChangeBitmap "ARCH" "Selection Set" "Selection Set A" "ARCH_SELECTAX")));
[_Button("Selection Set B", ARCH_SELECTB, ARCH_SELECTB)]^p(if (/= selb nil)(setq selb selb)(progn (setq selb (ssget))+
(ARCH:ChangeBitmap "ARCH" "Selection Set" "Selection Set B" "ARCH_SELECTBX")));
//[_Button("Selection Set C", ARCH_SELECTC, ARCH_SELECTC)]^p(if (/= selc nil)(setq selc selc)(progn (setq selc (ssget))+
//(ARCH:ChangeBitmap "ARCH" "Selection Set" "Selection Set C" "ARCH_SELECTCX")));
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ymg

  • Guest
Re: Create a selection set with some objects pre-selected
« Reply #7 on: April 17, 2014, 11:51:44 AM »
A small function to get the current selection.

Code - Auto/Visual Lisp: [Select]
  1. (defun getcurrentsel ( )
  2.    (if (and (equal 1 (getvar "pickfirst"))
  3.             (cadr (ssgetfirst))
  4.        )
  5.        (cadr (ssgetfirst))
  6.    )
  7. )
  8.  


« Last Edit: April 17, 2014, 12:00:34 PM by ymg »

Bhull1985

  • Guest
Re: Create a selection set with some objects pre-selected
« Reply #8 on: April 17, 2014, 01:29:29 PM »
The routine is fundamentally flawed, asking to select circles to MAKE them red and selecting red circles are two different options. I would set up a ssget filter to select all circles EXCEPT those that are red. Still getting graphics, right? Now it's an inversion thing because all red circles are solid and all non red circles are dashed from the autocad selection set.

/shrug

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Create a selection set with some objects pre-selected
« Reply #9 on: April 17, 2014, 02:02:28 PM »
Is this what you are trying to accomplish?

Code: [Select]
(defun c:Test (/)
  (if (ssget "_I")
    (command "_.pselect" "_P")
    (command "_.pselect")
  )
  (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create a selection set with some objects pre-selected
« Reply #10 on: April 17, 2014, 02:36:13 PM »
The routine is fundamentally flawed, asking to select circles to MAKE them red and selecting red circles are two different options...
You have misunderstood the goal of the code in the OP. The keyword is 'illustrate'.

Bhull1985

  • Guest
Re: Create a selection set with some objects pre-selected
« Reply #11 on: April 17, 2014, 05:05:23 PM »
Well I noticed that but when I went into a new dwg, created 5 total layers of different colors, and made 3 circles on each layer....the routine illustrated only by selection...maybe I just don't understand how selecting red circles illustrates that the circles are going to be red..... O.?

edit...okay, I see....he wants to show the circles as RED because they're selected.
I see.....routine wasn't doing that for me during the first run of it, but at least I understand the intent now

NICK_VNV

  • Newt
  • Posts: 63
Re: Create a selection set with some objects pre-selected
« Reply #12 on: April 18, 2014, 03:52:44 AM »
... what I'm trying to do. It pre-selects any red circles on the drawing, then allows the user to add any other circles they see fit.
For this you can slightly change your code following way
Code: [Select]
...
(setq presset   (ssget "x" '((0 . "CIRCLE")(62 . 1)))) ; Select all existing Circles that are red
(setq presset2 (ssget  '((0 . "CIRCLE")))) ; Let user select any other circles
;; then join two selections by adding each object from "presset2" to "presset"
(setq cnt 0)
(repeat (sslength presset2)
 (ssadd (ssname presset2 cnt) presset)
 (setq cnt (1+ cnt))
)
...
Try (sssetfirst nil presset) to see all objects containing in "presset" now
« Last Edit: April 18, 2014, 03:58:22 AM by NICK_VNV »
Sorry for my English...

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create a selection set with some objects pre-selected
« Reply #13 on: April 18, 2014, 05:01:59 AM »
@ NICK_VNV:
Of course this works, but the OP wants to show the presset to the user and allow the user to not only select more filtered entities but also remove elements from the presset.

BTW: It is risky to use (ssget "X" ...) as it will also select entities that are off screen and even on other layouts.

mhutchinson

  • Guest
Re: Create a selection set with some objects pre-selected
« Reply #14 on: April 21, 2014, 04:10:09 PM »
The user already has objects selected... right?
Why not simply use the 'SELECT' command... ?