Hi, sorry to bother you again with this.
Thanks for the video showing the use of VLIDE, that's very helpful. Doing it in Notepad with no feedback was no good!
So I've cleared up the parenthesis and variable name errors using VLIDE.
I've tidied up the TREN part and corrected the bug. The TREN part now runs faster and I've tested it as a standalone (TRENTEST) working from a simple (setq s (ssget "_X" '((8 . "TEXT")))) and it works!
However, the TEST program still doesn't work...
I'm now getting no debug breaks, so am watching using breakpoints as you described.
The PTRE selection is returning the correct number of PTRE blocks as coordinates.
The TEXT selection is also returning the correct number of TEXT coordinates.
When it gets to the comparison it iterates through all the TEXT coordinates correctly but deletes them all and ends up with a selection set of nil.
I think that's what's happening... I just can't seem to figure out why...
PS. Is the "1e-3" part a 0.001 fuzz factor? I've run the code with the TEXT moved to be exactly on the PTRE points, so coordinates are exactly the same, and still getting the same result...
Thanks again.
(defun c:TRENTEST ( / s i c e l)
(defun *error* (MSG)
(if (/= MSG "Function cancelled")
(princ (strcat "\nError: " MSG)))
(if osm (setvar "OSMODE" OSM))
(if lyr (setvar "CLAYER" LYR))
(princ))
(defun LM:str->lst ( str del / pos ) ;;; String to List - Lee Mac ;;;
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
(list str))
)
(setq OSM (getvar "OSMODE"))
(setq LYR (getvar "CLAYER"))
(setq s (ssget "_X" '((8 . "TEXT"))))
(if (and s (/= 0 (sslength s)))
(repeat (setq i (sslength s))
(setq i (1- i))
(setq XY (cdr (assoc 10 (entget (ssname s i))))) ;;;*** (setq xy (getpoint "Where? "))
(setq EN (entget (ssname s i))) ;;;*** (setq en (car (entsel "Pick info: ")))
(setq lst (LM:str->lst (cdr (assoc 1 EN)) "-")) ;;; G-S-H-species
(setq tr (atof (car lst)))
(setq sp (atof (cadr lst)))
(setq h (atof (caddr lst)))
(setq spe (last lst))
(command "osnap" "none")
(command "LAYER" "M" "TRTEXT" "")
(setq txy (polar xy 0.4636 0.894))
(command "TEXT" txy "" "" spe)
(command "TEXT" "" (strcat "G "(rtos tr 2 2)))
(command "TEXT" "" (strcat "S "(rtos sp 2 1)))
(command "TEXT" "" (strcat "H "(rtos h 2 0)))
(command "LAYER" "M" "TRTR" "")
(command "INSERT" "treebole" xy (/ tr PI) "" "")
(command "LAYER" "M" "TRCAN" "")
(command "INSERT" "trcan" xy sp "")
)
)
(setvar "OSMODE" OSM)
(setvar "CLAYER" LYR)
(princ)
)
(defun c:TEST ( / s i c e l)
(defun *error* (MSG)
(if (/= MSG "Function cancelled")
(princ (strcat "\nError: " MSG)))
(if osm (setvar "OSMODE" OSM))
(if lyr (setvar "CLAYER" LYR))
(princ))
(defun LM:str->lst ( str del / pos ) ;;; String to List - Lee Mac ;;;
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
(list str))
)
(setq OSM (getvar "OSMODE"))
(setq LYR (getvar "CLAYER"))
(if (setq s (ssget "_X" '((2 . "PTRE"))))
(repeat (setq i (sslength s)))
(setq c (cdr (assoc 10 (entget (ssname s (setq i (1- i))))))
l (cons c l)))
(if (setq s (ssget "_X" '((8 . "TEXT"))))
(repeat (setq i (sslength s))
(setq c (cdr (assoc 10 (entget (setq e (ssname s (setq i (1- i)))))))
l (vl-sort l (function (lambda (c1 c2) (< (distance c c1) (distance c c2))))))
(if (not (equal c (car l) 1e-3)) (ssdel e s))))
(if (and s (/= 0 (sslength s)))
(repeat (setq i (sslength s))
(setq i (1- i))
(setq XY (cdr (assoc 10 (entget (ssname s i))))) ;;;*** (setq xy (getpoint "Where? "))
(setq EN (entget (ssname s i))) ;;;*** (setq en (car (entsel "Pick info: ")))
(setq lst (LM:str->lst (cdr (assoc 1 EN)) "-")) ;;; G-S-H-species
(setq tr (atof (car lst)))
(setq sp (atof (cadr lst)))
(setq h (atof (caddr lst)))
(setq spe (last lst))
(command "osnap" "none")
(command "LAYER" "M" "TRTEXT" "")
(setq txy (polar xy 0.4636 0.894))
(command "TEXT" txy "" "" spe)
(command "TEXT" "" (strcat "G "(rtos tr 2 2)))
(command "TEXT" "" (strcat "S "(rtos sp 2 1)))
(command "TEXT" "" (strcat "H "(rtos h 2 0)))
(command "LAYER" "M" "TRTR" "")
(command "INSERT" "treebole" xy (/ tr PI) "" "")
(command "LAYER" "M" "TRCAN" "")
(command "INSERT" "trcan" xy sp "")
)
)
(setvar "OSMODE" OSM)
(setvar "CLAYER" LYR)
(princ)
)