Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selection Set help

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
bdsmls
885 Views, 14 Replies

Selection Set help

I've created a selection set by manually selecting objects. now what i want to do is highlight those objects later on in the session. so using previous to highlight the selection set is not an option. is there a way to have a selection set that is stored in the drawing highlighted on demand? i want to do this with LISP since this step will be used in conjunction with another step and i only know LISP.

 

thanks in advance,

Larry

14 REPLIES 14
Message 2 of 15
rkmcswain
in reply to: bdsmls

; select the objects
(setq p (ssget))
(do_something_else_here)
; select the selection set "p"
(sssetfirst nil p)

 Is this what you mean?

R.K. McSwain     | CADpanacea | on twitter
Message 3 of 15
Shneuph
in reply to: bdsmls

I think you're talking about redraw.  Check that function out.

Redraw Help

Message 4 of 15
bdsmls
in reply to: bdsmls

i thought i had it right, but it didn't work for me when i tested it. now i'm thinking it's because of the selection set name. here's what i wrote, trying to specify a selection set name that can be recalled later. maybe you can see the error:

 

(DEFUN C:SSBM()
(SETVAR "CMDECHO" 0)
(SETQ WTD(UKWORD 1 "Create Highlight" "Selection set: (Create  or Highlight)" WTD))  ;custom command similar to GETKWORD
(IF(= WTD "Create")(PROGN
(SETQ BMSS(UANS "Name for selection set" NIL NIL))
(SETQ BMSS(SSGET))
(SSSETFIRST NIL BMSS)
)
(PROGN
(SETQ BMSS(UANS "Name of selection set to highlight" BMSS NIL))
(SSSETFIRST NIL BMSS)
)
)
(PRINC)
)

Message 5 of 15
Kent1Cooper
in reply to: bdsmls


@bdsmls wrote:

i thought i had it right, but it didn't work for me when i tested it. now i'm thinking it's because of the selection set name. here's what i wrote, trying to specify a selection set name that can be recalled later. maybe you can see the error:

....

(IF(= WTD "Create")

  (PROGN ; then
    (SETQ BMSS(UANS "Name for selection set" NIL NIL))
    (SETQ BMSS(SSGET))
    (SSSETFIRST NIL BMSS)
  )
  (PROGN ; else
    (SETQ BMSS(UANS "Name of selection set to highlight" BMSS NIL))
    (SSSETFIRST NIL BMSS)
  )
....


It's hard to say without seeing what the (UANS) function does.  I'm hoping that will make it clear why there are two settings of BMSS in the 'then' part, but only one in the 'else' part.  But in either case, provided something was actually selected, the (sssetfirst) function ought to highlight/grip it/them.

Kent Cooper, AIA
Message 6 of 15
bdsmls
in reply to: Kent1Cooper

it did grip them, but only during the "create" part of the routine. when i tried to rehighlight the set it didn't work. that's why my original question was only how to highlight an old selection set. sorry i didn't clarify about the UANS, its basically just GETSTRING except it requires a value. the reason for two BMSS was i was trying to name the selection set before selecting so there is a name to identify the set for rehighlighting later

Message 7 of 15
Lee_Mac
in reply to: bdsmls

Here is a very simple version of what I believe you are looking to achieve:

 

(defun c:ssbm ( / sel var )
    (initget "Create Highlight")
    (if (= "Create" (getkword "\nChoose [Create/Highlight] <Highlight>: "))
        (if (and (setq var (ssbm:newname "\nName for selection set: "))
                 (setq sel (ssget))
            )
            (set (read var) sel)
        )
        (if (setq var (ssbm:getname "\nName of selection set to highlight: "))
            (sssetfirst nil (eval (read var)))
        )
    )
    (princ)
)

(defun ssbm:newname ( msg )
    (ssbm:getstringif msg '(lambda ( x ) (not (boundp (read x)))) "\nName invalid or already in use.")
)
(defun ssbm:getname ( msg )
    (ssbm:getstringif msg '(lambda ( x ) (= 'pickset (type (eval (read x))))) "\nSelection set not found.")
)
(defun ssbm:getstringif ( msg prd els / str )
    (while (not (or (= "" (setq str (getstring msg))) ((eval prd) str)))
        (princ els)
    )
    (if (/= "" str) str)
)
(princ)
Message 8 of 15
Kent1Cooper
in reply to: bdsmls

