Speaking of which, the code below used to work perfectly until 2016, now on 2017 it is not working: the second hatch where the number of desired vertical lins is more than 1 generates an error, saying the point sits on the object. Not sure why, any help fixing this much appreciated.
; Square divide
; Divides a virtual room into n x m rows and columns all on defpoints
(defun c:sd ()
; set hatch parameters
(setvar "CMDECHO" 0)
(setvar "HPANG" 0)
(setvar "HPNAME" "U")
(setvar "HPDOUBLE" 0)
;Save initial state
(setq ExistingLayer (getvar "CLAYER"))
(setq ExistingOSMODE (getvar "OSMODE"))
(setvar "OSMODE" 33)
; get corners
(setq pt1 (getpoint "\nPick lower left corner: "))
(setq pt3 (getpoint "\nPick upper right corner: "))
(setvar "OSMODE" 0)
; calculate points 2 and 4
(setq
pt2 (list (car pt3) (cadr pt1))
pt4 (list (car pt1) (cadr pt3))
Horizontal_Distance (distance pt1 pt2)
Verticall_Distance (distance pt1 pt4)
Num_Horizontal_Lines (getint "\nNumber of horizontal division lines: ")
Num_Verticall_Lines (getint "\nNumber of vertical division lines: ")
);setq
; Sit on DEFPOINTS, unlock first in case isolated
(command "layer" "m" "DEFPOINTS" "")
(command "layer" "U" "DEFPOINTS" "")
; Draw the vitual polyline
(command "pline" pt1 pt2 pt3 pt4 "c")
(setq vitual_Polyline (entlast))
(cond
((= Num_Horizontal_Lines 1)
(setq Middle_pt1 (polar pt1 (* pi 0.5) (/ Verticall_Distance 2)) )
(setq Middle_pt2 (polar pt2 (* pi 0.5) (/ Verticall_Distance 2)) )
(command "line" Middle_pt1 Middle_pt2 "")
);
((> Num_Horizontal_Lines 1)
(setq hatch_HORT (* Num_Horizontal_Lines 2))
(setq hatch_OHOR (/ Verticall_Distance hatch_HORT))
(setq hatch_HINS (polar pt1 (* pi 0.5) hatch_OHOR))
(command "-HATCH" "P" "" "0" (* hatch_OHOR 2) "N" "O" "S" hatch_HINS "" "S" vitual_Polyline "" "")
(command "explode" "L")
);
);cond
(cond
((= Num_Verticall_Lines 1)
(setq Middle_pt1 (polar pt1 0 (/ Horizontal_Distance 2)) )
(setq Middle_pt2 (polar pt4 0 (/ Horizontal_Distance 2)) )
(command "line" Middle_pt1 Middle_pt2 "")
);
((> Num_Verticall_Lines 1)
(setq hatch_VERT (* Num_Verticall_Lines 2))
(setq hatch_OVER (/ Horizontal_Distance hatch_VERT))
(setq hatch_VINS (polar pt1 0 hatch_OVER))
(command "-HATCH" "P" "" "90" (* hatch_OVER 2) "N" "O" "S" hatch_VINS "" "S" vitual_Polyline "" "")
(command "explode" "L")
);
);cond
; Cleanup
(command "erase" vitual_Polyline "")
; Restore
(command "layer" "s" ExistingLayer "")
(setvar "OSMODE" ExistingOSMODE)
(princ)
);defun
;;-----------------------------------------------------------------------------