http://bbs.mjtd.com/forum.php?mod=viewthread&tid=181585&highlight=%BE%D3%D6%D0

    1. ;对象居中:by zml84 2009-06-15 此基础上修改:by 忘霄
    2. (defun C:EC(/ box en_tmp ent i pt0 pt1 ss tmp);;;entity center ==> EC
    3. (setvar "CMDECHO" 0)
    4. (vl-load-com)
    5. (princ "\n选择需要居中的对象:")
    6. (if (setq ss (ssget))
    7. (progn
    8. (defun box(e / ll ur)
    9. (vla-getboundingbox (vlax-ename->vla-object e) 'll 'ur)
    10. (mapcar 'vlax-safearray->list (list ll ur))
    11. )
    12. (setq i -1)
    13. (command "undo" "be")
    14. (while (setq ent (ssname ss (setq i (1+ i))))
    15. (setq tmp (box ent))
    16. (setq tmp (mapcar '+ (car tmp) (cadr tmp)))
    17. (setq pt0 (mapcar '* tmp '(0.5 0.5 0.5)))
    18. (entdel ent)
    19. (setq en_tmp (bpoly pt0))
    20. (entdel ent)
    21. (setq tmp (box en_tmp))
    22. (setq tmp (mapcar '+ (car tmp) (cadr tmp)))
    23. (setq pt1 (mapcar '* tmp '(0.5 0.5 0.5)))
    24. (command "move" ent "" "non" pt0 "non" pt1)
    25. (entdel en_tmp)
    26. )
    27. (command "undo" "e")
    28. )
    29. (princ "\n没有选择对象!")
    30. )
    31. (princ)
    32. )