Tried to implement what I wrote into code? You should get the solution (commented for you) :
; Paste clip at 0,0(defun c:P0 ( / ent SS )(setq ent (entlast)) ;; attempt to obtain the last created entity from the database (command "._PASTECLIP" "0,0") ;; paste the selection from clipboard (and (setq SS (ssadd)) (cond (ent) ;; the drawing had objects, before pasteclipping - hence the last created entity was stored ( (setq ent (entnext)) (ssadd ent SS) ) ;; the drawing didn't had any objects (new drawing) - hence obtain the first entity after pasteclipping ); cond (progn (while (setq ent (entnext ent)) (ssadd ent SS)) (sssetfirst nil SS) ); progn ); and(princ (strcat "\n::" (itoa (sslength ss)) " Pasted copied objects @ 0,0 ::")) (princ)); defun c:P0
Thanks, I wasn't even close.
I will try to incorporate the UCS recognition from the code above.
; Created by 3dwannab; A lot of help by Grrr here: http://www.cadtutor.net/forum/showthread.php?103102-COPYBASE-w-0-0&p=699941&viewfull=1#post699941; INFO; 2018.03.27 - First release; 2018.03.28 - Help by Grrr to ssgetfirst the pasted items.; USAGE; Copies preselected objects or asks user to select and copies at location 0,0.; Pastes as clip at 0,0.; Pastes as block at 0,0.; COMMANDS; C0 Copies at 0,0; P0 Paste as clip at 0,0; B0 Paste as block at 0,0; Copies at 0,0(defun c:C0 ( / ss )(setq *error* SS:error)(SS:startundo)(setq cmde (getvar "cmdecho"))(setq os (getvar "osmode"))(setvar 'cmdecho 0)(setvar 'osmode 0)(progn (setq ss (last (ssgetfirst))) (if (not ss) (setq ss (ssget)) ) (if ss (progn (command "._COPYBASE" "0,0" ss "") (princ (strcat "\n >>> " (itoa (setq len (sslength ss))) (if (> len 1) " items" " item") " copied @ 0,0 > " (itoa (setq len (sslength ss))) (if (> len 1) " items" " item") " pasted @ 0,0 > " (itoa (setq len (sslength ss))) (if (> len 1) " items" " item") " pasted to block definition @ 0,0 FWIW for the PASTEBLOCK you don't need the same approach:
; Paste block at 0,0(defun c:B0 ( / ent i )(command "._PASTEBLOCK" "0,0")(princ) ;; paste the selection from clipboard (and (setq ent (entlast)) (sssetfirst nil (ssadd ent)) (not (vl-catch-all-error-p (setq i (vl-catch-all-apply 'eval '( (vla-get-Count (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-get-EffectiveName (vlax-ename->vla-object ent)) ); vla-Item ); vla-get-Count ) ); vl-catch-all-apply 'eval ); setq i ); vl-catch-all-error-p ); not (princ (strcat "\n >>> " (itoa i) (if (> i 1) " items" " item") " pasted to block definition @ 0,0 Sweet Grrr! That was quick! Alternative:
My 3 CUIX Drop-downs for Copy includes the custom macro "Copy with 0,0 as Base Point"
Macro:
$M=$(if,$(eq,$(substr,$(getvar,cmdnames),1,,GRIP),_copybase,^C^C_copybase) _non 0,0
My 6 CUIX Drop-downs for Paste includes the custom macro "Paste as Group"
Macro:
^C^C_pasteblock;\(setq LstBlk(vla-get-Name (vlax-ename->vla-object (entlast))));_explode;_last;_-group;_create;*;;_previous;;(command "-purge" "B" LstBlk "N")(setq LstBlk nil)
http://www.cadtutor.net/forum/showthread.php?91042-copy-and-keep-grouped-objects-to-new-dwg&p=625603&viewfull=1#post625603
It Pastes as Block, explodes the Block, creates a group of the exploded objects, then purges that block leaving only the group. Nice.
BTW, your signature is the best piece of advice out there.
I'm getting the error: >
Is it good practice to do:
(setq ss nil)
So the top code looks like (see 3 lines from bottom):
; Paste clip at 0,0(defun c:P0 ( / ent SS )(setq ent (entlast)) ;; attempt to obtain the last created entity from the database (command "._PASTECLIP" "0,0") ;; paste the selection from clipboard (and (setq SS (ssadd)) (cond (ent) ;; the drawing had objects, before pasteclipping - hence the last created entity was stored ( (setq ent (entnext)) (ssadd ent SS) ) ;; the drawing didn't had any objects (new drawing) - hence obtain the first entity after pasteclipping ); cond (progn (while (setq ent (entnext ent)) (ssadd ent SS)) (sssetfirst nil SS) ); progn ); and(princ (strcat "\n::" (itoa (sslength ss)) " Pasted copied objects @ 0,0 ::"))(setq ss nil) (princ)); defun c:P0 You'll probably want to exclude subentities from the set, and account for the last entity prior to issuing PASTECLIP also having subentities, e.g.:
(defun c:p0 ( / ent sel tmp ) (setq ent (entlast) sel (ssadd) ) (while (setq tmp (entnext ent)) (setq ent tmp)) (command "_.pasteclip" "_non" '(0 0)) (while (setq ent (entnext ent)) (or (member (cdr (assoc 0 (entget ent))) '("ATTRIB" "VERTEX" "SEQEND")) (ssadd ent sel) ) ) (sssetfirst nil sel) (princ)) Thanks,
I'll try this with the (setq ss nil) and see how it goes.
Is that the solution or is yours the way to go?
I'm only aware of this error, when you try few times to obtain the active selection set via activex without deleting it.
Are you sure that you get the error because of this particular code?
BTW, yea I didn't excluded the subentities, like Lee pointed out.
页:
1
[2]