Problems with AI generated LISP

Problems with AI generated LISP

brockcorbin5
Explorer Explorer
435 Views
3 Replies
Message 1 of 4

Problems with AI generated LISP

brockcorbin5
Explorer
Explorer

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!

0 Likes
436 Views
3 Replies
Replies (3)
Message 2 of 4

cadffm
Consultant
Consultant

Hi 

 

>"that creates a stipple hatch, "

 

>"This hatch would differ than a normal AutoCAD hatch because the dots would be more concentrated on the edge of a boundary."

 

Impossible for a hatch Pattern, so it is impossible for one hatch.

The code trying to use single POINT objects.

Hoping your "hatchs" aren't big, otherwise it will be an performance nightmare"

 

 

If you start with AI, go further.

Take the quote and send it to your ai chat.

Problem: 

error: no function definition: RANDOM"

 

Do this with all following errors.

 

Sebastian

Message 4 of 4

Kent1Cooper
Consultant
Consultant

@brockcorbin5 wrote:

.... the dots would be more concentrated on the edge of a boundary. ....


Would an "abrupt" change in concentration near the edge work for you?  It might not be very obviously abrupt.

Kent1Cooper_7-1721073231748.png

That is simply two Hatch patterns in AutoCAD's standard AR-SAND pattern, bounded between by a [removed] inboard Offset from the outer boundary, with a scale factor around the edge half that of the interior.  Of course you could change that density ratio, and the width of the denser edge Hatch, etc.  And if the shape changes, you could just edit the Hatch boundaries, rather than needing to wipe out what you did before and run a random-Point-generator routine again using the changed boundary.

Such a result could probably be automated, though there could be complications if you have convoluted borders.

 

Kent Cooper, AIA