If (UANS) is like (getstring), it appears that in your 'then' part you're setting BMSS to a string first, and then to a selection set.  In your 'else' part you're setting it only to a string, which will overwrite any selection set previously stored in that variable name, and which (sssetfirst) will not be able to highlight.

Kent Cooper, AIA
Message 9 of 15
bdsmls
in reply to: Lee_Mac

that worked great for highlighting existing selection sets, but it doesn't highlight the set when it's created

Message 10 of 15
Lee_Mac
in reply to: bdsmls

bdsmls wrote:

that worked great for highlighting existing selection sets, but it doesn't highlight the set when it's created

 

I'm sure you could've worked that one out Smiley Wink

 

(defun c:ssbm ( / sel var )
    (initget "Create Highlight")
    (if (= "Create" (getkword "\nChoose [Create/Highlight] <Highlight>: "))
        (if (and (setq var (ssbm:newname "\nName for selection set: "))
                 (setq sel (ssget))
            )
            (sssetfirst nil (set (read var) sel))
        )
        (if (setq var (ssbm:getname "\nName of selection set to highlight: "))
            (sssetfirst nil (eval (read var)))
        )
    )
    (princ)
)

(defun ssbm:newname ( msg )
    (ssbm:getstringif msg '(lambda ( x ) (not (boundp (read x)))) "\nName invalid or already in use.")
)
(defun ssbm:getname ( msg )
    (ssbm:getstringif msg '(lambda ( x ) (= 'pickset (type (eval (read x))))) "\nSelection set not found.")
)
(defun ssbm:getstringif ( msg prd els / str )
    (while (not (or (= "" (setq str (getstring msg))) ((eval prd) str)))
        (princ els)
    )
    (if (/= "" str) str)
)
(princ)
Message 11 of 15
bdsmls
in reply to: Lee_Mac

lol. i was just adding that when i saw your response.

thank you very much for the help

 

Larry

Message 12 of 15
bdsmls
in reply to: bdsmls

to take this one more step, seeing as how if enough selection sets are created it could become difficult to remember their names, is there a way to list the names of the sets for easy viewing?

 

Larry

Message 13 of 15
Lee_Mac
in reply to: bdsmls

bdsmls wrote:

to take this one more step, seeing as how if enough selection sets are created it could become difficult to remember their names, is there a way to list the names of the sets for easy viewing?

 

Try something like this:

 

(defun c:ssbm ( / sel var )
    (initget "Create Highlight")
    (if (or (null ssbm:selsets) (= "Create" (getkword "\nChoose [Create/Highlight] <Highlight>: ")))
        (if (and (setq var (ssbm:newname "\nName for selection set: "))
                 (setq sel (ssget))
                 (setq ssbm:selsets (cons var ssbm:selsets))
            )
            (sssetfirst nil (set (read var) sel))
        )
        (progn
            (initget "?")
            (while (= "?" (setq var (ssbm:getname "\nName of selection set to highlight [?]: ")))
                (foreach x (acad_strlsort ssbm:selsets) (print x))
            )
            (if var (sssetfirst nil (eval (read var))))
        )
    )
    (princ)
)

(defun ssbm:newname ( msg )
    (ssbm:getstringif msg '(lambda ( x ) (not (boundp (read x)))) "\nName invalid or already in use.")
)
(defun ssbm:getname ( msg )
    (ssbm:getstringif msg '(lambda ( x ) (or (= "?" x) (= 'pickset (type (eval (read x)))))) "\nSelection set not found.")
)
(defun ssbm:getstringif ( msg prd els / str )
    (while (not (or (= "" (setq str (getstring msg))) ((eval prd) str)))
        (princ els)
    )
    (if (/= "" str) str)
)
(princ)
Message 14 of 15
bdsmls
in reply to: bdsmls

perfect.

thanks for all your help

 

Larry

Message 15 of 15
Lee_Mac
in reply to: bdsmls

You're welcome Larry Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost