Thank you Very much,
I have taken your code from suggested link but not asking for no.of rows and columns. I have created 2 blocks wuth names mentioned in below code. When I used the lisp code only one block was placed in center of rectangle.
(setvar 'cmdecho 0)
(command "_.layer" "_make" "M-FIRE-SYMB-P" "_color" "2" "" "")
(setvar 'cmdecho 1)
(vl-load-com)
(defun SS (blkname / *error* ssia doc svnames svvals P1 rectss n ucschanged P3)
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
(princ (strcat "\nError: " errmsg))
); if
(if ucschanged (command-s "_.ucs" "_previous"))
; [change to (command ... if Acad version predates (command-s) function]
(mapcar 'setvar svnames svvals); reset System Variables
(vla-endundomark doc)
(princ)
); defun - *error*
(defun ssia (/ delta LL NX NY DS1 DS2); = SS Insert & Array
(setq
delta (mapcar 'abs (mapcar '- P3 P1)); differences in XYZ list
LL (mapcar 'min P1 P3)
; Lower Left regardless of pick order or Pline start or direction
NX (+ (fix (/ (car delta) dis)) 1)
DS1 (/ (car delta) NX)
DSS1 (/ area DS1)
NY (+ (fix (/ (cadr delta) DSS1)) 1)
DS2 (/ (cadr delta) NY)
); setq
(command
"_.insert" blkname "_none" (mapcar '+ LL (list (/ DS1 2) (/ DS2 2))) "" "" ""
"_.array" "_last" "" "_r" NY NX
); command [leaves it in Array awaiting spacing(s)
(cond
((= NX 1) (command DS2))
((= NY 1) (command DS1))
(T (command DS2 DS1))
); cond
); defun -- ssia
(vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
(setq ; System Variable saving/resetting without separate variables for each:
svnames '(cmdecho ucsfollow osmode blipmode)
svvals (mapcar 'getvar svnames)
); setq
(mapcar 'setvar svnames '(0 0)); turn off command echoing, UCS follow
(initget "Light Ordinary Extra")
(setq haz (getkword "\nSpeciefy Space Hazard Type [Light/Ordinary/Extra]: "))
(if (= haz "Light")
(setq
dis 4600
area 21000000
)
(progn
(if (= haz "Ordinary")
(setq
dis 4600
area 12000000
)
)
(progn
(if (= haz "Extra")
(setq
dis 3700
area 9000000
)
)
)
)
)
(initget "Select"); allows S as input to (getpoint) function, instead of point pick
(setq P1 (getpoint "\nFirst Corner of rectangular area for Sprinklers, or [Select]: "))
; [if in non-World UCS, returns in current UCS coordinates, not in WCS]
(if (= P1 "Select"); chose that option
(progn ; then
(prompt "\nTo distribute Sprinklers in rectangular Polylines,")
(if (setq rectss (ssget '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&") (70 . 1))))
; multiple selection -- only 4-vertex closed [does not check for rectangularity]
(progn ; then
(mapcar 'setvar svnames '(0 0 0 0)); also turn off Osnap, blips
(repeat (setq n (sslength rectss)); step through selection
(setq rect (ssname rectss (setq n (1- n))))
(command "_.ucs" "_object" rect)
(setq
ucschanged T ; marker for resetting in *error*
P1 (trans (vlax-curve-getPointAtParam rect 0) 0 1); starting vertex
P3 (trans (vlax-curve-getPointAtParam rect 2) 0 1); third vertex [opposite corner]
); setq
(ssia); run the subroutine to Insert and Array
(command "_.ucs" "_previous")
(setq ucschanged nil); [turn off marker]
); repeat
); progn
(prompt "\nNo closed 4-vertex Polyline(s) selected."); else
); if
); progn
(progn ; else [picked a point]
(setq P3 (getcorner P1 "\nOpposite Corner: "))
(mapcar 'setvar svnames '(0 0 0 0)); also turn off Osnap, blips
(ssia); run the subroutine to Insert and Array
); progn
); if
(mapcar 'setvar svnames svvals); reset System Variables
(vla-endundomark doc)
(princ)
); defun -- SS
(defun C:SSP ()
(SS "M-FFSP-PE02-P")
); defun
(defun C:SSU ()
(SS "M-FFSP-UP01-P")
); defun
(prompt "\n THIS PROGRAM FOR SPRINKLER DISTRIBUTION ")
(prompt "\n START command by : SSP:PENDANT SSU:UPRIGHT ")
(prompt "\n\n CREATED by :\n ********* M.SAIED. ********* ")
(prompt "\n MODIFIED by :\n ********* Saber Elkassas & Kent Cooper. ********* ")
(princ)