Problems with AI generated LISP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all, I am looking to make a LISP that creates a stipple hatch, similar to what you would see on a landscape architect’s plan to cover an area of grass. This hatch would differ than a normal AutoCAD hatch because the dots would be more concentrated on the edge of a boundary. The code is AI generated and I am receiving an error for it.
"(defun c:stippleHatch ()
(defun get-polyline-coordinates (ent)
(if (eq (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
(mapcar 'cdr
(vl-remove-if-not
'(lambda (x) (member (car x) '(10 42)))
(entget ent)
)
)
)
)
(defun random-range (min max)
(+ min (* (random) (- max min))))
(setq boundary (car (entsel "\nSelect the boundary: ")))
(setq densityHigh 50) ; Higher density near the edges
(setq densityLow 10) ; Lower density in the middle
(if (and boundary (eq (cdr (assoc 0 (entget boundary))) "LWPOLYLINE"))
(progn
(setq pointsList '())
(setq boundaryPoints (get-polyline-coordinates boundary))
(foreach pt boundaryPoints
(setq x (car pt) y (cadr pt))
(setq distanceToEdge (vlax-curve-getDistAtPoint boundary (list x y 0)))
(setq density (cond ((< distanceToEdge 2) densityHigh)
((< distanceToEdge 4) (/ densityHigh 2))
(t densityLow)))
(setq step (/ 1.0 density))
(setq i 0)
(while (< i density)
(setq randX (+ x (random-range (- step 0.5) step)))
(setq randY (+ y (random-range (- step 0.5) step)))
(setq pointsList (append pointsList (list (list randX randY 0))))
(setq i (1+ i))
)
)
(foreach pt pointsList
(entmake (list (cons 0 "POINT") (cons 10 pt)))
)
(princ "\nStipple hatch created.")
)
(princ "\nPlease select a valid polyline boundary.")
)
(princ)
)
(princ "\nType STIPPLEHATCH to run the stipple hatch routine.")
(princ)"
error: "error: no function definition: RANDOM"
any tips? thanks!