明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1626|回复: 20

有没有前辈研究过最大包围盒中心替换图形

[复制链接]
发表于 2023-3-2 09:33 | 显示全部楼层 |阅读模式
4明经币
本帖最后由 梦想家-DING 于 2023-3-2 09:36 编辑

类似这样的,可否方便分享学习下

附件: 您需要 登录 才可以下载或查看,没有账号?注册
发表于 2023-3-2 10:04 | 显示全部楼层
意思是先画出图形最小包围盒,再删除原图形?
回复

使用道具 举报

 楼主| 发表于 2023-3-2 14:08 | 显示全部楼层
ssyfeng 发表于 2023-3-2 10:04
意思是先画出图形最小包围盒,再删除原图形?

是的,现有的A图形替换现有的B图形。中心替换后确认是否删除B图形保留A图形,确定方式为空格或左键确定,取消为esc
回复

使用道具 举报

发表于 2023-3-2 15:29 | 显示全部楼层
你那演示不是写出来了嘛?
回复

使用道具 举报

发表于 2023-3-2 16:16 | 显示全部楼层
我是没看懂究竟要做什么,你这也不是最小包围盒。不存在最大包围盒。
回复

使用道具 举报

 楼主| 发表于 2023-3-2 18:51 | 显示全部楼层
mikewolf2k 发表于 2023-3-2 16:16
我是没看懂究竟要做什么,你这也不是最小包围盒。不存在最大包围盒。

不知道是不是这样表达,反正是图形中心对图形中心替换。
回复

使用道具 举报

 楼主| 发表于 2023-3-2 18:52 | 显示全部楼层
ssyfeng 发表于 2023-3-2 15:29
你那演示不是写出来了嘛?

别人的
回复

使用道具 举报

发表于 2023-3-2 19:09 | 显示全部楼层
  1. ;; Selection Set Bounding Box  -  Lee Mac
  2. ;; Returns a list of the lower-left and upper-right WCS coordinates of a
  3. ;; rectangular frame bounding all objects in a supplied selection set.
  4. ;; sel - [sel] Selection set for which to return bounding box

  5. (defun LM:ssboundingbox ( sel / idx llp ls1 ls2 obj urp )
  6.     (repeat (setq idx (sslength sel))
  7.         (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
  8.         (if (and (vlax-method-applicable-p obj 'getboundingbox)
  9.                  (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'llp 'urp))))
  10.             )
  11.             (setq ls1 (cons (vlax-safearray->list llp) ls1)
  12.                   ls2 (cons (vlax-safearray->list urp) ls2)
  13.             )
  14.         )
  15.     )
  16.     (if (and ls1 ls2)
  17.         (mapcar '(lambda ( a b ) (apply 'mapcar (cons a b))) '(min max) (list ls1 ls2))
  18.     )
  19. )




回复

使用道具 举报

发表于 2023-3-2 19:11 | 显示全部楼层
Alternative Version

  1. ;; Selection Set Bounding Box  -  Lee Mac
  2. ;; Returns a list of the lower-left and upper-right WCS coordinates of a
  3. ;; rectangular frame bounding all objects in a supplied selection set.
  4. ;; sel - [sel] Selection set for which to return bounding box

  5. (defun LM:ssboundingbox ( sel / idx llp ls1 ls2 obj urp )
  6.     (repeat (setq idx (sslength sel))
  7.         (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
  8.         (if (and (vlax-method-applicable-p obj 'getboundingbox)
  9.                  (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'llp 'urp))))
  10.             )
  11.             (setq ls1 (mapcar 'min (vlax-safearray->list llp) (cond (ls1) ((vlax-safearray->list llp))))
  12.                   ls2 (mapcar 'max (vlax-safearray->list urp) (cond (ls2) ((vlax-safearray->list urp))))
  13.             )
  14.         )
  15.     )
  16.     (if (and ls1 ls2) (list ls1 ls2))
  17. )
回复

使用道具 举报

发表于 2023-3-2 19:12 | 显示全部楼层
Test Program

  1. (defun c:test ( / box obj sel spc )
  2.     (if (and (setq sel (ssget))
  3.              (setq box (LM:ssboundingbox sel))
  4.         )
  5.         (progn
  6.             (setq spc
  7.                 (vlax-get-property (vla-get-activedocument (vlax-get-acad-object))
  8.                     (if (= 1 (getvar 'cvport))
  9.                         'paperspace
  10.                         'modelspace
  11.                     )
  12.                 )
  13.             )
  14.             (if (equal 0.0 (apply '- (mapcar 'caddr box)) 1e-6)
  15.                 (progn
  16.                     (setq obj
  17.                         (vlax-invoke spc 'addlightweightpolyline
  18.                             (apply 'append
  19.                                 (mapcar '(lambda ( x ) (mapcar '(lambda ( y ) ((eval y) box)) x))
  20.                                    '(
  21.                                         (caar   cadar)
  22.                                         (caadr  cadar)
  23.                                         (caadr cadadr)
  24.                                         (caar  cadadr)
  25.                                     )
  26.                                 )
  27.                             )
  28.                         )
  29.                     )
  30.                     (vla-put-closed obj :vlax-true)
  31.                     (vla-put-elevation obj (caddar box))
  32.                 )
  33.                 (apply 'vlax-invoke
  34.                     (vl-list* spc 'addbox
  35.                         (apply 'mapcar (cons '(lambda ( a b ) (/ (+ a b) 2.0)) box))
  36.                         (apply 'mapcar (cons '- (reverse box)))
  37.                     )
  38.                 )
  39.             )
  40.         )
  41.     )
  42.     (princ)
  43. )
  44. (vl-load-com) (princ)


回复

使用道具 举报

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-17 17:27 , Processed in 0.349162 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表