乐筑天下

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

[编程交流] find nearest osnap (intersecti

[复制链接]

42

主题

173

帖子

132

银币

后起之秀

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

铜币
220
发表于 2022-7-5 15:59:59 | 显示全部楼层 |阅读模式
hello every one ...
 
i have a block and i want to move this block from its base point to the nearest (rectangle) in a grid (false ceiling tiles)
 

                               
登录/注册后可看大图

 
my idea is to pick the block and get its base point
  1. (setq p1 (cdr (assoc 10 (entget (car (entsel))))))
 
and then find the nearest osnap to the gird block (the grid in white color)
and then move the block from its basepoint (p1) to the osnap point (p2)
 
any ideas to get the point p2
 
thanks in advance
回复

使用道具 举报

58

主题

3353

帖子

33

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1761
发表于 2022-7-5 16:11:32 | 显示全部楼层
Something like this:
  1. (vl-sort listofpointstosnapto '(lambda (a b) (< (distance bp a) (distance bp b))))
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:15:42 | 显示全部楼层
Alternatively, consider a function such as this for finding a general extremum.
回复

使用道具 举报

42

主题

173

帖子

132

银币

后起之秀

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

铜币
220
发表于 2022-7-5 16:20:32 | 显示全部楼层
 
i don't have the list of points "listofpointstosnapto"
i only have the "bp" and the grid (mesh) as a block ... how can i generate a list of "intersection points" of this mesh ?
 
thanks in advance
回复

使用道具 举报

58

主题

3353

帖子

33

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1761
发表于 2022-7-5 16:30:07 | 显示全部楼层
 
Depends on how that mesh is drafted.
回复

使用道具 举报

42

主题

173

帖子

132

银币

后起之秀

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

铜币
220
发表于 2022-7-5 16:38:29 | 显示全部楼层
 
what do you mean by "drafting"?
it's a mesh of vertical and horizontal polylines ! i don't think u mean this
回复

使用道具 举报

58

主题

3353

帖子

33

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1761
发表于 2022-7-5 16:40:09 | 显示全部楼层
Here's some quick code to get intersections on polylines .. I'm out on vacation for the next 5 days so someone else will need to help you more
  1. (defun _intersections (ss / out r s) (if   (and ss (setq s (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))   )    (progn      (while (setq o (car s)) (setq s (cdr s)) (setq out (cons (mapcar '(lambda (x) (vlax-invoke o 'intersectwith x acextendnone)) s) out))      )      (setq out (apply 'append (vl-remove 'nil (apply 'append out))))      (repeat (/ (length out) 3) (setq r   (cons (list (car out) (cadr out) (caddr out)) r)       out (cdddr out) )      )      r    ) ))(_intersections (ssget '((0 . "lwpolyline"))))
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:47:42 | 显示全部楼层
These functions may help.
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 16:56:13 | 显示全部楼层
I keep this one in my archive:
 
  1. ; (IntersectionsSS (ssget)); Get the point list of the intersections from a selection set(defun IntersectionsSS ( SS / vlax-list->3D-point i1 o1 i2 o2 rtn ) ; Grrr (defun vlax-list->3D-point ( L )   (if L (cons (list (car L) (cadr L) (caddr L)) (vlax-list->3D-point (cdddr L))) ) ) (if (eq 'PICKSET (type SS))   (repeat (setq i1 (sslength SS))     (and       (setq o1 (vlax-ename->vla-object (ssname SS (setq i1 (1- i1)))))       (vlax-method-applicable-p o1 'InterSectWith)       (setq rtn ; in case the object is self intersecting         (cons  ; but the problem is that this considers LWPOLY's/SPLINE's mid vertices as intersections (i.e. all vertices, except the endpoints)           (vlax-list->3D-point (vlax-invoke o1 'InterSectWith o1 acExtendNone))            rtn         )       ); setq rtn       (repeat (setq i2 i1)         (and           (setq o2 (vlax-ename->vla-object (ssname SS (setq i2 (1- i2)))))           (vlax-method-applicable-p o2 'InterSectWith)           (setq rtn (cons (vlax-list->3D-point (vlax-invoke o1 'InterSectWith o2 acExtendNone)) rtn))         ); and       ); repeat     ); and   ); repeat ); if (if rtn (apply 'append (reverse rtn)))); defun IntersectionsSS
回复

使用道具 举报

42

主题

173

帖子

132

银币

后起之秀

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

铜币
220
发表于 2022-7-5 17:06:01 | 显示全部楼层
Thanks all ... I did it using the routines u shared ... Thanks again
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 20:27 , Processed in 0.525737 second(s), 76 queries .

© 2020-2025 乐筑天下

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