(defun evenlyDivide (minNo maxNo div / spacing lst item)
;; https://www.theswamp.org/index.php?topic=57444.msg609257#msg609257
;; div cannot be less than or equal to 1
(setq spacing (/ (- maxNo minNo) (float (- div 1))))
(setq lst (list (float minNo)))
(setq item minNo)
(repeat (- div 1)
(setq item (+ item spacing))
(setq lst (cons item lst))
) ;_ end of repeat
(reverse lst)
) ;_ end of defun
(defun getBestResult (func lst comp / results bestResult)
(setq results (mapcar func lst))
(setq bestResult (car results))
(foreach result (cdr results)
(if (apply comp (list result bestResult))
(setq bestResult result)
) ;_ end of if
) ;_ end of foreach
(nth (vl-position bestResult results) lst)
) ;_ end of defun
(defun linearSearch (func comp maxRep minS maxS error curRep div / spacing lst bestResult)
(setq spacing (/ (- maxS minS) div))
(setq lst (evenlyDivide minS maxS div))
(setq bestResult (getBestResult func lst comp))
(setq curRep (1+ curRep))
(if (or (>= curRep maxRep) (< (abs (- bestResult minS)) error) (< (abs (- bestResult maxS)) error))
bestResult
(linearSearch func
comp
maxRep
(max (- bestResult spacing) minS)
(min (+ bestResult spacing) maxS)
error
curRep
div
) ;_ end of linearSearch
) ;_ end of if
) ;_ end of defun
(defun c:di2 (/ en1 en2 dist pt1 p2) ;; line between 2 entities from nearest edges
(princ "\n Line at Minimum.Nearest Points of 2 Objects <+dist>..")
(setq en1 (car (entsel "\n Select First Object..<curved.first>")))
(setq en2 (car (entsel "\n Select Second Object..")))
(setq dist (linearSearch '(lambda (dist)
(distance (setq pt (vlax-curve-getPointAtDist en1 dist)) (vlax-curve-getClosestPointTo en2 pt))
) ;_ end of lambda
'<
10
0
(vlax-curve-getdistatparam en1 (vlax-curve-getendparam en1))
0.001
1
50
) ;_ end of linearSearch
) ;_ end of setq
(setq pt1 (vlax-curve-getPointAtDist en1 dist))
(command "line" pt1 (vlax-curve-getClosestPointTo en2 pt1) "")
(setq p2 (vlax-curve-getClosestPointTo en2 pt1)) ;; set p2 coord
(setq d22 (distance pt1 p2)) ;; calc length
(princ (strcat "\n Nearest Distance Between: "(rtos d22 2 4))) ;; print w/info
(princ)
) ;_ end of defun
;;; By Jimmy Bergmark
;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved
;;; returns the length or the perimeter of selected object
(defun c:loo (/ en curve len) ;; object length
(princ "\n..Length of Object \(T\), <not.pick.points>..")
(if (setq en (entsel))
(progn
(setq curve (vlax-ename->vla-object (car en)))
(if (vl-catch-all-error-p
(setq len (vl-catch-all-apply
'vlax-curve-getDistAtParam
(list curve
(vl-catch-all-apply
'vlax-curve-getEndParam
(list curve)
)
)
)
)
)
nil
len
)
)
)
)
(defun c:cmd (/ en1 en2 dist pt1 p2) ;; circle between 2 entities from nearest edges
(princ "\n Circle at Minimum.Nearest Points of 2 Objects <+dist>..")
(setq en1 (car (entsel "\n Select First Object..<curve.first>")))
(setq en2 (car (entsel "\n Select Second Object..")))
(setq dist (linearSearch '(lambda (dist)
(distance (setq pt (vlax-curve-getPointAtDist en1 dist)) (vlax-curve-getClosestPointTo en2 pt))
) ;_ end of lambda
'<
10
0
(vlax-curve-getdistatparam en1 (vlax-curve-getendparam en1))
0.001
1
50
) ;_ end of linearSearch
) ;_ end of setq
(setq pt1 (vlax-curve-getPointAtDist en1 dist))
(command "circle" "2P" pt1 (vlax-curve-getClosestPointTo en2 pt1) "") ;; copied+changed object inserted
(setq p2 (vlax-curve-getClosestPointTo en2 pt1)) ;; set p2 coord
(setq d22 (distance pt1 p2)) ;; calc length
(princ (strcat "\n Nearest Distance Between: "(rtos d22 2 4))) ;; print w/info
(princ)
) ;_ end of defun
(defun c:pmd (/ en1 en2 dist pt1 p2) ;; point between 2 entities from nearest edges
(princ "\n Point at Mid of Minimum.Nearest Points of 2 Objects <+point.dist>..")
(setq en1 (car (entsel "\n Select First Object..<curved.first>")))
(setq en2 (car (entsel "\n Select Second Object..")))
(setq dist (linearSearch '(lambda (dist)
(distance (setq pt (vlax-curve-getPointAtDist en1 dist)) (vlax-curve-getClosestPointTo en2 pt))
) ;_ end of lambda
'<
10
0
(vlax-curve-getdistatparam en1 (vlax-curve-getendparam en1))
0.001
1
50
) ;_ end of linearSearch
) ;_ end of setq
(setq pt1 (vlax-curve-getPointAtDist en1 dist))
(command "circle" "2P" pt1 (vlax-curve-getClosestPointTo en2 pt1) "")
(setq p2 (vlax-curve-getClosestPointTo en2 pt1)) ;; set p2 coord
(if (setq s (ssget "_L" '((0 . "CIRCLE")))) ;; change circle into point
(repeat (setq i (sslength s))
(setq e (ssname s (setq i (1- i))))
(if (entmake (list '(0 . "POINT") (assoc 10 (entget e))))
(entdel e)
)
)
)
(setq d22 (distance pt1 p2)) ;; calc length
(princ (strcat "\n Nearest Distance to Point: "(rtos (* 0.5 d22) 2 4))) ;; print w/info
(princ)
) ;_ end of defun