Author Topic: my first lisp. weahhh  (Read 2563 times)

0 Members and 1 Guest are viewing this topic.

diarmuid

  • Bull Frog
  • Posts: 417
my first lisp. weahhh
« on: September 04, 2006, 04:22:11 AM »
Howdy folks,

Below Iíve posted a lisp routine (my first, yeahhhhh). :-P 
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




Code: [Select]
(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.
« Last Edit: September 04, 2006, 05:25:37 AM by jonesy »
If you want to win something run the 100m, if you want to experience something run a marathon

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: my first lisp. weahhh
« Reply #1 on: September 04, 2006, 06:29:27 AM »
I'm impressed for a first effort ..


.. very impressed with your time management skills too
Quote
created on 25.09.2006


Investigate the (command "UNDO" "Mark" etc options, that may solve your restore quandry.
kdub in one timeline.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<-

diarmuid

  • Bull Frog
  • Posts: 417
Re: my first lisp. weahhh
« Reply #2 on: September 04, 2006, 10:05:51 AM »
I've jumped the gun a small bit.  below was the level of complexety of the lisps that i have created. very basic stuff, the one that i have posted above was easily the most complicated routine that i have ever done, and not without help. i've been snooping this site among many others for help fro various problems.  i couldn't have done it with out help from these places.

thanks for your complements by the way.


Code: [Select]
(defun c:0()
(command "-layer" "set" "0" "")
)

(defun c:LZ()
(command "-layer" "make" "XREF" "c" "9" "" "")
(command "-layer" "make" "VP1" "c" "1" "" "")
)

(defun c:xx()
(command "-layer" "make" "XREF" "c" "9" "" "")
)
(defun c:ha()
(command "-layer" "make" "hatch" "c" "15" "" "")
)
(defun c:hs()
(command "-layer" "make" "H_STEEL" "c" "6" "" "")
)

;----------------------------------------------------------
(defun c:byl(/ byla)
(setq byla(ssget))
(command "_change" byla "" "p" "c" "bylayer" "lt" "bylayer" "")
(princ)
)

(defun c:bylc(/ bylc)
(setq bylc(ssget))
(command "_change" bylc "" "p" "c" "bylayer" "" "")
(princ)
)

(defun c:byllt(/byllt)
(setq byllt(ssget))
(command "_change" byllt "" "p" "lt" "bylayer" "" "")
)

; change a selection set to dashed line type

(defun c:dsh(/ dshsel)
(setq dshsel(ssget))
(command "_change" dshsel ""  "p" "lt" "dashed" "")
(princ)
)

;----------------------------------------------------------
(defun c:L0(/ sell0)
(setq sell0(ssget))
(command "_change" sell0 ""  "p" "layer" "0" "")
(princ)
)
;--------

EDIT - added code tags (Jonesy)
« Last Edit: September 04, 2006, 10:08:46 AM by jonesy »
If you want to win something run the 100m, if you want to experience something run a marathon

jmamu

  • Guest
Re: my first lisp. weahhh
« Reply #3 on: September 04, 2006, 06:31:58 PM »
That's great!!

As Kerry Brown said you have to check (command "_undo" "_mark" ... and (setvar .... .
That will help you!!

Regards!!

I've jumped the gun a small bit.  below was the level of complexety of the lisps that i have created. very basic stuff, the one that i have posted above was easily the most complicated routine that i have ever done, and not without help. i've been snooping this site among many others for help fro various problems.  i couldn't have done it with out help from these places.

thanks for your complements by the way.


Code: [Select]
(defun c:0()
(command "-layer" "set" "0" "")
)

(defun c:LZ()
(command "-layer" "make" "XREF" "c" "9" "" "")
(command "-layer" "make" "VP1" "c" "1" "" "")
)
[/quote]