乐筑天下

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

[编程交流] AMOVE from ASMI: selectable at

[复制链接]

11

主题

117

帖子

133

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
52
发表于 2022-7-6 14:16:56 | 显示全部楼层 |阅读模式
First of all Thanks ASMI for the AMOVE lisp.  It works great.  Now is it possible to modify it so that I can pick certain attributes to move inside the block and not all the attributes.
ie: I have a block with many attributes, I want to pick some attributes to align to left and some attributes to align to the right of the block(s) depending on space avalible on the drawing itself.
Here's the code written by ASMI.  Great code ASMI!
  1. ;; ==================================================================== ;;;;                                                                      ;;;;  AMOVE.LSP - Moves multiple attributes simultaneously                ;;;;                                                                      ;;;; ==================================================================== ;;;;                                                                      ;;;;  Command(s) to call: AMOVE                                           ;;;;                                                                      ;;;;  Select multuple blocks and move all attributes simultaneously.      ;;;;                                                                      ;;;; ==================================================================== ;;;;                                                                      ;;;;  THIS PROGRAM AND PARTS OF IT MAY REPRODUCED BY ANY METHOD ON ANY    ;;;;  MEDIUM FOR ANY REASON. YOU CAN USE OR MODIFY THIS PROGRAM OR        ;;;;  PARTS OF IT ABSOLUTELY FREE.                                        ;;;;                                                                      ;;;;  THIS PROGRAM PROVIDES 'AS IS' WITH ALL FAULTS AND SPECIFICALLY      ;;;;  DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS        ;;;;  FOR A PARTICULAR USE.                                               ;;;;                                                                      ;;;; ==================================================================== ;;;;                                                                      ;;;;  V1.0, 14th Julay 2007, Riga, Latvia                                 ;;;;  © Aleksandr Smirnov (ASMI)                                          ;;;;  For AutoCAD 2000 - 2008 (isn't tested in a next versions)           ;;;;                                                                      ;;;;                             http://www.asmitools.com                 ;;;;                                                                      ;;;; ==================================================================== ;;(defun c:amove(/ atSet actDoc atLst actSp curTxt         aFlg laySt mDel bPt dPt *error*) (vl-load-com) (defun *error*(msg)   (if tSet     (progn         (setvar "CMDECHO" 0)         (command "_.erase" tSet "")         (setvar "CMDECHO" 1)       ); end progn     ); end if   (if laySt      (asmi-LayersStateRestore laySt)     ); end if   (if actDoc      (vla-EndUndoMark actDoc)      ); end if    (princ)   ); end of *error*  (defun asmi-LayersUnlock(/ restLst)  (setq restLst '())    (vlax-for lay(vla-get-Layers     (vla-get-ActiveDocument       (vlax-get-acad-object)))         (setq restLst           (append restLst             (list               (list                lay                 (vla-get-Lock lay)                ); end list              ); end list            ); end append          ); end setq       (vla-put-Lock lay :vlax-false)     ); end vlax-for  restLst ); end of asmi-LayersUnlock  (defun asmi-LayersStateRestore(StateList)   (foreach lay StateList     (vla-put-Lock(car lay)(cadr lay))    ); end foreach   (princ) ); end of asmi-LayersStateRestore  (defun asmi-GetAttributes(Block / atArr caArr)  (append    (if      (not        (vl-catch-all-error-p          (setq atArr(vl-catch-all-apply 'vlax-safearray->list            (list(vlax-variant-value                    (vla-GetAttributes Block)))))))          atArr); end if    (if      (not        (vl-catch-all-error-p          (setq caArr(vl-catch-all-apply 'vlax-safearray->list            (list              (vlax-variant-value                (vla-GetConstantAttributes Block)))))))            caArr); end if     ); end append   ); end asmi-GetAttributes  (defun asmi-GetActiveSpace(/ actDoc)   (setq actDoc          (vla-get-ActiveDocument             (vlax-get-acad-object)))       (if(= 1(getvar "TILEMODE"))          (vla-get-ModelSpace actDoc)           (vla-get-PaperSpace actDoc)        ); end if     ); end of asmi-GetActiveSpace (princ "\n> ") (if   (setq atLst(ssget '((0 . "INSERT")(66 . 1))))   (progn     (setq atLst(apply 'append                  (mapcar 'asmi-GetAttributes                    (mapcar 'vlax-ename->vla-object                      (vl-remove-if 'listp                        (mapcar 'cadr(ssnamex atLst)))))                    ); end apply           tSet(ssadd)           actSp(asmi-GetActiveSpace)           laySt(asmi-LayersUnlock)    actDoc(vla-get-ActiveDocument            (vlax-get-acad-object))            ); end setq  (vla-StartUndoMark actDoc)  (foreach att atLst      (setq curTxt         (vla-AddText actSp "Text"           (vlax-3D-point '(0.0 0.0 0.0))1.0))             (ssadd(vlax-vla-object->ename curTxt)tSet)               (foreach pr '("TextString" "StyleName" "Height"                      "ScaleFactor" "Backward" "ObliqueAngle"                      "UpsideDown" "Rotation" "Color" "Layer"                      "Linetype" "Lineweight" "Alignment")                  (vlax-put-Property curTxt pr                      (vlax-get-Property att pr))                ); end foreach    (cond      ((= 0(vla-get-Alignment att))         (vla-put-InsertionPoint curTxt           (vla-get-InsertionPoint att))             (setq aFlg "InsertionPoint")        ); end condition #1      ((member(vla-get-Alignment att) '(3 5))         (vla-put-InsertionPoint curTxt           (vla-get-InsertionPoint att))         (vla-put-TextAlignmentPoint curTxt           (vla-get-TextAlignmentPoint att))         (vla-put-ScaleFactor curTxt           (vla-get-ScaleFactor att))           (setq aFlg "InsertionPoint")         ); end condition #2      ((not(member(vla-get-Alignment att)'(0 3 5)))          (vla-put-TextAlignmentPoint curTxt            (vla-get-TextAlignmentPoint att))            (setq aFlg "TextAlignmentPoint")         ); end condition #3       ); end cond    ); end foreach     (command "_.move" tSet "" pause pause)     (setq mDel        (mapcar '-          (vlax-get            (vlax-ename->vla-object              (ssname tSet(1-(sslength tSet))))aFlg)                (vlax-get(last atLst) aFlg)         ); end mapcar       ); end setq     (foreach att atLst        (setq bPt(vlax-get att aFlg)              dPt(mapcar '+ bPt mDel)              ); end setq        (vla-Move att(vlax-3d-Point bPt)(vlax-3d-Point dPt))       ); end foreach        (setvar "CMDECHO" 0)        (command "_.erase" tSet "")        (setvar "CMDECHO" 1)        (asmi-LayersStateRestore laySt)        (vla-EndUndoMark actDoc)      ); end progn    ); end if (princ) ); end of c:amove(princ "\n[info] http:\\\\www.AsmiTools.com [info]")(princ "\n[info] Type AMOVE to move multiple attributes at once. [info]")
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 14:21:59 | 显示全部楼层
This will work on individual Blocks, let me know if you had something else in mind
 
  1. (defun c:amove2 (/ *error* lklst ent Obj bPt gr) (vl-load-com) (defun *error* (msg)   (vla-EndUndoMark     (vla-get-ActiveDocument       (vlax-get-acad-object)))   (if lklst     (foreach l lklst       (vla-put-lock         (car l) (cdr l))))   (if (not         (wcmatch           (strcase msg)             "*BREAK,*CANCEL*,*EXIT*"))     (princ       (strcat "\n>")))   (redraw)   (princ))            (vlax-for l   (vla-get-layers     (vla-get-ActiveDocument       (vlax-get-acad-object)))   (setq lklst     (cons       (cons l         (vla-get-lock l)) lklst))   (vla-put-lock l :vlax-false)) (while   (progn     (setq ent       (car (nentsel "\nSelect Attribute: ")))     (cond       ((eq 'ENAME (type ent))        (if          (not            (eq "ATTRIB"                (cdr (assoc 0 (entget ent)))))          (princ "\n** Object is not an Attribute **")          nil))       (t (princ "\n** Nothing Selected **"))))) (setq Obj (vlax-ename->vla-object ent)       bPt (vlax-safearray->list             (vlax-variant-value               (vla-get-InsertionPoint Obj))))  (vla-StartUndoMark   (vla-get-ActiveDocument     (vlax-get-acad-object))) (while       (and         (setq gr           (grread t 13 0))         (eq 5 (car gr)))   (redraw)   (vla-move Obj     (vla-get-InsertionPoint Obj)       (vlax-3D-point (cadr gr)))   (grdraw bPt (cadr gr) 3 1)) (vla-EndUndoMark   (vla-get-ActiveDocument     (vlax-get-acad-object))) (foreach l lklst   (vla-put-lock     (car l) (cdr l))) (redraw) (princ))
回复

使用道具 举报

11

主题

117

帖子

133

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
52
发表于 2022-7-6 14:27:04 | 显示全部楼层
Thx LeeMac, I'll have to try your code once I get back to work. I'm on holiday for a week.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 14:34:53 | 显示全部楼层
Another option:
 
This will move multiple attributes by tag:
 
  1. ;; ============ Amove2.lsp ===============;;;;  FUNCTION:;;  Will move Multiple Attribute Tags;;;;  SYNTAX: AMOVE2;;;;  AUTHOR:;;  Copyright (c) 2009, Lee McDonnell;;  (Contact Lee Mac, CADTutor.net);;;;  VERSION:;;  1.0  ~  28.06.2009;;;; ====================================(defun c:amove2 (/ *error* lklst ent Blk                  Obj bNme ss bPt ObjLst) (vl-load-com) (defun *error* (msg)   (vla-EndUndoMark     (vla-get-ActiveDocument       (vlax-get-acad-object)))   (if lklst     (foreach l lklst       (vla-put-lock         (car l) (cdr l))))   (if (not         (wcmatch           (strcase msg)             "*BREAK,*CANCEL*,*EXIT*"))     (princ       (strcat "\n>")))   (redraw)   (princ))            (vlax-for l   (vla-get-layers     (vla-get-ActiveDocument       (vlax-get-acad-object)))   (setq lklst     (cons       (cons l         (vla-get-lock l)) lklst))   (vla-put-lock l :vlax-false)) (while   (progn     (setq ent       (car (nentsel "\nSelect Attribute: ")))     (cond       ((eq 'ENAME (type ent))        (if          (not            (eq "ATTRIB"                (cdr (assoc 0 (entget ent)))))          (princ "\n** Object is not an Attribute **")          nil))       (t (princ "\n** Nothing Selected **"))))) (setq Blk   (vla-ObjectIdtoObject     (vla-get-ActiveDocument       (vlax-get-acad-object))     (vla-get-OwnerId       (setq Obj         (vlax-ename->vla-object ent))))) (setq bNme   (if (vlax-property-available-p Blk 'EffectiveName)     (vla-get-EffectiveName Blk)       (vla-get-Name Blk))) (setq ss   (ssget "_X" (list (cons 0 "INSERT")                       (cons 2 bNme)                         (cons 66 1)))) (if (setq bPt (getpoint "\nSelect Base Point: "))   (progn     (vla-StartUndoMark       (vla-get-ActiveDocument         (vlax-get-acad-object)))     (setq ObjLst       (vl-remove-if-not         (function           (lambda (x)             (eq (vla-get-TagString x)                 (vla-get-TagString Obj))))         (apply 'append           (mapcar 'asmi-GetAttributes             (mapcar 'vlax-ename->vla-object               (mapcar 'cadr (ssnamex ss)))))))     (lmac-ss-drag-move       "\nMove Attributes" ObjLst bPt t)     (vla-EndUndoMark       (vla-get-ActiveDocument         (vlax-get-acad-object)))))  (foreach l lklst   (vla-put-lock     (car l) (cdr l))) (princ)) ;;Asmi(defun asmi-GetAttributes (Block / atArr caArr)  (append    (if      (not        (vl-catch-all-error-p          (setq atArr            (vl-catch-all-apply              'vlax-safearray->list            (list              (vlax-variant-value                (vla-GetAttributes Block)))))))          atArr)    (if      (not        (vl-catch-all-error-p          (setq caArr            (vl-catch-all-apply              'vlax-safearray->list            (list              (vlax-variant-value                (vla-GetConstantAttributes Block)))))))            caArr)))  ;; Ghosting Example, by Lee McDonnell(defun lmac-ss-drag-move (msg ss pt hi  / oBjLst MiP MaP                                         bsvec cPLst gr) (vl-load-com) (if msg   (prompt     (strcat       (if (not (vl-string-search "\n" msg))         "\n""") msg))) (or (and (listp ss) (setq OBjLst ss))     (setq oBjLst       (mapcar 'vlax-ename->vla-object         (vl-remove-if 'listp           (mapcar 'cadr             (ssnamex ss)))))) (vla-getBoundingBox   (car oBjLst) 'MiP 'MaP)     (setq bsvec       (mapcar '-         (vlax-safearray->list MiP) pt));;;  (mapcar;;;    (function;;;      (lambda (x);;;        (vla-highlight x :vlax-true)));;;          (setq cpLst;;;            (mapcar 'vla-copy oBjLst))) (while       (eq 5         (car           (setq gr (grread 't )))             (redraw)     (if       (and         (eq 5 (car gr))           (listp (cadr gr)))       (progn         (vla-getBoundingBox           (car oBjLst) 'MiP 'MaP)             (mapcar               (function                 (lambda (x)                   (vla-move x                     (vlax-3D-point                       (mapcar '-                         (vlax-safearray->list MiP) bsVec))                           (vlax-3D-point                             (cadr gr)))))                               oBjLst)         (if hi           (grdraw pt (cadr gr) 3 1)))));;;  (mapcar;;;    (function;;;      (lambda (x);;;        (vl-catch-all-apply;;;          'vla-delete;;;            (list x)))) cpLst) (redraw))
 
I have also updated the code in my first post to add some features.
回复

使用道具 举报

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 14:40:00 | 显示全部楼层
Thank you very much for amove2
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 14:42:49 | 显示全部楼层
 
Your welcome, I'm glad you like it
回复

使用道具 举报

59

主题

327

帖子

268

银币

后起之秀

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

铜币
295
发表于 2022-7-6 14:47:04 | 显示全部楼层
Lee,
 
I just tried the code above. Very good job, I had to say that !!
Imagine, I was just curious if you'd done some lisping lately... and yup, you did.
Nice one, I'll keep that one in mind for I might have a use for it sometime.
 
Regards,
Marco
回复

使用道具 举报

15

主题

335

帖子

322

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 14:52:03 | 显示全部楼层
 
Again and again, Lee Mac to the rescue!
 
Great lisp work, as always!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 14:55:27 | 显示全部楼层
 
 
Thanks guys
回复

使用道具 举报

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 15:01:24 | 显示全部楼层
I added the following code at the beginning and end:
 
;--------------------------------------------------            
;save current UCS
(setq mUCS (getvar "UCSNAME"))
(command "_UCS" "")
;--------------------------------------------------            
 
;...(the code).........
 
;--------------------------------------------------            
;restore UCS
(command "UCS" "r" mUCS )
;--------------------------------------------------            
 
Regards, ArqStaad
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-5 03:06 , Processed in 0.599557 second(s), 72 queries .

© 2020-2025 乐筑天下

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