乐筑天下

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

[编程交流] 三维,通过拾取面对齐

[复制链接]

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 17:40:20 | 显示全部楼层 |阅读模式
大家好,
今天,我正在研究我的几个想法之一,即通过拾取人脸来对齐选择集:
1.选择要对齐的对象(SS)
2、拾取源面
3、拾取目标面
(在3D中工作)
 
不用说,试图从三维实体对象中获取dxf数据显示了一些可怕的事情。
你可以看到我的想法:
  1. ; Pick 3D Object's face
  2. ; Attempt to align objects by picking faces:
  3. ; 1.Select objects to align (SS)
  4. ; 2.Pick Source Face
  5. ; 3.Pick Destination Face
  6. ; 4.The SS is aligned, where the Source Face and Destination Face share the same plane, and their centroids are matched
  7. ;      *******************x <- mx
  8. ;      *                  *
  9. ;      *                  *
  10. ;      *        x <-cenx  *
  11. ;      *                  *
  12. ;      *                  *
  13. ; mn-> x*******************
  14. ;
  15. ; Points mn, mx and cenx are collinear!
  16. ; Grrr
  17. ; Credits to: Lee Mac
  18. (defun C:test ( / SS msg continiue pt1 bpoly-ent1 bpoly-elist1 vla-bpoly1 mn1 mx1 box1 bpolys-cen1 pt2 bpoly-ent2 bpoly-elist2 vla-bpoly2 mn2 mx2 box2 bpolys-cen2)
  19. (if
  20.         (and
  21.                 (princ "\nSelect objects to align, by picking faces")
  22.                 (setq SS (ssget "_:L"))
  23.                 (sssetfirst nil SS)
  24.         )
  25.         (progn
  26.                 ; Will prompt for point, until the bpoly's elist is displayed:
  27.                 ; Picking Source Face:
  28.                 (setq continiue T)
  29.                 (while
  30.                         continiue
  31.                         (progn
  32.                                 (setq pt1 (getpoint "\nPick the source face"))
  33.                                 (command "_.UCS" "F" pt1 "")
  34.                                 (command "_.BPOLY" pt1 "")
  35.                                 (if       
  36.                                         (and
  37.                                                 (eq (cdr (assoc 0 (entget (entlast)))) "LWPOLYLINE")
  38.                                                 (not (member msg '("Function cancelled" "quit / exit abort" "Valid hatch boundary not found.")))
  39.                                         )
  40.                                         (progn
  41.                                                
  42.                                                 (setq bpoly-ent1 (entlast))
  43.                                                 (setq bpoly-elist1 (entget bpoly-ent1))
  44.                                                 (setq vla-bpoly1 (vlax-ename->vla-object bpoly-ent1))
  45.                                                 (setq box1 (vla-getboundingbox vla-bpoly1 'mns 'mxs))
  46.                                                 (setq bpolys-cen1
  47.                                                         ( mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.0))
  48.                                                                 (setq mn1 (trans (vlax-safearray->list mns) 1 1))
  49.                                                                 (setq mx1 (trans (vlax-safearray->list mxs) 1 1))
  50.                                                         )
  51.                                                 )
  52.                                                 (entmakex
  53.                                                         (list
  54.                                                                 (cons 0 "POINT")
  55.                                                                 (cons 10 bpolys-cen1)
  56.                                                         )
  57.                                                 )
  58.                                                 (entdel bpoly-ent1)
  59.                                                 (command "_.UCS" "W" )
  60.                                                 (setq continiue F)
  61.                                                 ; how to set (entlast) to nil ? or not to be a (cons 0 LWPOLYLINE) ? So the code would reset
  62.                                         )
  63.                                         (princ "\n*** Try again! ***")
  64.                                 )
  65.                         )
  66.                 )
  67.                
  68.                 ; Picking Destination Face:
  69.                 (setq continiue T)
  70.                 (while
  71.                         continiue
  72.                         (progn
  73.                                 (setq pt2 (getpoint "\nPick the destination face"))
  74.                                 (command "_.UCS" "F" pt2 "")
  75.                                 (command "_.BPOLY" pt2 "")
  76.                                 (if       
  77.                                         (and
  78.                                                 (eq (cdr (assoc 0 (entget (entlast)))) "LWPOLYLINE")
  79.                                                 (not (member msg '("Function cancelled" "quit / exit abort" "Valid hatch boundary not found.")))
  80.                                         )
  81.                                         (progn
  82.                                                
  83.                                                 (setq bpoly-ent2 (entlast))
  84.                                                 (setq bpoly-elist2 (entget bpoly-ent1))
  85.                                                 (setq vla-bpoly1 (vlax-ename->vla-object bpoly-ent2))
  86.                                                 (setq box2 (vla-getboundingbox vla-bpoly2 'mnz 'mxz))
  87.                                                 (setq bpolys-cen2
  88.                                                         ( mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.0))
  89.                                                                 (setq mn2 (trans (vlax-safearray->list mnz) 1 1))
  90.                                                                 (setq mx2 (trans (vlax-safearray->list mxz) 1 1))
  91.                                                         )
  92.                                                 )
  93.                                                 (entmakex
  94.                                                         (list
  95.                                                                 (cons 0 "POINT")
  96.                                                                 (cons 10 bpolys-cen2)
  97.                                                         )
  98.                                                 )
  99.                                                 (entdel bpoly-ent2)
  100.                                                 (command "_.UCS" "W" )
  101.                                                 (setq continiue F)
  102.                                                 ; how to set (entlast) to nil ? or not to be a (cons 0 LWPOLYLINE) ? So the code would reset
  103.                                         )
  104.                                         (princ "\n*** Try again! ***")
  105.                                 )
  106.                         )
  107.                 )
  108.                
  109.                 (command "_.3DALIGN" SS ""
  110.                         bpolys-cen1 mn1 mx1 ; the points must not be collinear! (in this example they are)
  111.                         bpolys-cen2 mn2 mx2 ; the points must not be collinear! (in this example they are)
  112.                 )
  113.         );progn
  114. );if
  115. (princ)
  116. );defun               

我的目标是表示与Autodesk Inventor的对齐,请参见此示例视频
从1:37开始,粉红色部分与棕色部分对齐。(至少与此相近)。 
目前,我遇到了一些问题,要找到“第三个”非共线点进行对齐。在下图中,您可以看到黄色的临时bpoly,以及红色的当前点:
184022vhu887f8xh66f3u8.jpg
 
如果您有更好的建议,请随意修改代码。
对我来说,写这样的代码是一种爱好,我不是一个真正的程序员,所以我不需要任何学分。
(是的,我想为什么不使用bpoly的顶点呢?但我花了几天的时间才弄明白)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 03:08 , Processed in 0.637223 second(s), 57 queries .

© 2020-2025 乐筑天下

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