jes_g Posted January 26, 2018 Posted January 26, 2018 Hello, there, I am trying to find a LISP routine which will find the closest point on a polyline from a selected block reference. This routine finds the closest distance between two objects by selecting both objects, but it does not seem to work with block reference. After it finds the closest point, how to create a new vertex on that point? Thank you in advance Best wishes, Jes G Quote
devitg Posted January 26, 2018 Posted January 26, 2018 (edited) ;; Design by Gabo CALOS DE VIT from CORDOBA ARGENTINA ;;; Copyleft 1995-2018 by Gabriel Calos De Vit ;; [email]DEVITG@GMAIL.COM[/email] ; Hecho por Gabo CALOS DE VIT de CORDOBA ARGENTINA ;;; Copyleft 1995-2018 por Gabriel Calos De Vit ;; [email]DEVITG@GMAIL.COM[/email] ; no error check. ;; no nothing (vl-load-com) (DEFUN C:EXAMPLE_ADDVERTEX ( / ACADOBJ BLK-REF-XYZ BLK-REFERENCE DOC LSTPOINT MODELSPACE NEWVERTEX PARAM-AT-CLOSEST-POINT PLINE PLINE-OBJ POINT-AT-PARAM VERTEX-POINT ) (SETQ ACADOBJ (VLAX-GET-ACAD-OBJECT)) (SETQ DOC (VLA-GET-ACTIVEDOCUMENT ACADOBJ)) (SETQ MODELSPACE (VLA-GET-MODELSPACE DOC)) (SETQ PLINE (ENTSEL "\nSelect Polyline: ")) (SETQ PLINE-OBJ (VLAX-ENAME->VLA-OBJECT (CAR PLINE))) (SETQ BLK-REFERENCE (CAR (ENTSEL "\Select the block-reference"))) (SETQ BLK-REF-XYZ (CDR (ASSOC 10 (ENTGET BLK-REFERENCE)))) ;;; (VL-CMDF "POINT" BLK-REF-XYZ "") (SETQ LSTPOINT (VLAX-CURVE-GETCLOSESTPOINTTO PLINE-OBJ BLK-REF-XYZ)) (SETQ PARAM-AT-CLOSEST-POINT (VLAX-CURVE-GETPARAMATPOINT PLINE-OBJ LSTPOINT)) (SETQ POINT-AT-PARAM (VLAX-CURVE-GETPOINTATPARAM PLINE-OBJ PARAM-AT-CLOSEST-POINT)) (SETQ VERTEX-POINT (LIST (CAR POINT-AT-PARAM) (CADR POINT-AT-PARAM))) ;;; (VL-CMDF "POINT" VERTEX-POINT "") (SETQ NEWVERTEX (VLAX-MAKE-SAFEARRAY VLAX-VBDOUBLE '(0 . 1))) (VLAX-SAFEARRAY-FILL NEWVERTEX VERTEX-POINT) (VLA-ADDVERTEX PLINE-OBJ (1+ (FIX PARAM-AT-CLOSEST-POINT)) NEWVERTEX) (VLA-UPDATE PLINE-OBJ) ) ;|«Visual LISP© Format Options» (180 2 1 0 nil "end of " 100 20 2 2 nil nil T nil T) ;*** DO NOT add text below the comment! ***|; new vertex closest from a block -jes_g.dwg Edited January 29, 2018 by devitg following the rules Quote
BIGAL Posted January 26, 2018 Posted January 26, 2018 You can do a boundingbox of a block but this is basically a rectangle and compare. Getting a boundary of block is not easy and has been discussed many times. Lee-mac has a convex hull routine and there are others I know of one that appears very good but you have to buy it. Quote
jes_g Posted January 27, 2018 Author Posted January 27, 2018 Thank you, devitg. It works perfectly! Quote
jes_g Posted January 27, 2018 Author Posted January 27, 2018 ;; Design by Gabo CALOS DE VIT from CORDOBA ARGENTINA;;; Copyleft 1995-2018 by Gabriel Calos De Vit ;; DEVITG@GMAIL.COM ; Hecho por Gabo CALOS DE VIT de CORDOBA ARGENTINA ;;; Copyleft 1995-2018 por Gabriel Calos De Vit ;; DEVITG@GMAIL.COM ; no error check. ;; no nothing (vl-load-com) (DEFUN C:EXAMPLE_ADDVERTEX ( / ACADOBJ BLK-REF-XYZ BLK-REFERENCE DOC LSTPOINT MODELSPACE NEWVERTEX PARAM-AT-CLOSEST-POINT PLINE PLINE-OBJ POINT-AT-PARAM VERTEX-POINT ) (SETQ ACADOBJ (VLAX-GET-ACAD-OBJECT)) (SETQ DOC (VLA-GET-ACTIVEDOCUMENT ACADOBJ)) (SETQ MODELSPACE (VLA-GET-MODELSPACE DOC)) (SETQ PLINE (ENTSEL "\nSelect Polyline: ")) (SETQ PLINE-OBJ (VLAX-ENAME->VLA-OBJECT (CAR PLINE))) (SETQ BLK-REFERENCE (CAR (ENTSEL "\Select the block-reference"))) (SETQ BLK-REF-XYZ (CDR (ASSOC 10 (ENTGET BLK-REFERENCE)))) ;;; (VL-CMDF "POINT" BLK-REF-XYZ "") (SETQ LSTPOINT (VLAX-CURVE-GETCLOSESTPOINTTO PLINE-OBJ BLK-REF-XYZ)) (SETQ PARAM-AT-CLOSEST-POINT (VLAX-CURVE-GETPARAMATPOINT PLINE-OBJ LSTPOINT)) (SETQ POINT-AT-PARAM (VLAX-CURVE-GETPOINTATPARAM PLINE-OBJ PARAM-AT-CLOSEST-POINT)) (SETQ VERTEX-POINT (LIST (CAR POINT-AT-PARAM) (CADR POINT-AT-PARAM))) ;;; (VL-CMDF "POINT" VERTEX-POINT "") (SETQ NEWVERTEX (VLAX-MAKE-SAFEARRAY VLAX-VBDOUBLE '(0 . 1))) (VLAX-SAFEARRAY-FILL NEWVERTEX VERTEX-POINT) (VLA-ADDVERTEX PLINE-OBJ (1+ (FIX PARAM-AT-CLOSEST-POINT)) NEWVERTEX) (VLA-UPDATE PLINE-OBJ) ) ;|«Visual LISP© Format Options» (180 2 1 0 nil "end of " 100 20 2 2 nil nil T nil T) ;*** DO NOT add text below the comment! ***|; It works perfectly! Quote
SLW210 Posted January 29, 2018 Posted January 29, 2018 Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.