;; | ---------------------------------------------------------------------------- ;; | GE_ClosestPointTo ;; | ---------------------------------------------------------------------------- ;; | Function : Locate the closest point to the curve. This function is meant ;; | for use by IntelliCAD-based applications like BricsCAD in ;; | which the implementation of the vlax-curve-getClosestPointTo ;; | function is still not available (as on 5/8/2008) ;; | Argument : [pt] - Point at which the nearest point on th curve is ;; | to be determined. ;; | [ename] - Curve entity name around which to check the ;; | nearest point ;; | Return : The actual nearest point on the curve is returned ;; | e-mail : rakesh.rao@4d-technologies.com ;; | Web : www.4d-technologies.com ;; | ---------------------------------------------------------------------------- (defun GE_GetClosestPointTo ( ename Pt / entl en OS LL UR Cen elast ename1 EndAng Found Lst NeaPt pname PtLst Rad ss ss1 StAng vlist len ) (setq OS (getvar "OSMODE")) (setvar "OSMODE" 0) (setq Found nil Lst (GE_GetObjectBoundingBox ename) ) (if Lst (progn (setq LL (car Lst) UR (cadr Lst) ) (command "._Zoom" "_Window" LL UR "._Zoom" "0.9x" ) (setq vlist (GE_plist3d2d (PL_plist ename) "Zero")) (if vlist (progn (setq NeaPt (GE_NearPt pt vlist)) (if NeaPt (progn (setq ss (ssget NeaPt)) (if (and ss (ssmemb ename ss)) (progn (setq NeaPt (osnap NeaPt "_nea")) (if NeaPt (setq Found T) ) )) )) )) (if (not Found) (progn (setq entl (entget ename) en (LI_item 0 entl) ename1 nil ) (cond ((= en "SPLINE") (setq len (MI_CurveLength ename) ename1 (PL_Spl2Pl_Int ename (* len 0.001) T) ) ) ((member en (list "POLYLINE" "LWPOLYLINE")) (cond ((PL_Arced? ename) (setq elast (MI_xentlast)) (command "._Copy" ename "" (list 0.0 0.0 0.0) "" "._Explode" (entlast) ) (setq ss1 (MI_After elast)) (if ss1 (progn (setq vlist (PL_plist ename) PtLst (PL_ReconstructPoly (car vlist) ss1 "Angular" 1.0) ) (command "._Erase" ss1 "") (if (and PtLst (>= (length PtLst) 1)) (progn (setq ename1 (PL_mk_pl PtLst 0 0.0)) )) )) ) ((or (PL_Fitted? ename) (PL_Splined? ename)) (setq len (MI_CurveLength ename) ename1 (PL_Spl2Pl_Int ename (* len 0.001) T) ) ) ) ) ((member en (list "ARC" "CIRCLE")) (setq Cen (LI_item 10 entl) Rad (LI_item 40 entl) ) (if (= en "CIRCLE") (setq StAng 0.0 EndAng 360.0 ) (setq StAng (MI_r2d (LI_item 50 entl)) EndAng (MI_r2d (LI_item 51 entl)) )) (setq vlist (GE_Arc2Line Cen Rad StAng EndAng "Angular" 1.0)) (if vlist (progn (setq vlist (GE_DistWeed vlist 0.001 "Slope")) (if (and vlist (setq vlist (car vlist))) (setq ename1 (PL_mk_pl vlist (if (= en "ARC") 0 1) 0.0)) ) )) ) ) (if ename1 (setq pname ename1) (setq pname ename) ) (setq vlist (PL_plist pname)) (if ename1 (entdel ename1) ) (setq NeaPt (GE_NearPt pt vlist)) (if NeaPt (progn (setq ss (ssget NeaPt)) (if (and ss (ssmemb ename ss)) (progn (setq NeaPt (osnap NeaPt "_nea")) (if NeaPt (setq Found T) (alert "Internal error: osnap failed in GE_GetClosestPointTo function.") ) ) (alert "Internal error: ssget=nil in GE_GetClosestPointTo function.") ) ) (alert "Internal error: NeaPt=nil in GE_GetClosestPointTo function.") ) )) (command "._Zoom" "_Previous" "._Zoom" "_Previous" ) )) (if Found NeaPt nil) )