Hello, rehashing an old lisp ported by the owner. I would like to add the option to put a light in the center of the room. with an array of high hat/can lights around it.
;;------------------=={ Custom Block Array }==----------------;;
;; ;;
;; Program will generate a rectangular array of a selected ;;
;; block with a specified number of rows and columns, with ;;
;; blocks spaced uniformly and aligned centrally between two ;;
;; window corner points selected by the user. ;;
;; ;;
;; Upon calling the program, the user is prompted to select ;;
;; a block to be arrayed. Following a valid selection, the ;;
;; user is then prompted to specify the number of rows and ;;
;; columns for the array, with the previously entered ;;
;; figures available as default values. ;;
;; ;;
;; A prompt then asks the user whether grid-lines are to ;;
;; be constructed, such grid-lines intersect at the ;;
;; insertion points of each block in the array and extend ;;
;; to the limits set by the selected corner points. ;;
;; ;;
;; The user is then prompted to pick two corner points of an ;;
;; array window, and the selected block is arrayed evenly ;;
;; between these points, with equal spacing. ;;
;; ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Version 1.1 - 14-09-2011 ;;
;;------------------------------------------------------------;;
(defun c:bArray
(
/
*error* _StartUndo _EndUndo _SelectIf
acdoc bl hd layer msg p0 p1 p2 p3 p4 vd x1 xd yd
)
;;------------------------------------------------------------;;
(setq layer "EST_E_LIGHTING-CONSTRUCION-LINES") ;; Layer for Grid Lines (created if not present)
;;------------------------------------------------------------;;
(defun *error* ( msg )
(if acdoc (_EndUndo acdoc))
(if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
(princ (strcat "\nError: " msg))
)
(princ)
)
(defun _StartUndo ( doc )
(_EndUndo doc)
(vla-StartUndoMark doc)
)
(defun _EndUndo ( doc )
(if (= 8 (logand 8 (getvar 'UNDOCTL)))
(vla-EndUndoMark doc)
)
)
(defun _SelectIf ( msg pred )
(
(lambda ( pred / sel )
(while
(progn (setvar 'ERRNO 0) (setq sel (car (entsel msg)))
(cond
( (= 7 (getvar 'ERRNO))
(princ "\nMissed, Try again.")
)
( (eq 'ENAME (type sel))
(if (and pred (not (pred sel)))
(princ "\nInvalid Object Selected.")
)
)
)
)
)
sel
)
(eval pred)
)
)
(if
(and
(setq bl
(_SelectIf "\nSelect Block to Array: "
(function
(lambda ( x )
(and (eq "INSERT" (cdr (assoc 0 (entget x))))
(zerop
(logand 4
(cdr
(assoc 70
(tblsearch "BLOCK" (cdr (assoc 2 (entget x))))
)
)
)
)
)
)
)
)
)
(progn (initget 6)
(setq *rows*
(cond
(
(getint
(strcat "\nSpecify Number of Rows <"
(itoa
(setq *rows* (cond ( *rows* ) ( 10 )))
)
">: "
)
)
)
( *rows* )
)
)
)
(progn (initget 6)
(setq *cols*
(cond
(
(getint
(strcat "\nSpecify Number of Columns <"
(itoa
(setq *cols* (cond ( *cols* ) ( 10 )))
)
">: "
)
)
)
( *cols* )
)
)
)
(progn (initget "Yes No")
(setq *grid*
(cond
(
(getkword
(strcat "\nConstruct Grid-lines? [Yes/No] <"
(setq *grid* (cond ( *grid* ) ( "Yes" )))
">: "
)
)
)
( *grid* )
)
)
)
(setq p1 (getpoint "\nSpecify First Corner of Array: "))
(setq p2
(
(if (zerop (getvar 'WORLDUCS))
getpoint
getcorner
)
"\nSpecify Opposite Corner of Array: " p1
)
)
)
(progn
(setq p0 (vlax-3D-point (trans (cdr (assoc 10 (entget bl))) bl 0))
bl (vlax-ename->vla-object bl)
hd (- (car p2) (car p1))
vd (- (cadr p2) (cadr p1))
xd (/ hd *cols*)
yd (/ vd *rows*)
x1 (- (car p1) (/ xd 2.0))
p3 (list x1 (- (cadr p1) (/ yd 2.0)) (caddr p1))
p4 (polar P1 (angle P1 P2) (/ (distance P1 P2) 2.0)))
)
(_StartUndo
(setq acdoc
(vla-get-activedocument (vlax-get-acad-object))
)
)
(repeat *rows*
(setq p3 (list x1 (+ (cadr p3) yd) (caddr p3)))
(repeat *cols*
(vla-move (vla-copy bl) p0
(vlax-3D-point
(trans (setq p3 (list (+ (car p3) xd) (cadr p3) (caddr p3))) 1 0)
)
)
)
)
(if (eq "Yes" *grid*)
(progn
(setq p3 (list (car p1) (- (cadr p1) (/ yd 2.0)) (caddr p1)))
(repeat *rows*
(setq p3 (list (car p3) (+ (cadr p3) yd) (caddr p3)))
(entmakex
(list
(cons 0 "LINE")
(cons 8 layer)
(cons 10 (trans p3 1 0))
(cons 11 (trans (list (+ (car p3) hd) (cadr p3) (caddr p3)) 1 0))
)
)
)
(setq p3 (list (- (car p1) (/ xd 2.0)) (cadr p1) (caddr p1)))
(repeat *cols*
(setq p3 (list (+ (car p3) xd) (cadr p3) (caddr p3)))
(entmakex
(list
(cons 0 "LINE")
(cons 8 layer)
(cons 10 (trans p3 1 0))
(cons 11 (trans (list (car p3) (+ (cadr p3) vd) (caddr p3)) 1 0))
)
)
)
)
)
(command "insert" "light" p4)
(_EndUndo acdoc)
)
)
(princ)
)
;;------------------------------------------------------------;;
(vl-load-com) (princ)
;;------------------------------------------------------------;;
;; End of File ;;
;;------------------------------------------------------------;;
I added = p4 (polar P1 (angle P1 P2) (/ (distance P1 P2) 2.0)))
trying to set the center of the room using p1 and p2
I added = (command "insert" "light" p4)
I would think that it would work like this,, eventually I would like the option to ask if you want to add a ceiling light or ,, a fan light.. yes or no
Any input please? Nick
Solved! Go to Solution.
(setq P4 (polar P1 (angle P1 P2) (/ (distance P1 P2) 2.0)))
(command "insert" "light" p4 "" "" "")
(_EndUndo acdoc)
)
)
(princ)
)
I guess that I figured it out.. thanks
(setq P4 (polar P1 (angle P1 P2) (/ (distance P1 P2) 2.0)))
(initget "Yes No")
(if (= "Yes" (getkword "\nAdd a light? [Yes/No] <Yes>: "))
(command "insert" "light" p4 "" "" "")
)
(initget "Yes No")
(if (= "Yes" (getkword "\nAdd a Fan Light? [Yes/No] <No>: "))
(command "insert" "fb" p4 "" "" "")
)
(_EndUndo acdoc)
)
)
(princ)
)
;;------------------------------------------------------------;;
(vl-load-com) (princ)
;;------------------------------------------------------------;;
;; End of File ;;
;;------------------------------------------------------------;;
(defun C:barray2 (/ c1 c2 wid ht rows cols blk); = Lights in Rectangular [& orthogonal] Room
(setq
c1 (getpoint "\nCorner of room: ")
c2 (getpoint "\nOpposite corner: ")
wid (abs (- (car c1) (car c2)))
ht (abs (- (cadr c1) (cadr c2)))
rows (getint "\nNumber of rows (---): ")
cols (getint "\nNumber of columns (|||): ")
); setq
(command
"_.minsert" "csof"
(mapcar '+ ; insertion point
(list (min (car c1) (car c2)) (min (cadr c1) (cadr c2))); lower left of room
(list (/ wid cols 2) (/ ht rows 2)); fractions of width/height
); mapcar
"" "" "" ; X, Y, rotation defaults -- edit if needed
rows cols (/ ht rows) (/ wid cols); numbers and spacings
(setq c3 (polar c1 (angle c1 c2) (/ (distance c1 c2) 2.0)))
)
(initget "Yes No")
(if (= "Yes" (getkword "\nAdd a Light? [Yes/No] <Yes>: "))
(command "insert" "light" c3 "" "" "")
)
(initget "Yes No")
(if (= "Yes" (getkword "\nAdd a Fan Light? [Yes/No] <No>: "))
(command "insert" "fb" c3 "" "" "")
)
(princ)
)
Hello, how do I set the defaults for the rows to (2), columns to (2)
and a default Yes for add a light?
Thanks Nick
@Anonymous wrote:
....
Hello, how do I set the defaults for the rows to (2), columns to (2)
and a default Yes for add a light?
....
One way, if you want it always to default to 2 [not to remember your previous value and offer that, which is also possible]:
(setq
....
rows
(cond
((getint "\nNumber of rows (---) <2>: ")); User input
(2); User Enter above [returns nil]
); cond
cols
(cond
((getint "\nNumber of columns (|||) <2>: "))
(2)
); cond
....
); setq
For the light:
(initget "Yes No")
(if (/= "No" (getkword "\nAdd a Light? [Yes/No] <Yes>: "))
(command "insert" "light" c3 "" "" "")
)
(defun C:barray2 (/ c1 c2 wid ht rows cols blk); = Lights in Rectangular [& orthogonal] Room
(setq
c1 (getpoint "\nCorner of room: ")
c2 (getpoint "\nOpposite corner: ")
wid (abs (- (car c1) (car c2)))
ht (abs (- (cadr c1) (cadr c2)))
); setq
(cond
((getint "\nNumber of rows (---) <2>: ")); User input
(2); User Enter above [returns nil]
); cond
cols
(cond
((getint "\nNumber of columns (|||) <2>: ")); User input
(2); User Enter above [returns nil]
); cond
(command
"_.minsert" "csof"
(mapcar '+ ; insertion point
(list (min (car c1) (car c2)) (min (cadr c1) (cadr c2))); lower left of room
(list (/ wid cols 2) (/ ht rows 2)); fractions of width/height
); mapcar
"" "" "" ; X, Y, rotation defaults -- edit if needed
rows cols (/ ht rows) (/ wid cols); numbers and spacings
(setq c3 (polar c1 (angle c1 c2) (/ (distance c1 c2) 2.0)))
)
(initget "Yes No")
(if (/= "No" (getkword "\nAdd a Light? [Yes/No] <Yes>: "))
(command "insert" "light" c3 "" "" "")
)
(initget "Yes No")
(if (= "Yes" (getkword "\nAdd a Fan Light? [Yes/No] <No>: "))
(command "insert" "fb" c3 "" "" "")
)
(princ)
)
Hrm,, its not setting the system variable. Pulling my hair out over here. 🙂
Nick
Your line to end the (setq) function:
); setq
is way too soon, and you omitted the variable name -- rows -- before the part that puts a value in it.
Can't find what you're looking for? Ask the community or share your knowledge.