vanowm Posted March 15, 2015 Share Posted March 15, 2015 (edited) Hello. *me again with stupid questions about selection set * Using AutoCAD2000i. I need to select or at least get list of entities of the object's copies after they were copied. I found an ancient topic regarding this on another forum and one of the proposed solutions by eddyhgng was to use move command: (setq sel (ssget)) (command "copy" sel "" "0,0" "0,0" "move" "P" "" pause pause) (setq sel2 (ssget "p")) At least in ACAD2k it didn't quiet work, it doesn't finish move command, so I replaced it with: (setq sel (ssget)) (command "copy" sel "" "0,0" "0,0" "move" "P" "" "0,0" "@") (setq sel2 (ssget "p")) Unfortunately sel2 would still contain same original objects as sel variable. Another proposed solution by CAB2k was to get latest object in drawing before the copy and then get list of newly added objects after it: ;;============================================================ ; Rune Wold and Michael Puckett - modified ; e.g. usage (setq marker (ALE_LASTENT)) ;; Function to get the absolute last entity in the database ;; Returns nil is drawing is completely empty (defun ALE_LastEnt ( / EntNam OutVal) (and (setq OutVal (entlast)); if there is an entity in drawing (while (setq EntNam (entnext OutVal)) (setq OutVal EntNam) ) ) OutVal ) ;;============================================================ ;; Function to get new items after EntNam in the database (defun ALE_Ss-After (EntNam / EntNxt SelSet) (cond ( (not EntNam) (ssget "_X") ); dwg was empty ( (setq EntNxt (entnext EntNam)); get new items (setq SelSet (ssadd EntNxt)) (while (setq EntNxt (entnext EntNxt)) (if (entget EntNxt) (ssadd EntNxt SelSet)) ) SelSet ) ) ) ;========================================================= ;;===================================================================== ;;=================== Code to get New objects ======================== ;;===================================================================== (setq elast (ALE_LastEnt)); get last entity in database (setq newbies (ssadd)) ; create an empty selection set ;; ;; Do your array or paste command ;; (setq newbies (ALE_Ss-After elast)) ;; newbies is a selection set of all items created by your command. ;;===================================================================== Unfortunately this method returns list of parts the copied objects are made out of (tested on ruled surfaces it would return entities for 3DPolyLines that they made out of) Any more ideas how to achieve this? Thank you. Edited March 15, 2015 by vanowm Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 15, 2015 Share Posted March 15, 2015 An easier option would be to use the Visual LISP ActiveX copy method on the vla-object representation of every object in the selection set, and then collect a list or selection set of the objects returned by this method; but if you wanted to continue using the standard AutoCAD COPY command, you could use the following method to retrieve the entities created by this command: [color=GREEN];; Define function & declare local variables[/color] ([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] ent new sel tmp ) [color=GREEN];; Prompt user for selection of objects[/color] ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] [color=MAROON]"_:L"[/color])) ([color=BLUE]progn[/color] [color=GREEN];; Retrieve last primary entity added to the database[/color] ([color=BLUE]setq[/color] ent ([color=BLUE]entlast[/color])) [color=GREEN];; Retrieve last subentity (if applicable)[/color] ([color=BLUE]while[/color] ([color=BLUE]setq[/color] tmp ([color=BLUE]entnext[/color] ent)) ([color=BLUE]setq[/color] ent tmp)) [color=GREEN];; Copy selected objects[/color] ([color=BLUE]command[/color] [color=MAROON]"_.copy"[/color] sel [color=MAROON]""[/color] [color=MAROON]"_non"[/color] '(0 0) [color=MAROON]"_non"[/color] '(0 0)) [color=GREEN];; Create new selection set for copied objects[/color] ([color=BLUE]setq[/color] new ([color=BLUE]ssadd[/color])) [color=GREEN];; Iterate over new objects added to database[/color] ([color=BLUE]while[/color] ([color=BLUE]setq[/color] ent ([color=BLUE]entnext[/color] ent)) [color=GREEN];; Add primary object to new selection set[/color] ([color=BLUE]ssadd[/color] ent new) [color=GREEN];; If subentities follow[/color] ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 66 ([color=BLUE]entget[/color] ent)))) [color=GREEN];; Iterate over subentities until SEQEND entity is reached[/color] ([color=BLUE]while[/color] ([color=BLUE]/=[/color] [color=MAROON]"SEQEND"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] ent)))) ([color=BLUE]setq[/color] ent ([color=BLUE]entnext[/color] ent)) ) ) ) [color=GREEN];; Highlight copied objects[/color] ([color=BLUE]sssetfirst[/color] [color=BLUE]nil[/color] new) ) ) [color=GREEN];; Suppress return of last evaluated expression[/color] ([color=BLUE]princ[/color]) ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.