I want to execute a command within a lisp routine, and then select all entities created by the command.You could just keep track of the entities you're creating in your routine, then you don't have to select them again?
...
(defun _SSAfter ( ename / ss d e )
(if (eq 'ename (type ename))
(progn
(setq
ss (ssadd)
e (entnext ename)
)
(while e
(if
(and
(setq d (entget e))
(null (member (cdr (assoc 0 data)) '("VERTEX" "ATTRIB" "SEQEND")))
)
(ssadd e ss)
)
(setq e (entnext e))
)
(if
(and
(eq 'pickset (type ss))
(< 0 (sslength ss))
)
ss
)
)
)
)
An entity filter list is an association list that uses DXF group codes in the same format as a list returned by entget. (See the DXF Reference for a list of group codes.) The ssget function recognizes all group codes except entity names (group –1), handles (group 5), and xdata codes (groups greater than 1000). If an invalid group code is used in a filterlist, it is ignored by ssget.
I should have clarified in the original post that I didn't want to write a routine that creates specific new entities. I wanted the routine to execute a normal COPY or MIRROR command (with the selection set and displacement or mirror line specified at run time), except that when it's done all the newly created entities are selected for use in the next command.
Good eye and commentary regarding attempts to grab seqends. When I wrote that function it was to harvest entities created by flattening processes by reverse engineered dxb files or wmfin exploits (essentially all simple primitives). Revised function to harvest only primary entities. Thanks Lee.
....if the entity returned by (entlast) is a complex entity (such as an attributed block or 3D polyline), the subsequent calls to (entnext) will return the subentities which follow the parent entity (i.e. the attribute references or 3D polyline vertices respectively). For this reason, I suggested the lastent function that I posted above, which will return the last entity in the drawing database for which a call to (entnext) will return nil.Does that mean that (lastent) returns the last non-complex entity? If so, what if there's a newer entity that is complex? What keeps that newer complex entity from being included in the final selection set? I see where you skip over the sub-entities, but where do you skip over a complex entity that's newer than the last non-complex entity?
Lee Mac, thanks so much for the revised function, which does exactly what I want, and especially for the remarks included with it.
I tried to adapt it to make an equivalent Mirror command, but this always terminates with nothing selected. What did I do wrong?
And I hate to be greedy, but there are a couple of things I still don't understand:
1.....if the entity returned by (entlast) is a complex entity (such as an attributed block or 3D polyline), the subsequent calls to (entnext) will return the subentities which follow the parent entity (i.e. the attribute references or 3D polyline vertices respectively). For this reason, I suggested the lastent function that I posted above, which will return the last entity in the drawing database for which a call to (entnext) will return nil.Does that mean that (lastent) returns the last non-complex entity? If so, what if there's a newer entity that is complex? What keeps that newer complex entity from being included in the final selection set? I see where you skip over the sub-entities, but where do you skip over a complex entity that's newer than the last non-complex entity?
2. What's that rtn all by itself at the end of the (lastent) function) It's not part of any expression other than the (defun) function, so I'm surprised it's even allowed in (defun sym ([arguments] [/ variables ...]) expr ...). And what does it do?
I left out the third input to the Mirror command because I wanted to be able to specify yes or no at run time. I didn't realize that would mess up the building of the new selection set. I guess I have to prompt for the two clicks and the yes or no and then pass all the input to the Mirror command.
But with the following code, answering Yes suppresses the creation of a new selection set. I only get a selection set on termination if I answer N or Enter. Can you see what I did wrong?
.... I tend to avoid using AutoCAD commands in my code, as you become reliant on the behaviour of the command under each condition.
I've been re-reading the earlier discussion between you and MP and I have a question about that: It sounds like the only problem with MP's (_ssAfter) function is that it might try to add a SEQEND to a selection set, and that would fail and the function would return nil. If that's the only problem, wouldn't it be easy to protect against that possibility by checking to see (if (/= "SEQEND" (cdr (assoc 0 (entget e))))) before adding each entity?