Hi guys...
I wrote a lisp inspired with this topic :
https://www.cadtutor.net/forum/topic/68947-how-to-get-block-nearest-end-point-or-perpendicular-point/that works on complex block references that consist of curves, other blocks and other entities...
It works well with blocks, however, I wanted to use it also with xrefs and then boomer!!! It works, but results are sometimes with complex xrefs unexpected (wrong)... The problem IMHO lies in the fact that parent entity to nested xref is not block or xref it's nested to, but directly Model Space... Here I am posting my version for xrefs and blocks, but I have the one just for blocks that works - parent of nested block is always block... Also I am not sure if my sub for (collectingblkrefs) is doing good job as it's a little difficult to explain - it should collect all relevant parent entities to nested curve entity and only with this info, routine should process - finding closestpointto that nested curve...
In attached *.zip is my problem - there is folder with xrefs - main *.dwg is xrefs.dwg, and when you test it on simple xrefs also in main dwg it works, but when applied to complex one (1.dwg) that consists only of circle curves complexly nested in blocks and other xrefs it won't work as desired...
Please, take a look and if you find something relevant I should be using, please reply... I and others will be very grateful...
M.R.
(defun c:findclosestpointtonestedinblkref
( / findclosestpointtonestedinblkref refgeom trp mxm mxv LM:InverseMatrix processclosestpointto processclosestpointtoinv collectblkrefs collectallentsfromref collectallcurvesnestedinblkrefwithparentrefassociations stblkref blkref wcspt p
)
(defun findclosestpointtonestedinblkref
( blkref wcspt
/ pl curreflst rg
)
(foreach curref
(setq curreflst
(collectallcurvesnestedinblkrefwithparentrefassociations blkref
)) )
)
;; RefGeom (gile)
;; Returns a list whose first item is a 3x3 transformation matrix and
;; second item the object insertion point in its parent (xref, block or space)
(defun refgeom
( ent
/ ang enx mat ocs
) )
(mxm
'(
(1.0 0.0 0.0)
(0.0 1.0 0.0)
(0.0 0.0 1.0)
)
)
(mxm
'(0.0 0.0 1.0)
)
)
)
)
)
)
)
)
;; Matrix Transpose - Doug Wilson
;; Args: m - nxn matrix
)
;; Matrix x Matrix - Vladimir Nesterovsky
;; Args: m,n - nxn matrices
)
;; Matrix x Vector - Vladimir Nesterovsky
;; Args: m - nxn matrix, v - vector in R^n
)
;;--------------------=={ Inverse Matrix }==------------------;;
;; ;;
;; Implements the Gauss-Jordan Elimination algorithm to ;;
;; inverse a non-singular nxn matrix. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: m - nxn Matrix ;;
;;------------------------------------------------------------;;
;; Returns: Matrix inverse, or nil if matrix is singular ;;
;;------------------------------------------------------------;;
(defun LM:InverseMatrix
( m
/ _identity _eliminate p r x
)
)
)
(defun _eliminate
( m p
) )
)
m
)
)
)
r
(cons p
(_eliminate r p
)) )
)
)
)
(defun processclosestpointto
( parentlst pt
/ parent
) )
)
pt
)
(defun processclosestpointtoinv
( parentlst pt
/ child
) (setq pt
((lambda ( matveclst
) (mxv
(LM:InverseMatrix
(car matveclst
)) (mapcar '
- pt
(cadr matveclst
)))) (refgeom child
))) )
)
pt
)
(defun collectblkrefs
( blkref curve
/ el ee
) (setq el
(collectallentsfromref blkref
)) )
)
(setq blkrefinl blkrefin
) )
)
)
(collectblkrefs ee curve)
nil
)
)) el
)
blkrefinl
)
(defun collectallentsfromref
( blkref
/ e el
)
)
el
)
(defun collectallcurvesnestedinblkrefwithparentrefassociations
( blkref
/ blkrefinl e el ex gg g q f
)
)
(setq el
(collectallentsfromref blkref
)) ( (wcmatch (cdr (assoc 0 ex
)) "*POLYLINE,SPLINE,XLINE,LINE,RAY,ARC,CIRCLE,ELLIPSE,HELIX") (setq blkrefinl
(collectblkrefs stblkref e
)) (setq blkrefinl
(cons blkref blkrefinl
)) )
)
)
)
)
)
(setq blkrefinl
nil gg
nil g
nil q
nil f
nil) )
(collectallcurvesnestedinblkrefwithparentrefassociations e)
)
)
)
curreflst
)
)
)
(prompt "\nMissed or picked wrong entity type...") )
(princ (setq p
(findclosestpointtonestedinblkref blkref wcspt
))) )