乐筑天下

帖子
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: GregGleason

[编程交流] COPYBASE w/ 0,0

[复制链接]

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 15:56:38 | 显示全部楼层
 
Tried to implement what I wrote into code? You should get the solution (commented for you) :
 
  1. ; 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
 
回复

举报

56

主题

256

帖子

230

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
253
发表于 2022-7-5 16:01:36 | 显示全部楼层
Thanks, I wasn't even close.
 
I will try to incorporate the UCS recognition from the code above.
 

[code]; 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
回复

举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 16:03:49 | 显示全部楼层
FWIW for the PASTEBLOCK you don't need the same approach:
 

[code]; 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
回复

举报

56

主题

256

帖子

230

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
253
发表于 2022-7-5 16:06:32 | 显示全部楼层
Sweet Grrr! That was quick!
回复

举报

17

主题

1274

帖子

25

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
260
发表于 2022-7-5 16:10:13 | 显示全部楼层
Alternative:
My 3 CUIX Drop-downs for Copy includes the custom macro "Copy with 0,0 as Base Point"
Macro:
  1. $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:
  1. ^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.
回复

举报

56

主题

256

帖子

230

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
253
发表于 2022-7-5 16:13:19 | 显示全部楼层
Nice.
 
BTW, your signature is the best piece of advice out there.
回复

举报

56

主题

256

帖子

230

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
253
发表于 2022-7-5 16:17:21 | 显示全部楼层
 
I'm getting the error: >
 
Is it good practice to do:
  1. (setq ss nil)
 
So the top code looks like (see 3 lines from bottom):
  1. ; 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
回复

举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:21:11 | 显示全部楼层
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.:
  1. (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))
回复

举报

56

主题

256

帖子

230

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
253
发表于 2022-7-5 16:23:54 | 显示全部楼层
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?
回复

举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 16:27:50 | 显示全部楼层
 
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.
回复

举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁體中文

GMT+8, 2025-3-15 09:02 , Processed in 1.222631 second(s), 81 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表