Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Home
Help
Login
Register
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
Unselect items (selection set)
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: Unselect items (selection set) (Read 1723 times)
0 Members and 1 Guest are viewing this topic.
JohnK
Administrator
Seagull
Posts: 10661
Unselect items (selection set)
«
on:
September 26, 2023, 12:53:30 PM »
I am trying to build a more robust command that will act differently if there are items selected but I cannot remember if there is a way to "unselect" items. I built this example code to help show you what I mean. This example will simply draw a line, however if there are items selected, the clayer will be set to the objects layer under the pickpoint. This will work but I want to "unselect the selectionset" because I don't actually need the selected items for anything other than a "flag to do something". So, my question is how can I 'unselect' items that are preselected before my command is called?
EXAMPLE:
Code - Auto/Visual Lisp:
[Select]
(
defun
C:B
(
/
;; -Function locals.
*error*
*
error
-
push
-
vars
*
getlayerfrompickedpoint entmake
-
line drawline getpoints
;; -Variable locals.
pt1 ss
)
;;
;; This function will draw a line and adopt the layer of the ent
;; under the picked point.
;;
;; TODO: 1. Only adopt the layer if there are items selected, otherwise just
;; draw a line with the current layer.
;; a. Unselect items slected.
(
defun
*error*
(
msg
)
(
mapcar
'
eval
#error_lst#
)
(
setq
#error_lst#
nil
)
)
(
defun
*
error
-
push
-
vars
*
(
lst
/
push
->
lst
)
(
defun
push
->
lst
(
sym lst
)
(
set
lst
(
cons
sym
(
eval
lst
)
)
)
)
(
mapcar
(
function
(
lambda
(
x
)
(
push
->
lst
(
list
'
setvar
(
car
x
)
(
getvar
(
car
x
)
)
)
'#error_lst#
)
(
if
(
cadr
x
)
(
setvar
(
car
x
)
(
cadr
x
)
)
)
)
)
lst
)
)
(
defun
getlayerfrompickedpoint
(
pt
/
)
;; (getlayerfrompickedpoint <pt>)
;; Return the layer of the entity located at the pickpoint.
;; If there isn't an entity or layer property, return the current layer.
;;
;; ARGS: pt - A point
;;
;; RETURNS: A layer name
(
setvar
'LASTPOINT pt
)
(
setq
layer
(
getvar
'CLAYER
)
)
;; -Set default layer
;; NOTE: This value is being set now/here
;; because it should be overridden in the
;; code block below. This is so that
;; the clayer is returned if no entity
;; is picked.
(
cond
(
(
ssget
pt
)
;; -if we have something...
(
setq
pt
(
ssname
(
ssget
pt
)
0
)
)
(
cond
(
(
assoc
2
(
entget
pt
)
)
;; -disable xref objects from the list of items.
(
not
(
assoc
1
(
tblsearch
"BLOCK"
(
cdr
(
assoc
2
(
entget
pt
)
)
)
)
)
)
)
(
(
setq
layer
(
cdr
(
assoc
8
(
entget
pt
)
)
)
)
)
;; -otherwise just get the layer of pt/ent at the picked point.
)
)
)
layer
;; -return the layer
)
(
defun
entmake
-
line
(
p1 p2
)
;; Draws a line from two points.
;;
;; ARGS: p1 - A point
;; p2 - A Point
;;
;; RETURNS: A ent list.
(
entmakex
(
list
(
cons
0
"LINE"
)
(
cons
10
p1
)
(
cons
11
p2
)
)
)
)
(
defun
drawline
(
lst
)
;; A simple list processor that draws lines from the points
;;
;; ARGS: lst - A list of points
;;
;; RETURNS: nil
(
cond
(
(
null
lst
)
nil
)
(
(
cadr
lst
)
(
entmake
-
line
(
car
lst
)
(
cadr
lst
)
)
;; -draw a line from the
;; first and second point in list
(
drawline
(
cdr
lst
)
)
)
)
)
;; -send the remaining list back
;; through again to draw another line.
(
defun
getpoints
(
pt
/
pt p1 sp cnt
)
;; This is a very basterdized version of Smadsens function for getting
;; points and generating a list of points.
;;
;; I have overhauled the routine to draw lines instead of just
;; gathering points (and returning a list).
;;
;; ARGS: pt - The first point.
;;
;; RETURNS: nil
(
setq
p1 pt
sp pt
cnt
2
)
(
while
pt
(
initget
"Close"
)
(
setq
pt
(
getpoint
pt
(
strcat
"
\r
Point no. "
(
itoa
cnt
)
" [Close]: "
)
)
)
(
cond
(
(
vl-consp
pt
)
(
drawline
(
list
p1 pt
)
)
(
setq
p1 pt
)
)
(
(
=
pt
"Close"
)
(
drawline
(
list
p1 sp
)
)
(
setq
pt sp
pt
nil
)
)
)
(
setq
cnt
(
1+
cnt
)
)
)
)
(
setq
ss
(
cadr
(
ssgetfirst
)
)
)
(
princ
"
\n
**Line**"
)
(
setq
pt1
(
getpoint
"
\n
Enter first point: "
)
)
(
if
(
eq
(
type
ss
)
'PICKSET
)
;; -If there are items selected.
(
progn
(
*
error
-
push
-
vars
*
'
(
(
"CLAYER"
)
)
)
;; -Save the current layer for restoring later.
(
setvar
'CLAYER
(
getlayerfrompickedpoint pt1
)
)
)
;; -Set the current layer to item under picked point.
)
(
command
"_.regenall"
)
;; -UNSELECT selection set.
(
getpoints pt1
)
;; -Draw a line...
(
quit
)
)
Logged
TheSwamp.org
(serving the CAD community since 2003)
Member location map - Add yourself
Donate to TheSwamp.org
danAllen
Newt
Posts: 134
Re: Unselect items (selection set)
«
Reply #1 on:
September 26, 2023, 12:57:51 PM »
I think: (sssetfirst nil)
Or/also have you looked at pickfirst variable?
Logged
JohnK
Administrator
Seagull
Posts: 10661
Re: Unselect items (selection set)
«
Reply #2 on:
September 26, 2023, 01:41:15 PM »
(sssetfirst nil) worked great.
Thank you.
Logged
TheSwamp.org
(serving the CAD community since 2003)
Member location map - Add yourself
Donate to TheSwamp.org
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
Unselect items (selection set)