Message 1 of 6
AutoCAD LISP Script Issues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
(defun c:FinalHatchR (/ ss i obj vla-obj area oldsnap)
(setq ss (ssget "X" '((0 . "LWPOLYLINE,POLYLINE,LINE,ARC,CIRCLE,ELLIPSE"))))
(if ss
(progn
(command "_.undo" "_begin")
(setq i -1)
(while (setq obj (ssname ss (setq i (1+ i))))
(setvar "cecolor" "green")
(princ "\ni = ")
(princ i)
(princ "\n")
(setq vla-obj (vlax-ename->vla-object obj))
(setq area nil)
(if (vl-catch-all-error-p (setq area (vl-catch-all-apply 'vla-get-area (list vla-obj))))
(setq area nil)
)
(setq ent (entget (ssname ss i)))
(setq layer (cdr (assoc 8 ent)))
(princ "\n")
(princ layer)
(princ "\n")
(if (and area (not (ssget "_X" (list (cons 0 "HATCH") (cons 10 (vlax-curve-getstartpoint vla-obj))))))
(progn
(setq oldsnap (getvar "osmode"))
(setvar "osmode" 0)
(cond
((wcmatch layer "*LayerYellow*")
(setvar "cecolor" "yellow")
)
((wcmatch layer "*LayerBlue*")
(setvar "cecolor" "blue")
)
((wcmatch layer "*LayerGrey*")
(setvar "cecolor" "8")
)
)
(if (not (equal "green" (getvar "cecolor")))
(progn
(command "_.bpoly" (vlax-curve-getstartpoint vla-obj) "") ; Create a boundary polyline around the enclosed area
(setq obj (entlast)) ; Get the last created entity (boundary polyline)
(command "_.hatch" "S" "P" obj "") ; Hatch the enclosed area
(command "_.erase" obj "") ; Erase the boundary polyline
(setvar "cecolor" "green")
)
)
(setvar "osmode" oldsnap)
)
)
)
(command "_.undo" "_end")
(princ "\nAll enclosed areas have been hatched with color.")
)
)
(princ "\nNo enclosed areas found.")
(princ)
)May I ask why when it comes to "LayerGrey", it paints the area as "blue"?