Exchange Forum > Dcl Dialogs
L-Shapes dialog for angles
L-Shapes dialog for angles

#1

Trevor
Join Date:
07-29-2007
I'm working on L-Shapes and I'm having a major glitch with the Thks list for the thicknesses. Once I get through this I'll be using the data from the manual of Steel Construction. The function has the main DataList which contains items for Leg1, Leg2, Thk, Kdim, & Weight. I included Weight because it might come in handy for calculating the weights in another program later on.
 
The program will use three lists for Leg1s, Leg2s & Thks. Leg1s will change Leg2s & Thks, and Leg2s will change the Thks list. Here is a run of the TestLshapes function to get it working. The last two lists Leg2Thks and Thks is where I'm having the glitch. They should be Leg2Thks = (list (2-1/2 1/4 3/8) (3 7/16 1/2)) and Thks = (list 7/16 1/2). I'd appreciate any help with figuring this one out.
Thanks,
Trevor
Quote:
Command: TestLshapes 
DataList = 
(3 2 3/16 0.5 3.07) 
(3 2 1/4 0.5625 4.1) 
(3 2-1/2 3/8 0.75 6.6) 
(3 2-1/2 1/2 0.875 8.5) 
(3-1/2 2-1/2 1/4 0.6875 4.9) 
(3-1/2 2-1/2 3/8 0.8125 7.2) 
(3-1/2 3 7/16 0.875 9.1) 
(3-1/2 3 1/2 0.9375 10.2) 
(4 3 1/4 0.6875 5.8) 
(4 3 3/8 0.8125 8.5) 
(4 3-1/2 5/16 0.75 7.7) 
(4 3-1/2 7/16 0.875 10.6) 
Leg1Leg2s = ((3 2 2-1/2) (3-1/2 2-1/2 3) (4 3 3-1/2)) 
Leg1s = (3 3-1/2 4) 
Leg1 = 3-1/2 
Leg2 = 3 
Leg2s = (2-1/2 3) 
Leg2Thks = ((2-1/2 2-1/2 2-1/2) (3 3 3)) 
Thks = (3 3)
Code:
(defun c:TestLshapes ()
  (setq DataList (list;Leg1 Leg2 Thk Kdim Weight
    (list "3"     "2"     "3/16"  0.5     3.07)
    (list "3"     "2"     "1/4"   0.5625  4.1)
    (list "3"     "2-1/2" "3/8"   0.75    6.6)
    (list "3"     "2-1/2" "1/2"   0.875   8.5)
    (list "3-1/2" "2-1/2" "1/4"   0.6875  4.9)
    (list "3-1/2" "2-1/2" "3/8"   0.8125  7.2)
    (list "3-1/2" "3"     "7/16"  0.875   9.1)
    (list "3-1/2" "3"     "1/2"   0.9375  10.2)
    (list "4"     "3"     "1/4"   0.6875  5.8)
    (list "4"     "3"     "3/8"   0.8125  8.5)
    (list "4"     "3-1/2" "5/16"  0.75    7.7)
    (list "4"     "3-1/2" "7/16"  0.875   10.6)
    )
  )
  (setq Leg1Leg2s nil Leg1s nil)
  (foreach Data DataList
    (if (not (member (car Data) Leg1s))
      (setq Leg1s (append Leg1s (list (car Data))))
    )
  )
  (foreach Num Leg1s
    (setq Info (list Num))
    (foreach Data DataList
      (if (and (= (car Data) Num)(not (member (cadr Data) (cdr Info))))
        (setq Info (append Info (list (cadr Data))))
      )
    )
    (setq Leg1Leg2s (append Leg1Leg2s (list Info)))
  )
  (princ "\nDataList = ")
  (foreach Data DataList
    (princ "\n")(princ Data)
  )
  (princ "\nLeg1Leg2s = ")(princ Leg1Leg2s)
  (princ "\nLeg1s = ")(princ Leg1s)
  (setq Leg1 "3-1/2")(princ "\nLeg1 = ")(princ Leg1)
  (setq Leg2 "3")(princ "\nLeg2 = ")(princ Leg2)
  (setq Leg2s (cdr (assoc Leg1 Leg1Leg2s)))
  (princ "\nLeg2s = ")(princ Leg2s)
  (setq Leg2Thks nil)
  (foreach Num Leg2s
    (setq Info (list Num))
    (foreach Data DataList
      (if (and (= (car Data) Leg1)(= (cadr Data) Num)(not (member (caddr Data) (cdr Info))))
        (setq Info (append Info (list (cadr Data))))
      )
    )
    (setq Leg2Thks (append Leg2Thks (list Info)))
  )
  (princ "\nLeg2Thks = ")(princ Leg2Thks)
  (setq Thks (cdr (assoc Leg2 Leg2Thks)))
  (princ "\nThks = ")(princ Thks)
  (princ)
)
L-Shapes dialog for angles

