Jump to content
jes_g

Closest point on a polyline from a block reference

Recommended Posts

jes_g

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

Share this post


Link to post
Share on other sites
ronjonp

Explode your blocks?

Share this post


Link to post
Share on other sites
devitg

;; 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 by devitg
following the rules

Share this post


Link to post
Share on other sites
BIGAL

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.

ScreenShot108.jpg

Share this post


Link to post
Share on other sites
jes_g

Thank you, devitg. It works perfectly!

Share this post


Link to post
Share on other sites
jes_g
;; 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!

Share this post


Link to post
Share on other sites
devitg

Glad it help.

Share this post


Link to post
Share on other sites
SLW210

Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE]

Your Code Here[/NOPARSE]

=

Your Code Here

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...