乐筑天下

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

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

[复制链接]

35

主题

145

帖子

114

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
180
发表于 2022-7-5 15:24:45 | 显示全部楼层 |阅读模式
I wrote 2 lisp routines, but they do not work well.  One is to do a copybase at 0,0 and the other is to paste at 0,0.
 
  1. ; ==================================================================================================(defun c:cpz ()  (command "_copybase" "0,0" "")  (princ));_defun; ==================================================================================================(defun c:pcz ()  (command "pasteclip" "0,0" "")  (princ));_defun; ==================================================================================================
How can I improve the code?
 
Greg
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 15:28:56 | 显示全部楼层
Here are some minor improvements:
  1. (defun c:cpz ( / s )   (if (setq s (ssget)) (command "_.copybase" "_non" '(0 0) s ""))   (princ))(defun c:pcz ( )   (command "_.pasteclip" "_non" '(0 0))   (princ))
回复

使用道具 举报

35

主题

145

帖子

114

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
180
发表于 2022-7-5 15:32:41 | 显示全部楼层
 
Beautiful!  Thank you, Sir!
 
Greg
回复

使用道具 举报

35

主题

145

帖子

114

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
180
发表于 2022-7-5 15:37:25 | 显示全部楼层
 
I think I understand everything but the "_non".  What function does that do?
 
Greg
回复

使用道具 举报

58

主题

3353

帖子

33

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1761
发表于 2022-7-5 15:38:58 | 显示全部楼层
This is what I use:
  1. ;; Copy items to clip board @ 0,0,0(defun c:cb (/ ss) (setvar 'cmdecho 0) (if (setq ss (ssget ":L"))   (progn (if (= 1.0 (car (getvar 'ucsxdir)))     (command "_.copybase" '(0 0 0) ss "")     (progn (command "_.ucs" "world")            (command "_.copybase" '(0 0 0) ss "")            (command "_.ucs" "view")     )   )   (princ (strcat "\n" (itoa (sslength ss)) " items copied to clip board..."))   ) ) (setvar 'cmdecho 1) (princ));; Paste items copied to clip board @ 0,0,0(defun c:cv nil (setvar 'cmdecho 0) (if (= 1.0 (car (getvar 'ucsxdir)))   (command "_.pasteclip" '(0 0 0))   (progn (command "_.ucs" "world") (command "_.pasteclip" '(0 0 0)) (command "_.ucs" "view")) ) (setvar 'cmdecho 1) (princ))
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 15:43:23 | 显示全部楼层
Its to ignore all your OSNAP settings.
回复

使用道具 举报

35

主题

145

帖子

114

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
180
发表于 2022-7-5 15:46:07 | 显示全部楼层
 
Ahhhhh.  Ok, thank you.  It makes sense.
 
Greg
回复

使用道具 举报

56

主题

256

帖子

230

银币

后起之秀

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

铜币
253
发表于 2022-7-5 15:50:00 | 显示全部楼层
I was just about to post something very similar so forgive me if I post in here.
 
My problem is that I would like to sssetfirst the pasted objects to select them after I paste, should I need to change then straight away in the new drawing or whatnot.
 
  1. (setq ent (entlast))(sssetfirst nil ent)
Doesn't work in the below code.
 
  1. ; Created by 3dwannab; INFO; 2018.03.27        -        First release; 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 ":: Copied selected objects @ 0,0 ::")                        )                (princ "\nUser Cancelled Command")                )        )(*error* nil)(princ)); Paste clip at 0,0(defun c:P0 ( / ent )(command "._PASTECLIP" "0,0");; Won't select newly created objects. Is there a way round this?(setq ent (entlast))(sssetfirst nil ent)(princ (strcat "\n::" (itoa (sslength ss)) " Pasted copied objects @ 0,0 ::"))); Paste block at 0,0(defun c:B0 ( / )(command "._PASTEBLOCK" "0,0")(princ)(princ (strcat "\n::" (itoa (sslength ss)) " Pasted copied objects to block definition @ 0,0 ::")))(defun SS:error (errmsg)(and acDoc (vla-EndUndoMark acDoc))(and errmsg        (not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))        (princ (strcat "\n>"))        )(setvar 'cmdecho cmde)(setvar 'osmode os))(defun SS:startundo ()(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc)))(princ(strcat        "\n:: 3dwannab_Copy_0_Paste_0.lsp Loaded ::"        "\n:: Invoke by typing 'C0' 'P0' 'B0' ::"        ))(princ);;----------------------------------------------------------------------;;;;                             End of File                              ;;;;----------------------------------------------------------------------;;
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 15:52:28 | 显示全部楼层
  1. ; Paste clip at 0,0(defun c:P0 ( / ent )(command "._PASTECLIP" "0,0") ;; Won't select newly created objects. Is there a way round this?(setq ent (entlast))
 
Flanders, before 'pasteclipping' into the new drawing you have to store initially the last created entity(if theres one).
Then you must iterate from it using entnext, and store these enames into your customly created selection set.
And in the end just grip it with sssetfirst.
回复

使用道具 举报

56

主题

256

帖子

230

银币

后起之秀

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

铜币
253
发表于 2022-7-5 15:54:42 | 显示全部楼层
lol. 
I think I'm close, but struggling now. Tried everything. I'm sure with these two fns by CAB I can achieve what I'm after.
 
Just lost ATM.
 
  1. ; Paste clip at 0,0(defun c:P0 ( / LastEntInDatabase)(command "._COPYBASE" "0,0" pause "")(command "._PASTECLIP" "0,0")(setq LastEntInDatabase (GetLastEnt))(sssetfirst nil (GetNewEntities LastEntInDatabase));;  CAB - get last entity in datatbase(defun GetLastEnt ( / ename result )        (if (setq result (entlast))                (while (setq ename (entnext result))                        (setq result ename)                        )                )        result        );;===================================;;  CAB - return a list of new enames(defun GetNewEntities (ename / new)        (cond                ((null ename) (alert "Ename nil"))                ((eq 'ENAME (type ename))                        (while (setq ename (entnext ename))                                (if (entget ename) (setq new (cons ename new)))                                )                        )                ((alert "Ename wrong type."))                )        new        ))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-14 21:05 , Processed in 0.506362 second(s), 72 queries .

© 2020-2025 乐筑天下

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