#2

Bennett
Join Date:
07-26-2007
Trevor,
Your program is doing exactly what you put in the code, but not what you intended or you wanted. The functions like caaar, caadr, caar, cadar, cadddr, caddr, cadr, car, cdaar, cdadr, cdar, cddar, cdddr, cddr, and cdr can be very confusing sometimes especially if you're tired. If you can replace them with the nth function instead, you are much better off. In your program the cdr function is necessary to return a list starting with the second item in the list. But the car, cadr and caddr functions can be replaced with the easier to read nth function.
Here's a simple example of what I'm referring to.
(setq abc (list "a" "b" "c" "d"))
(cdr abc) = ("b" "c" "d");Needed
(car abc) & (nth 0 abc) = "a"
(cadr abc) & (nth 1 abc) = "b"
(caddr abc) & (nth 2 abc) = "c"
(cadddr abc) & (nth 3 abc) = "d"
Code:
(defun c:Test1-Lshapes ()
  (setq DataList (list;Leg1 Leg2 Thk Kdim Weight
    (list "3"     "2"     "3/16"  0.5     3.07)
    (list "3"     "2"     "1/4"   0.5625  4.1)
    (list "3"     "2-1/2" "3/8"   0.75    6.6)
    (list "3"     "2-1/2" "1/2"   0.875   8.5)
    (list "3-1/2" "2-1/2" "1/4"   0.6875  4.9)
    (list "3-1/2" "2-1/2" "3/8"   0.8125  7.2)
    (list "3-1/2" "3"     "7/16"  0.875   9.1)
    (list "3-1/2" "3"     "1/2"   0.9375  10.2)
    (list "4"     "3"     "1/4"   0.6875  5.8)
    (list "4"     "3"     "3/8"   0.8125  8.5)
    (list "4"     "3-1/2" "5/16"  0.75    7.7)
    (list "4"     "3-1/2" "7/16"  0.875   10.6)
    )
  )
  (setq Leg1Leg2s nil Leg1s nil)
  (foreach Data DataList
    (if (not (member (car Data) Leg1s))
      (setq Leg1s (append Leg1s (list (car Data))))
    )
  )
  (foreach Num Leg1s
    (setq Info (list Num))
    (foreach Data DataList
      (if (and (= (car Data) Num)(not (member (cadr Data) (cdr Info))))
        (setq Info (append Info (list (cadr Data))))
      )
    )
    (setq Leg1Leg2s (append Leg1Leg2s (list Info)))
  )
  (princ "\nDataList = ")
  (foreach Data DataList
    (princ "\n")(princ Data)
  )
  (princ "\nLeg1Leg2s = ")(princ Leg1Leg2s)
  (princ "\nLeg1s = ")(princ Leg1s)
  (setq Leg1 "3-1/2")(princ "\nLeg1 = ")(princ Leg1)
  (setq Leg2 "3")(princ "\nLeg2 = ")(princ Leg2)
  (setq Leg2s (cdr (assoc Leg1 Leg1Leg2s)))
  (princ "\nLeg2s = ")(princ Leg2s)
  (setq Leg2Thks nil)
  (foreach Num Leg2s
    (setq Info (list Num))
    (foreach Data DataList
      (if (and (= (car Data) Leg1)(= (cadr Data) Num)(not (member (caddr Data) (cdr Info))))
        (setq Info (append Info (list (caddr Data))));<-- This line!
      )
    )
    (setq Leg2Thks (append Leg2Thks (list Info)))
  )
  (princ "\nLeg2Thks = ")(princ Leg2Thks)
  (setq Thks (cdr (assoc Leg2 Leg2Thks)))
  (princ "\nThks = ")(princ Thks)
  (princ)
)
Version substituting car, cadr, and caddr with nth functions:
Code:
(defun c:Test2-Lshapes ()
  (setq DataList (list;Leg1 Leg2 Thk Kdim Weight
    (list "3"     "2"     "3/16"  0.5     3.07)
    (list "3"     "2"     "1/4"   0.5625  4.1)
    (list "3"     "2-1/2" "3/8"   0.75    6.6)
    (list "3"     "2-1/2" "1/2"   0.875   8.5)
    (list "3-1/2" "2-1/2" "1/4"   0.6875  4.9)
    (list "3-1/2" "2-1/2" "3/8"   0.8125  7.2)
    (list "3-1/2" "3"     "7/16"  0.875   9.1)
    (list "3-1/2" "3"     "1/2"   0.9375  10.2)
    (list "4"     "3"     "1/4"   0.6875  5.8)
    (list "4"     "3"     "3/8"   0.8125  8.5)
    (list "4"     "3-1/2" "5/16"  0.75    7.7)
    (list "4"     "3-1/2" "7/16"  0.875   10.6)
    )
  )
  (setq Leg1Leg2s nil Leg1s nil)
  (foreach Data DataList
    (if (not (member (nth 0 Data) Leg1s))
      (setq Leg1s (append Leg1s (list (nth 0 Data))))
    )
  )
  (foreach Num Leg1s
    (setq Info (list Num))
    (foreach Data DataList
      (if (and (= (nth 0 Data) Num)(not (member (nth 1 Data) (cdr Info))))
        (setq Info (append Info (list (nth 1 Data))))
      )
    )
    (setq Leg1Leg2s (append Leg1Leg2s (list Info)))
  )
  (princ "\nDataList = ")
  (foreach Data DataList
    (princ "\n")(princ Data)
  )
  (princ "\nLeg1Leg2s = ")(princ Leg1Leg2s)
  (princ "\nLeg1s = ")(princ Leg1s)
  (setq Leg1 "3-1/2")(princ "\nLeg1 = ")(princ Leg1)
  (setq Leg2 "3")(princ "\nLeg2 = ")(princ Leg2)
  (setq Leg2s (cdr (assoc Leg1 Leg1Leg2s)))
  (princ "\nLeg2s = ")(princ Leg2s)
  (setq Leg2Thks nil)
  (foreach Num Leg2s
    (setq Info (list Num))
    (foreach Data DataList
      (if (and (= (nth 0 Data) Leg1)(= (nth 1 Data) Num)(not (member (nth 2 Data) (cdr Info))))
        (setq Info (append Info (list (nth 2 Data))))
      )
    )
    (setq Leg2Thks (append Leg2Thks (list Info)))
  )
  (princ "\nLeg2Thks = ")(princ Leg2Thks)
  (setq Thks (cdr (assoc Leg2 Leg2Thks)))
  (princ "\nThks = ")(princ Thks)
  (princ)
)
L-Shapes dialog for angles

#3

Trevor
Join Date:
07-29-2007
Bennett,
Thanks for looking into my function and for the information on car, cadr, and caddr functions. You're right about using the nth function. It does make it easier to understand and debug.
Trevor
L-Shapes dialog for angles

#4

Trevor
Join Date:
07-29-2007
I finished writing the code for the L-shapes dialog for drawing angles. It went fairly smooth after figuring out how to change the thickness list. In the dialog I also added the option to mirror the L-shape instead of prompting on the command line. I was able to use the W-shapes dialog as a template. Please test it and let me know if you find any bugs in the code.
Thanks,
Trevor



Attachments  L-shapes.lsp    L-shapes.dcl    L-shapes.gif