View Full Version : Subentity Selection
bweir
2007-04-16, 05:23 PM
I'm trying to use the (ssget ) to select sub entities. Reading through the help documentation I would have thought the following code would work.
(setq PtA (getpoint "nSelect a point: "))
(setq PtB (getcorner PtA "nSelect corner: "))
(setq Selection (ssget "W:V" PtA PtB))
What am I doing wrong here? The selection always comes back as nil.
kennet.sjoberg
2007-04-16, 05:36 PM
. . . What am I doing wrong here?
There is no "W:V" option
Try plain (setq Selection (ssget))
or
(setq Selection (ssget "_W" PtA PtB ) )
: ) Happy Computing !
kennet
shawn.bean
2007-04-16, 05:42 PM
Let's assume there is only one entity with sub-entities in the window you are selecting (we'll use blocks as an example):
(defun testit ()
(setq PtA (getpoint "nSelect a point: "))
(setq PtB (getcorner PtA "nSelect corner: "))
(setq Selection (ssget "W" PtA PtB '((0 . "INSERT")) )) ;this will filter for insertions of the block
(setq InsertEName (ssname Selection 0)) ;get the INSERT's entity name
(setq SubEntEName (entnext InsertEName)) ;get the entity name for the first sub-entity
(setq SubEntEList (entget SubEntEName)) ;get the entity list for the first sub-entity
(setq SubEntDescr (cdr (assoc 0 SubEntEList))) ;what is the sub-entity (ATTRIB or SEQEND)
(princ (strcat "\n" SubEntDescr)) ;tell us what the sub-entity is
(while (/= SubEntDescr "SEQEND") ;keep going until the end of the BLOCK definition
(progn
(setq SubEntEName (entnext SubEntEName))
(setq SubEntEList (entget SubEntEName)) ;do it all over again
(setq SubEntDescr (cdr (assoc 0 SubEntEList)))
(princ (strcat "\n" SubEntDescr))
) ;endprogn
) ;endwhile
)
Note that this only gets the ATTRIBs of an INSERT; to find the individual component entities (lines, arcs, text, attdefs, etc.) of the block, you'd have to go to the block definition in the BLOCK table. Polylines used to be handled similarly, with vertex sub-entities, but LWPolyines hold their vertices in their own entity lists.
Is that sort of what you're looking for?
bweir
2007-04-16, 07:07 PM
kennet,
According to the AutoCAD Lisp Help doc these are the selections methods.
C
CP
F
I
L
P
W
WP
X
:E
:N
:S
:U
:V
bweir
2007-04-16, 07:15 PM
Thanks shawn,
I was hoping that the code would be a little simpler. I need to select every object on a certain layer. These objects might be in blocks or in model space or paper space, any where. If I can't do this simply with an (ssget ) I was thinking that I'd just iterate each block definition an look for anything on the layer.
bweir
2007-04-16, 08:01 PM
Shawn, should the (ssnext ) function actually be the (entnext ) function? The (ssnext ) function is undefined on my computer.
(setq SubEntEName (ssnext InsertEName)) ;get the entity name for the first sub-entity
kennet.sjoberg
2007-04-16, 08:06 PM
kennet,
According to the AutoCAD Lisp Help doc these are the selections methods.
Thank you for the information, but in witch versions will you find the option :V and :U ?
: ) Happy Computing !
kennet
...hmm I suppose in 2007+
shawn.bean
2007-04-16, 08:22 PM
Shawn, should the (ssnext ) function actually be the (entnext ) function? The (ssnext ) function is undefined on my computer.
Yup; my bad. Thanks for checking me on that; I'll edit the original post to reflect the correction.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.