- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
AutoCAD LT 2025
I would like to create a lisp routine that:
- creates layer (if not already created) called 'Earth Hatch 2' - colour '11'
- enables hatching of multiple pick points
- Hatch pattern 'Earth'
- Hatch scale '35'
- Hatch angle '45'
- Successfully places hatch on colour 11 regardless of previous hatch colour settings being set to:
'ByLayer', 'ByBlock', 'Use Current' or set to an index colour.
- Allows for furture hatches, created via the normal hatch command, to be created on the current layer at the time as opposed to continuing to be created on 'Earth Hatch 2' layer.
- Allows for furture hatches, created via the normal hatch command, not to retain the same attributes set by the LISP routine i.e. scale, angle, colour, though to remain what ever the settings were previously set to.
The following code works perfectly except:
- requires you to press 'enter' to confirm 'none' for background colour.
I would like this to happen automatically.
- Future hatches are created on colour 11
As I understand it AutoCAD LT has limits regarding how you can set the colour for hatches through LISP routines.
- The background color prompt cannot be suppressed or auto-answered through LISP.
- LT doesn’t let you set it directly by LISP
Can someone please help me remove the prompt for 'new background colour' after initiating the LISP routine?
Many thanks.
;; ERH17M-MP18 — Earth hatch, multiple pick points
(defun c:ERH17M-MP18 ( / oldce oldlay oldhpname oldhpscale oldhpang oldhplayer lay)
;; Save environment & hatch defaults
(setq oldce (getvar "CMDECHO"))
(setq oldlay (getvar "CLAYER"))
(setq oldhpname (getvar "HPNAME"))
(setq oldhpscale (getvar "HPSCALE"))
(setq oldhpang (getvar "HPANG"))
(setq oldhplayer (getvar "HPLAYER"))
(setvar "CMDECHO" 0) ; quiet mode
(setq lay "Earth Hatch 2")
;; Ensure layer exists and is colour 11
(if (tblsearch "LAYER" lay)
(vl-cmdf "_.-LAYER" "C" "11" lay "")
(vl-cmdf "_.-LAYER" "N" lay "C" "11" lay "")
)
;; Temporarily make Earth Hatch 2 current
(setvar "CLAYER" lay)
;; Start hatch with full property setup
(vl-cmdf
"_.-HATCH"
"_Properties" "EARTH" "35" "45"
"_Layer" lay
"_Color" "11" ;; <- force hatch colour to 11, independent of HPCOLOR
"_PickPoints"
)
;; Allow multiple picks until user presses Enter
(while (= 1 (getvar "CMDACTIVE"))
(command pause)
)
;; Restore hatch defaults
(if oldhpname (setvar "HPNAME" oldhpname))
(if oldhpscale (setvar "HPSCALE" oldhpscale))
(if oldhpang (setvar "HPANG" oldhpang))
(if oldhplayer (setvar "HPLAYER" oldhplayer))
;; Restore previous layer and CMDECHO
(setvar "CLAYER" oldlay)
(setvar "CMDECHO" oldce)
(princ)
)
Solved! Go to Solution.