handasa 发表于 2022-7-5 15:59:59

find nearest osnap (intersecti

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)
 
https://s26.postimg.org/hhivf77d5/2017-09-21_18h11_02.png
 
my idea is to pick the block and get its base point

(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

ronjonp 发表于 2022-7-5 16:11:32

Something like this:

(vl-sort listofpointstosnapto '(lambda (a b) (< (distance bp a) (distance bp b))))

Lee Mac 发表于 2022-7-5 16:15:42

Alternatively, consider a function such as this for finding a general extremum.

handasa 发表于 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

ronjonp 发表于 2022-7-5 16:30:07

 
Depends on how that mesh is drafted.

handasa 发表于 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

ronjonp 发表于 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

(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"))))

Lee Mac 发表于 2022-7-5 16:47:42

These functions may help.

Grrr 发表于 2022-7-5 16:56:13

I keep this one in my archive:
 

; (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

handasa 发表于 2022-7-5 17:06:01

Thanks all ... I did it using the routines u shared ... Thanks again
页: [1]
查看完整版本: find nearest osnap (intersecti