Jump to content

Recommended Posts

Posted

I am trying to write a lisp for creating millwork. I have the thing written to draw all the items exept those that are to be either mirrored or arrayed. What I am needing is some help in writing an if then function. If the number of bays equals an even number the mirror and array the items x times.......if bays is odd then mirror and array items x-1 times then draw odd bay.

 

I am not a noob, but have not programmed in a few years so am rusty on the commands and functions. Can any one recommend a decent site for me to brush up on my routines?

Posted

Here's an example to test for even/odd

(defun c:test ()
 (setq int (getint "Enter number of bays: "))
 (if
   (> (rem int 2) 0)
   (progn
   (alert "There are an odd number of bays"); mirror and array code here
   );progn
   (progn
   (alert "There are an even number of bays"); mirror and array code here
   );progn
   )
 )

Do you want help with the mirror/array too? More info is needed...

 

Here's a couple of sites I find helpful

http://afralisp.net/

http://ronleigh.info/autolisp/index.htm

 

BTW... your profile says LT, no lisp unless you have an add on.

Posted

I'll try that here in a second. Thanks for the quick reply. I am using lt I have the drcauto toolkit. Not real helpful except the lisp support.

 

As for the array and mirror support I think I got that down pat. I just had no clue as to where to go for the odd even. Hopefully this works, if not you'll know. Thanks for the help!!!!

Posted

Ok so here is the code. It runs fine on ecept the odd/even function. Either I'm a moron (which is likely) or I need more help on how to defin what to do if there is a odd number. HELP!!!!

 

 
(DEFUN C:MILL ()
 (setq p1 (getpoint "\nPick lower left corner : "))
 (setq c1 (getpoint "\nPick right extents of cabinets : "))
 (setq p2 (list (car c1)(cadr p1)))
 (setq p3 (list (car p2)(+ (cadr p2) 34)))
 (setq p4 (list (car p1)(+ (cadr p1) 34)))
 (command "layer" "s" "a-mill" "")
 (command "line" p1 p2 "")
  (command "chprop" "l" "" "c" "6" "")
 (command "line" p3 p4 "")
 (setq p5 (list (car p1)(+ (cadr p1) 4)))
 (setq p6 (list (car p2)(cadr p5)))
 (command "line" p5 p6 "")
 (setq p7 (list (+ (car p1) 0.75)(+ (cadr p5) 0.75)))
 (setq p8 (list (- (car p2) 0.75)(cadr p7)))
 (command "line" p7 p8 "")
  (command "chprop" "l" "" "c" "2" "")
  (command "chprop" "l" "" "lt" "hidden2" "")
 (setq p9 (list (car p7)(+ (cadr p6) 10.75)))
 (setq p10 (list (car p8)(cadr p9)))
 (command "line" p9 p10 "")
  (command "chprop" "l" "" "c" "2" "")
  (command "chprop" "l" "" "lt" "hidden2" "")
 (setq p11 (list (car p9)(+ (cadr p9) 0.75)))
 (setq p12 (list (car p10)(cadr p11)))
 (command "line" p11 p12 "")
  (command "chprop" "l" "" "c" "2" "")
  (command "chprop" "l" "" "lt" "hidden2" "")
 (setq p13 (list (car p1)(- (cadr p4) 1.5)))
 (setq p14 (list (car p2)(cadr p13)))
 (command "line" p13 p14 "")
 (command "line" p1 p4 "")
 (command "line" p2 p3 "")
 (setq dist (distance p1 p2))
 (setq dist1 (- dist 3))
  (setq bays (/ dist1 18))
   (setq bays2 (fix bays))
   (setq spaces (/ bays2 2))
   (setq spaces2 (* spaces 1.5))
  (setq dist2 (- dist1 spaces2))
  (setq dist3 (/ dist2 bays2))
(setq d1 (list (+ (car p1) 1.5)(+ (cadr p1) 4)))
(setq d2 (list (+ (car d1) dist3)(+ (cadr d1) 21.5)))
 (command "rectangle" d1 d2)
(setq c1 (entlast))
(setq dr1 (list (car d1)(+ (cadr d2) 0.5)))
(setq dr2 (list (- (car d2) 0.75)(+ (cadr dr1) 5.5)))
 (command "rectangle" dr1 dr2)
 (setq dra1 (entlast))
(setq dr3 (list (+ (car dr2) 1.5)(cadr dr1)))
(setq dr4 (list (- (+ (car dr3) dist3) 0.75)(cadr dr2)))
 (command "rectangle" dr3 dr4)
 (setq dra2 (entlast))
(setq d3 (list (+ (car d2) dist3)(cadr d1)))
 (command "rectangle" d2 d3)
 (setq c2 (entlast))
 (if
   (> (rem bays2 2) 0)
   (progn
(setq adist (+ (* dist3 2) 1.5))
(setq columns (/ bays2 2))
(command "array" c1 c2 dra1 dra2 "" "" "" columns adist "")
)
(progn
 (setq adist (+ (* dist3 2) 1.5))
(setq columns (/ bays2 2))
(command "array" c1 c2 dra1 dra2 "" "" "" columns adist "")
(setq ec1 (list (- (car p8) 1.5)(cadr d1)))
(setq ec2 (list (- (car ec1) dist3)(+ (cadr ec1) 21.5)))
 (command "rectangle" ec1 ec2)
  (setq endc (entlast))
(setq ed1 (list (car ec1)(+ (cadr ec2) 0.5)))
(setq ed2 (list (+ (car ec2) 0.75)(+ (cadr ed1) 5.5)))
 (command "rectangle" ed1 ed2)
 (setq edr (entlast))
))
)

Posted

oooops just a moron. I fingered it out! Thanks again!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...