However, I've found some issues that I fixed in your main routine... Whenever it's possible avoid using (command) function to setup sysvars - instead use (setvar)... I've added undomarks also, so you can quickly undo routine processing in one single "U" call... Also I've fixed my mistake in above posted function - added (if ss ... ) as when no sel. set - empty subfunction would fail, this way it's doing what it's supposed to do...
Code:
;;-------------------STANDARD LISP--------------------;;
;;--Description --;;
;;--Description --;;
;;--Description --;;
;;--Description --;;
;;--Description --;;
;;----------------------------------------------------;;
;;--Designed by: Matthew Mortimer --;;
;;--email: Matthew.e.mortimer@hotmail.com --;;
;;----------------------------------------------------;;
(defun c:test (/ *error* ClashDetection
*adoc* dwgname dwgprefix osmode
clayer filedia pdmod EndPoint
Increment WIPInt i1 i2
i3 Frontier Visited CurrentPoint
FrontierProposed
)
;;;;;--------------------ERROR CHECKING-------------------;;;;;
(defun *error* (msg)
(setvar "filedia" 1)
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort")))
; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** ")))
; Fatal error, display it
)
(vla-endundomark *adoc*)
(princ)
)
;;;;;--------------------ERROR CHECKING-------------------;;;;;
(defun ClashDetection
(pt1 pt2 / ss_fnestelst n s e x1 x2 check i WIP)
(defun ss_fnestelst (p1 p2 / unique ss ssn ptsssn ent entl)
(defun unique (l)
(if l
(cons (car l) (vl-remove (car l) (unique (cdr l))))
)
)
(setq ss (ssget "_F" (list p1 p2)))
(if ss
(progn (setq ssn (ssnamex ss))
(setq ptsssn
(mapcar
'cadr
(apply
'append
(mapcar '(lambda (x) (vl-remove-if-not 'listp x))
ssn
)
)
)
)
(foreach pt ptsssn
(setq ent (car (nentselp pt)))
(setq entl (cons ent entl))
)
(unique entl)
)
)
)
(if (setq s (ss_fnestelst pt1 pt2))
(progn (setq i 0
n (length s)
)
(repeat n
(setq e (nth i s)
x1 (cdr (assoc 8 (entget e)))
x2 (cdr (assoc 0 (entget e)))
WIP (if (= nil (wcmatch (strcase x2) "*DOOR*"))
(if (or (/= nil
(wcmatch (strcase x1)
"*GENM*,*WALL*,*GLAZ*,*STRUCT*"
)
)
(/= nil
(wcmatch (strcase x2)
"*GENM*,*WALL*,*GLAZ*,*STRUCT*"
)
)
)
(setq check T)
)
)
i (1+ i)
)
)
)
)
check
) ;----------[PRE-ROUTINE]-------------------------------
(setq dwgname (getvar "dwgname")
dwgprefix (getvar "dwgprefix")
osmode (getvar "osmode")
clayer (getvar "clayer")
filedia (getvar "filedia")
pdmod (getvar "pdmode")
)
(vl-load-com)
(setq *adoc* (vla-get-activedocument (vlax-get-acad-object)))
(vla-startundomark *adoc*) ;----------[PRE-ROUTINE]-------------------------------
(setq EndPoint (getpoint "\nPick Desired Room: ")
Increment 500
WIPInt (getint "\nEnter Number: ")
i1 1
i2 0
i3 0
Frontier (list EndPoint)
Visited (list)
)
(repeat WIPInt
(setq CurrentPoint (nth (1- (length Frontier)) Frontier)
Frontier (vl-remove CurrentPoint Frontier)
Visited (cons CurrentPoint Visited)
i1 1
)
(repeat 4
(setq FrontierProposed (cond ((= i1 1)
(list (+ (nth 0 CurrentPoint) Increment)
(nth 1 CurrentPoint)
(nth 2 CurrentPoint)
)
)
((= i1 2)
(list (nth 0 CurrentPoint)
(+ (nth 1 CurrentPoint) Increment)
(nth 2 CurrentPoint)
)
)
((= i1 3)
(list (- (nth 0 CurrentPoint) Increment)
(nth 1 CurrentPoint)
(nth 2 CurrentPoint)
)
)
((= i1 4)
(list (nth 0 CurrentPoint)
(- (nth 1 CurrentPoint) Increment)
(nth 2 CurrentPoint)
)
)
)
Frontier (if (member FrontierProposed Visited)
Frontier
(if (ClashDetection CurrentPoint FrontierProposed)
Frontier
(cons FrontierProposed Frontier)
)
)
i1 (1+ i1)
)
)
)
(setvar "osmode" 0)
(setvar "pdmode" 35)
(repeat (length Frontier)
(command "point" (nth i2 Frontier))
(setq i2 (1+ i2))
)
(setvar "pdmode" 0)
(setvar "clayer" "defpoints")
(repeat (length Visited)
(command "point" (nth i3 Visited))
(setq i3 (1+ i3))
)
(setvar "clayer" "0") ;----------[POST-ROUTINE]-----------------------------
(setvar "osmode" osmode)
(setvar "clayer" clayer)
(setvar "filedia" filedia)
(setvar "pdmode" pdmod) ;----------[POST-ROUTINE]-----------------------------
(*error* nil)
)
Only one side note - as experienced drawer you actually don't need this function - it's obvious which rooms are dead - no entrances - this is classical mistake... Avoid such situations - put just a single door if that is adequate, but one door is minimum you should predict, unless those rooms are some kind of isolated spaces with entrances in floor or ceiling or they represent some kind of shafts for elevators, ventilation, etc...