Howdy folks,

Below I’ve posted a lisp routine (my first, yeahhhhh).

It’s a metric based insert a window routine. You enter the ope size of the window, pick a point on the OUTSIDE face, and on the same side of the opening pick the inside face, the window is then drawn in place. It can of course be adapted to imperial, just change the values in the routine.

All comments suggestions will be greatly appreciated. Fyi. I chose to call my bearings after clock times. That way it was easier for me to remember which angle was which.

One minor question. Is there something I can add to the routine that will allow me to go back to the beginning of the routine if I undo. i.e. I jump back to the state , before I ran the routine

Thanks in advance

`(defun c:dr(/ layerold offdistold oldsnap p1 p2 objlast obj8 objlastlayer wallwidth 6oclock deg6oc deg3oc deg12oc rad3 12oclock p3 p4 f1 ope ope2 radf degf 3oclock f2`

)

(setq lold(getvar "clayer")); get the current layer

(command "-layer" "make" "_testlayer" "c" "2" "" ""); creates a layer for doing the routine.

(setq offold(getvar "offsetdist")); get the offset distance

(setq osold(getvar "osmode")); get the osmode value

;calculating openings sizes, and block types

(princ"\nDoor insert routine, by Diarmuid Ryan created on 25.09.2006")

(setq ope(getreal"\nenter the actual structural ope size... ."))

(setq ope2 (/ ope 2))

(setq dname (strcat (rtos ope 2 0) "d"))

;draw the first line of the ope

(setq oldsnap(getvar "osmode"))

(setvar "osmode" 512)

(command "-layer" "make" "wall" "c" "4" "" "") ; set the wall layer

(princ "\n pick the 1st point of the ope... (this is the hinge side of the door)")

(setq p1(getpoint))

(setvar "osmode" 128)

(princ "\n pick the 2nd point (the same side as the hinge side of the door)...")

(setq p2(getpoint p1 ))

;calculate the width of the wall

(command "line" p1 p2 "")

(setq wallw(distance p1 p2))

(setq halfwall( / wallw 2))

(setq 6oclock (angle p1 p2))

(setq deg6oc (* 180.0 (/ 6oclock pi)))

(setq deg3oc (+ deg6oc 90))

(setq 3oclock (* pi (/ deg3oc 180.0)))

(setq p3 (polar p2 3oclock ope))

;draw the second line

(setq deg12oc (+ deg3oc 90))

(princ"\ncalulating radians")

(setq 12oclock (* pi (/ deg12oc 180.0)))

(setq p4 (polar p3 12oclock wallw))

(command "line" p3 p4 "")

;calculating the midpoint of p1 p2

(princ "\ncalculating midpoints.....")

(setq p1a(polar p2 12oclock halfwall))

(setq p4a(polar p3 12oclock halfwall))

(setvar "osmode" oldsnap)

(princ "\ndrawing door frame")

(setq wp1(polar p1a 12oclock 50))

(setq wp2(polar p1a 6oclock 50))

(setq wp3(polar wp2 3oclock ope))

(setq wp4(polar wp3 12oclock 100))

(setq deg9oc (- deg6oc 90))

(setq 9oclock (* pi (/ deg9oc 180.0)))

(setq wp5(polar wp1 3oclock 50))

(setq wp6(polar wp2 3oclock 50))

(setq wp7(polar wp3 9oclock 50))

(setq wp8(polar wp4 9oclock 50))

(princ "\nDrawing door...")

(setq d1 (polar wp6 6oclock (- ope 100)))

(setq d2 (polar d1 3oclock 50))

(setq d3 (polar d2 12oclock (- ope 100)))

;calculating fence line....

;f1

(princ"\ncalulating radians....")

(setq f1 (polar p2 3oclock ope2))

;calculating fence line....

;f2

(princ"\ncalulating fence line....")

(setq f2 (polar p1 3oclock ope2))

(command "-layer" "make" "door" "c" "5" "" "" );set the proper layer for the window

(command "break" f2 "first" p1 p4 )

(command "break" f1 "first" p2 p3 )

;calculating insertion point & reseting the values before the routine was run...

(princ "\nlocating the swing point of door.....")

(command "pline" d1 wp6 wp2 wp1 wp5 wp6 d3 d2 d1 "arc" "r" (- ope 100 ) wp7 "l" wp3 wp4 wp8 wp7 "")

(command "draworder" "l" "" "back")

(command "-layer" "s" lold "" )

(command "offsetdist" offold)

(princ "\nDoor Inserted")

)

Edit by Jonesy - Added code tags.