TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Curious Drafter on June 17, 2022, 02:41:45 PM

Title: Still learning, but now trying to make an "L" shape.
Post by: Curious Drafter on June 17, 2022, 02:41:45 PM
Thank you to everyone who helped last time I tried making a LISP and a pre thank you for any advice and guidance.

I am trying to make an "L" shape using polylines. The goal is to be able to set the leg lengths and thickness. I will eventually need to be able to have the legs vary in length, but keep the same thickness. So far I have the following thrown together:

Code - Auto/Visual Lisp: [Select]
  1. (defun C:BAA ()
  2.  
  3.         (setq pt (getpoint "Choose a starting point"))
  4.                
  5.                 (setq ptx (nth 0 pt))
  6.                        
  7.                         (setq pty (nth 1 pt))
  8.  
  9.                                 (setq LG1 (getreal "How long is the 1st leg?"))
  10.  
  11.                                         (setq THK1 (getreal "How thick is the member?"))
  12.  
  13.                                                         (setq x1 (+ pty LG1))
  14.  
  15.                                                 (setq pt1 (list x1 ptx 0))
  16.                                                                
  17.                                         (setq y1 (+ pty THK1))
  18.  
  19.                                 (setq pt2 (- x1 THK1))
  20.  
  21.                         (setq pt3 (list ptx y1 0))
  22.  
  23.                 (setq pt4 (- pty THK1))
  24.  
  25.         (command "pline" pt pt1 pt2 pt3 pt4 "c")
  26.  
  27. ) ;Closes defun.

I know I need to adjust the points and lengths (as it's trying to make a triangle right now), but I am trying to narrow down what needs switched around.

I am very grateful for any and all help.
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: Grrr1337 on June 17, 2022, 06:19:13 PM
Hi, heres a quick example. Not sure if thats what you are after -
Code - Auto/Visual Lisp: [Select]
  1. ; Sample chart:
  2. ;
  3. ;   pt_legYaxis
  4. ;    |  | ipt_legYaxis
  5. ;    |  |
  6. ;    |  |
  7. ;    |  | ipt
  8. ;    |  |___________ ipt_legXaxis
  9. ; pt |________________ pt_legXaxis
  10. ;
  11. ;
  12. (defun C:BAA ( / pt LG1 LG2 THK1 pt_legYaxis pt_legXaxis ipt_legYaxis ipt_legXaxis ipt ) ; always localise your variables
  13.  
  14.   (if
  15.     (and ; code block that collects all the user's inputs
  16.       (setq pt (getpoint "Choose a starting point"))
  17.       (setq LG1 (getreal "How long is the 1st leg?"))
  18.       (setq LG2 (getreal "How long is the 2nd leg?"))
  19.       (setq THK1 (getreal "How thick is the member?"))
  20.     ); and
  21.     (progn ; code block that processes the inputs
  22.       (setq pt_legYaxis (mapcar '+ pt (list 0.0 LG1 0.0))) ; calculate the vertical leg by adding 'LG1' distance to 'pt's Y coordinate
  23.       (setq pt_legXaxis (mapcar '+ pt (list LG2 0.0 0.0))) ; calculate the horizontal leg by adding 'LG2' distance to 'pt's X coordinate
  24.       (setq ipt_legYaxis (mapcar '+ pt_legYaxis (list THK1 0.0 0.0))) ; calculate the inner top vertex by adding 'THK1' distance on 'ipt_legYaxis' s X coordinate
  25.       (setq ipt_legXaxis (mapcar '+ pt_legXaxis (list 0.0 THK1 0.0))) ; calculate the inner bottom vertex by adding 'THK1' distance on 'ipt_legXaxis' s Y coordinate
  26.       (setq ipt (mapcar '+ pt (list THK1 THK1 0.0))) ; calculate the inner intersection by adding 'THK1' distance on 'pt's X coordinate and Y coordinate
  27.      
  28.       (command "_.pline" pt pt_legXaxis ipt_legXaxis ipt ipt_legYaxis pt_legYaxis "c") ; invoke polyline command and order the point arguments to shape an outline
  29.     ); progn
  30.     (alert "User interrupted an input")
  31.   ); if
  32.   (princ)
  33. ); defun C:BAA
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: BIGAL on June 17, 2022, 10:12:44 PM
Grrr1337 has provided a good solution

You can change input to this if you want.

(http://)

Code: [Select]
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Enter values " "1st leg Len " 10 9 "6" "2nd leg len" 10 9 "6" "Thickness " 10 9 "1" )))
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: Curious Drafter on June 20, 2022, 09:07:58 AM
That command does work amazing and I am learning a lot from checking out what each line does, but I was wondering if there would be an easy way to incorporate the angle (plus or minus 90 degrees) and a fillet on the outside of the angle. I am hoping to start the incorporation now, so that later I can have it change based on user input.

thank you for all your help and guidance, it is greatly appreciated.
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: Grrr1337 on June 20, 2022, 11:11:05 AM
You have your 'regular' points for describing the shape, for such recalculation you might need some point-rotating and/or point-reflecting subfunctions.

Here are few links from a quick google search:
Rotate a list of points (https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/rotate-a-list-of-points/td-p/1569846)
How to calculate mirrored point (https://www.theswamp.org/index.php?topic=43041.0)

For me personally to perform such tasks I use Lee Mac's Matrix transform functions (because I'm not that good at math):
Matrix Transformation Functions (http://www.lee-mac.com/matrixtransformationfunctions.html)

Your next objective is how to incorporate them into your code, and also decide on what kind of user input to draw the rotated/mirrored shape.

Title: Re: Still learning, but now trying to make an "L" shape.
Post by: BIGAL on June 20, 2022, 08:46:46 PM
It maybe that entering -ve value for lengths may invert the "L" using GRRR code but it will need a couple of values changed. Will have a think if Grrr does not do 1st.

(http://)
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: BIGAL on June 22, 2022, 01:38:23 AM
Found some time and had a play sorry Grrr got lost in pt names, accepts negative distances.

Code: [Select]
; Sample chart:
; Original code by Grrr
; Modified by Alanh to do 4 directions

;      pt2  pt3
;       |  |
;       |  |
;       |  |
;       |  | pt4
;       |  |___________ pt5
; pt1 |________________ pt6
;
;
(defun C:BAA ( / oldsnap pt1 LG1 LG2 THK1 l1 l2 l3 l4 pt1 pt2 pt3 pt4 pt5 pt6) ; always localise your variables



(defun l1 ( / )
(setq pt2 (mapcar '+ pt1 (list 0.0 LG1 0.0))) ; calculate the vertical leg by adding 'LG1' distance to 'pt's Y coordinate
(setq pt3 (mapcar '+ pt2 (list THK1 0.0 0.0))) ; calculate the inner top vertex by adding 'THK1' distance on 'ipt_legYaxis' s X coordinate
(setq pt4 (mapcar '+ pt1 (list THK1 THK1 0.0))) ; calculate the inner intersection by adding 'THK1' distance on 'pt's X coordinate and Y coordinate
(setq pt6 (mapcar '+ pt1 (list LG2 0.0 0.0))) ; calculate the horizontal leg by adding 'LG2' distance to 'pt's X coordinate
(setq pt5 (mapcar '+ pt6 (list 0.0 THK1 0.0))) ; calculate the inner bottom vertex by adding 'THK1' distance on 'ipt_legXaxis' s Y coordinate
(command "_.pline" pt1 pt2 pt3 pt4 pt5 pt6  "c")
)

(defun l2 ( / )
(setq pt2 (mapcar '+ pt1 (list 0.0 LG1 0.0))) ; calculate the vertical leg by adding 'LG1' distance to 'pt's Y coordinate
(setq pt3 (mapcar '+ pt2 (list THK1 0.0 0.0))) ; calculate the inner top vertex by adding 'THK1' distance on 'ipt_legYaxis' s X coordinate
(setq pt4 (mapcar '+ pt1 (list THK1 (- THK1) 0.0))) ; calculate the inner intersection by adding 'THK1' distance on 'pt's X coordinate and Y coordinate
(setq pt6 (mapcar '+ pt1 (list LG2 0.0 0.0))) ; calculate the horizontal leg by adding 'LG2' distance to 'pt's X coordinate
(setq pt5 (mapcar '+ pt6 (list 0.0 (- THK1) 0.0))) ; calculate the inner bottom vertex by adding 'THK1' distance on 'ipt_legXaxis' s Y coordinate
(command "_.pline" pt1 pt2 pt3 pt4 pt5 pt6  "c")
)

(defun l3 ( / )
(setq pt2 (mapcar '+ pt1 (list 0.0 LG1 0.0))) ; calculate the vertical leg by adding 'LG1' distance to 'pt's Y coordinate
(setq pt3 (mapcar '+ pt2 (list (- THK1) 0.0 0.0))) ; calculate the inner top vertex by adding 'THK1' distance on 'ipt_legYaxis' s X coordinate
(setq pt4 (mapcar '+ pt1 (list (- THK1) THK1 0.0))) ; calculate the inner intersection by adding 'THK1' distance on 'pt's X coordinate and Y coordinate
(setq pt6 (mapcar '+ pt1 (list LG2 0.0 0.0))) ; calculate the horizontal leg by adding 'LG2' distance to 'pt's X coordinate
(setq pt5 (mapcar '+ pt6 (list 0.0 THK1 0.0))) ; calculate the inner bottom vertex by adding 'THK1' distance on 'ipt_legXaxis' s Y coordinate
(command "_.pline" pt1 pt2 pt3 pt4 pt5 pt6  "c")
)

(defun l4 (  / )
(setq pt2 (mapcar '+ pt1 (list 0.0 LG1 0.0))) ; calculate the vertical leg by adding 'LG1' distance to 'pt's Y coordinate
(setq pt3 (mapcar '+ pt2 (list (- THK1) 0.0 0.0))) ; calculate the inner top vertex by adding 'THK1' distance on 'ipt_legYaxis' s X coordinate
(setq pt4 (mapcar '+ pt1 (list (- THK1) (- THK1) 0.0))) ; calculate the inner intersection by adding 'THK1' distance on 'pt's X coordinate and Y coordinate
(setq pt6 (mapcar '+ pt1 (list LG2 0.0 0.0))) ; calculate the horizontal leg by adding 'LG2' distance to 'pt's X coordinate
(setq pt5 (mapcar '+ pt6 (list 0.0 (- THK1) 0.0))) ; calculate the inner bottom vertex by adding 'THK1' distance on 'ipt_legXaxis' s Y coordinate
(command "_.pline" pt1 pt2 pt3 pt4 pt5 pt6  "c")
)

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))

(if (= (setq  pt1 (getpoint "Choose a starting point")) nil)
(alert "User interrupted an input")
(progn
  (setq ans (AH:getvalsm (list "Enter values " "Height  " 6 5 "100" "Length " 6 5 "150" "Thick " 6 5 "10" )))
  (setq LG1 (atof (nth 0 ans)) lG2 (atof (nth 1 ans)) THK1 (atof (nth 2 ans)))
  (setq oldsnap (getvar 'osmode))
  (setvar 'osmode 0)

  (cond
    ((and (> lg1 0.0)(> LG2 0.0))(L1))
    ((and (< lg1 0.0)(> LG2 0.0))(L2))
    ((and (> lg1 0.0)(< lg2 0.0))(L3))
    ((and (< lg1 0.0)(< lg2 0.0))(L4))
 ) ; cond

 (setvar 'osmode oldsnap)
 
   ); progn
 ); if
  (princ)
); defun C:BAA
(c:baa)
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: Curious Drafter on June 23, 2022, 03:08:46 PM
I think I will end up having to set the base point and leg orientation later, but what I meant when I was talking about changing the angle of the angle member I meant how would I go about making it either acute or obtuse instead of a 90 degree angle. I am currently working on the best way to incorporate the angle as well as a fillet on the "outside corner". If I can figure it out I will attach a dwg of what I hope the end product to look similar to.
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: BIGAL on June 23, 2022, 07:57:12 PM
Good task to learn lisp, look at what I posted, you would remove the mapcar functions and replace with a (setq pt2 (polar pt1 ang dist))

So you home work is to google help about the polar function. Start  here https://www.afralisp.net/autolisp/tutorials/calculating-polar-points.php#:~:text=The%20Polar%20function%20is%20defined%20in%20the%20AutoCAD,distance%20from%20a%20point.%20%28polar%20pt%20ang%20dist%29

(http://)



Title: Re: Still learning, but now trying to make an "L" shape.
Post by: Curious Drafter on July 06, 2022, 09:58:49 AM
Well, I am still working on it and I am trying to incorporate everything I have found so far, but this is what I have and it isn't loading properly. Any and all feedback is greatly appreciated.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:BAA ( / pt LG1 LG2 THK1 pty ptx ipty iptx ipt dtr) ; Localizes the variables.
  2.  
  3. (setq CL (getvar "clayer")); Gets the current layer.
  4.        
  5. (command "layer" "m" "0" "c" 4 "" "l" "continuous" "" nil); Creates and sets layer 0.
  6.  
  7. (setq lm (getvar "limcheck")); Gets the current limit setting.
  8.  
  9. (setvar "limcheck" 0); Sets limits to 0 or off.
  10.  
  11. (defun dtr (x); Defines the degrees to radians. Remember to change it back.
  12.  
  13. (* pi (/ x 180.0)); Angle divided by 180, then total is multiplied by Pi.
  14.  
  15. ); Closes Rad function.
  16.  
  17.  
  18.  
  19.         (if
  20.  
  21.                 (and
  22.  
  23.                         (setq pt (getpoint "Please choose a start?")); Bottom left starting point of leg.
  24.  
  25.                                 (setq LG1 (getreal "Please enter the 1st leg length?")); Vertical leg length.
  26.  
  27.                                         (setq LG2 (getreal "Please enter the 2nd leg length?")); horizontal leg length.
  28.  
  29.                                                 (setq THK1 (getreal "How thick is the member?")); Thickness of the angle member.
  30.  
  31.                                                         ); Closes and
  32.  
  33.                                                                 (progn ; code block that processes the inputs
  34.  
  35.                                                                         (setq pty (polar '+ pt (dtr 0.0 LG1 0.0))) ; Outside of vertical leg.
  36.  
  37.                                                                 (setq ptx (polar '+ pt (dtr LG2 0.0 0.0))) ; Outside of horizontal leg.
  38.  
  39.                                                         (setq ipty (polar '+ pty (dtr THK1 0.0 0.0))) ; Inside of vertical leg.
  40.  
  41.                                                 (setq iptx (polar '+ ptx (dtr 0.0 THK1 0.0))) ; Inside horizontal leg.
  42.  
  43.                                         (setq ipt (polar '+ pt (dtr THK1 THK1 0.0))) ; Inside intersection.
  44.  
  45.                                 (command "pline" pt ptx iptx ipt ipty pty "c") ; Polyline to make the angle.
  46.  
  47.                                                                 ); Closes progn
  48.  
  49.         ); Closed if
  50.  
  51. (command "layer" "s" cl ""); To set layer back to original.
  52.  
  53. (setvar "limcheck" lm); To reset limit to starting limit.
  54.  
  55. ); Closes defun
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: JohnK on July 06, 2022, 10:34:48 AM
The problem with your current code is that you are trying to pass too many arguments to the `dtr` function.


Little tips, there are simple standard conventions for some (they may seem minor but they will help you later).

1. Comment the function close with a " ;_ <function> " string.
2. You can line up your inline comments for easier reading (I tend to use column 57 if you are using a text editor and have control over that).
3. I prefix my comments with a dash so I can tell where a new comment (sentence/statement) starts.

Code - Auto/Visual Lisp: [Select]
  1. ;; -X-          This code does not work          -X-
  2. (defun C:BAA ( / pt LG1 LG2 THK1 pty ptx ipty iptx ipt dtr) ; -Localizes the variables.
  3.   (setq CL (getvar "clayer"))                           ; -Gets the current layer.
  4.   (command "layer" "m" "0" "c" 4 "" "l" "continuous" "" nil); -Creates and sets layer 0.
  5.   (setq lm (getvar "limcheck"))                         ; -Gets the current limit setting.
  6.   (setvar "limcheck" 0)                                 ; -Sets limits to 0 or off.
  7.  
  8.   (defun dtr (x)                                        ; -Defines the degrees to radians. Remember
  9.                                                         ;  to change it back.
  10.     (* pi (/ x 180.0))                                  ; -Angle divided by 180, then total
  11.                                                         ;  is multiplied by Pi.
  12.     );_ defun
  13.  
  14.  
  15.   (if
  16.     (and
  17.       (setq pt (getpoint "Please choose a start?"))     ; -Bottom left starting point of leg.
  18.       (setq LG1 (getreal "Please enter the 1st leg length?")); -Vertical leg length.
  19.       (setq LG2 (getreal "Please enter the 2nd leg length?")); -Horizontal leg length.
  20.       (setq THK1 (getreal "How thick is the member?"))  ; -Thickness of the angle member.
  21.       );_ and
  22.  
  23.     (progn                                              ; -code block that processes the inputs
  24.       (setq pty (polar '+ pt (dtr 0.0 LG1 0.0)))        ; -Outside of vertical leg.
  25.       (setq ptx (polar '+ pt (dtr LG2 0.0 0.0)))        ; -Outside of horizontal leg.
  26.       (setq ipty (polar '+ pty (dtr THK1 0.0 0.0)))     ; -Inside of vertical leg.
  27.       (setq iptx (polar '+ ptx (dtr 0.0 THK1 0.0)))     ; -Inside horizontal leg.
  28.       (setq ipt (polar '+ pt (dtr THK1 THK1 0.0)))      ; -Inside intersection.
  29.       (command "pline" pt ptx iptx ipt ipty pty "c")    ; -Polyline to make the angle.
  30.       );_ progn
  31.     );_ if
  32.  
  33.   (command "layer" "s" cl "")                           ; -To set layer back to original.
  34.   (setvar "limcheck" lm)                                ; -To reset limit to starting limit.
  35.   );_ defun
  36.  
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: BIGAL on July 06, 2022, 08:28:12 PM
Did you look at all the code in my post 6 it is full 4 direction "L's". Just make sure that Multi Getvals.lsp is in support path or Appload add to Startup Suite to it gets loaded on startup.
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: Curious Drafter on July 07, 2022, 09:04:24 AM
Is there a good way to make it work without the "Multi GETVALS" LISP?
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: dexus on July 07, 2022, 09:12:57 AM
Is there a good way to make it work without the "Multi GETVALS" LISP?
You can always combine the two files by putting al the code from multi getvals.lsp at the end of your lisp file.
That way you only have to load one file.

Edit, make sure to leave the header in, its good practice and a good way to see where you found the code so you can find the source a couple of years later if needed.
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: Curious Drafter on July 07, 2022, 09:35:31 AM
I think I will try that. I did want to see where I went wrong with incorporating this following link.

https://www.afralisp.net/autolisp/tutorials/calculating-polar-points.php#:~:text=The%20Polar%20function%20is%20defined%20in%20the%20AutoCAD,distance%20from%20a%20point.%20%28polar%20pt%20ang%20dist%29

I tried to use the "dtr" command and I am getting some pushback from the linked forum. I see where it is overused, but I am still learning programing language.

 https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/creating-custom-shape-with-formed-leg/m-p/11281305#M433384

Any and all help is greatly appreciated.
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: BIGAL on July 07, 2022, 09:42:02 PM
The (if (not loads the multi getvals if not loaded, you can do 2 solutions.

Save the file in a support file location. Make a directory if you dont have one for saving all the code you get from here.

Or use Appload add to Startup Suite Multi Getvals.lsp this is the way I have it set up.

The program is designed to not copy the code into every other program rather just call it geberally around 3 lines, you can also save previous selections as defaults when ran again. But only in current session. There is also Multi Radio Buttons, Multi Radio Buttons 2col and  Multi Toggles.

Lastly all my code uses this method now for initget style input nad value input. Been at it for like 40 years coding.

ALMOST FORGOT did you look at your post on other forums, new code includes angles.

Code: [Select]
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/creating-custom-shape-with-formed-leg/td-p/11281202

; angle design

; Sample chart:
; Original code by Grrr
; Modified by Alanh to do 4 directions July 2022

;      pt2  pt3
;       |  |
;       |  |
;       |  |
;       |  | pt4
;       |  |___________ pt5
; pt1 |________________ pt6
;
;
(defun C:BAA ( / oldsnap pt1 LG1 LG2 THK1 l1 l2 l3 l4 pt1 pt2 pt3 pt4 pt5 pt6) ; always localise your variables

(defun dtr (a)
(* pi (/ a 180.0))
)

(setq pi90 (/ Pi 2.0) pi270 (* 1.5 pi))

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))

(if (= (setq  pt1 (getpoint "Choose a starting point")) nil)
(alert "User interrupted an input")
(progn
  (setq ans (AH:getvalsm (list "Enter values " "Height  " 6 5 "100" "ANG1" 6 5 "0" "Length " 6 5 "150" "ANG2" 6 5 "90" "Thick " 6 5 "10" )))
  (setq LG1 (atof (nth 0 ans)) ang1 (dtr (atof (nth 1 ans))) lG2 (atof (nth 2 ans)) ang2 (dtr (atof (nth 3 ans))) THK1 (atof (nth 4 ans)))
  (setq oldsnap (getvar 'osmode) oldaunits (getvar 'aunits))
  (setvar 'osmode 0)
  (setvar 'aunits 3)

(setq pt2 (polar pt1 (+ pi90 ang1) lg1))
(setq pt3 (polar pt2 ang1 THK1))
(setq pt4 (polar pt3 (+ pi270 ang1) lg1))
(setq pt6 (polar pt1 (+ pi270 ang2) lg2))
(setq pt5 (polar pt6 ang2 thk1))
(setq pt7 (polar pt5  (- ang2 pi270) lg2))
(command "_.pline" pt4 pt3 pt2 pt1 pt6 pt5  pt7 "")
(setq pt6 (mapcar '* (mapcar '+ pt7 pt5) '(0.5 0.5)))
(setq pt7(mapcar '* (mapcar '+ pt3 pt4) '(0.5 0.5)))
(setvar 'filletrad 0.0)
(command "fillet"  pt6 pt7)

 (setvar 'osmode oldsnap)
 (setvar 'aunits oldaunits)
 
   ); progn
 ); if
  (princ)
); defun C:BAA
(c:baa)
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: Curious Drafter on July 08, 2022, 09:28:20 AM
I am very grateful for your code Al, and I can easily use it to do what I want it to do, but I am hoping to learn how to code what I want to do without outside lisp commands and why things work the way they do. I know that just about everything I would ever want to do and more is already done, but I really want to learn the ins and outs so I can do what you did on my own. I know I am a some what slow learner, but I am trying and want to make my skills better. I think if I go go line by line I can transfer hat I want to do to my own code, but it will take time. I think the main thing I am looking for now is a "what did I do wrong and what/how will it work in theory".

I definitely have a great place to start, but I hope to understand the language and how it works together. So thank you everyone for your help and patience while I learn.
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: BIGAL on July 08, 2022, 10:01:06 PM
Good to hear your having a go so many just ask for free, with projects like this I get a pen and paper draw the shape and label all the points. So work out next point then last join together line/pline.

I wrote some code then used copy and paste a line to command line, getpoint 1, work out next pt2 using polar, then I typed Line !pt1 !pt2 Enter and  a line was drawn note "!" so could check line was going in correct direction, just repeated this for all line segments. Re the inside point I could have used a Tan function to work out the angle for the polar but it was easier to let Acad fillet the 1st and last line.
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: Curious Drafter on July 12, 2022, 10:28:07 AM
I think I am getting closer to having a working code, but it's no longer drawings the lines. I am also getting a new error, but I'm a little stumped on what's not working correctly.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:BAA ( / pt1 LG1 LG2 THK1 L1 L2 L3 L4 pt2 pt3 pt4 pt5 pt6 pt7 piA piB ans dtr) ; -Localizes the variables.
  2.  
  3.  
  4.         (setq CL (getvar "clayer"))                                     ; -Gets the current layer.
  5.        
  6.         (command "layer" "m" "0" "c" 4 "" "l" "continuous" "" nil)      ; -Creates and sets layer 0.
  7.  
  8.         (setq lm (getvar "limcheck"))                                   ; -Gets the current limit setting.
  9.  
  10.         (setvar "limcheck" 0)                                           ; -Sets limits to 0 or off.
  11.  
  12.        
  13.         (defun dtr (d)                                                  ; -Defines the degrees to radians. Remember to change it back.
  14.  
  15.                 (* pi (/ d 180.0))                                      ; -Angle divided by 180, then total is multiplied by Pi.
  16.  
  17.                 ); -Closes Radian function.
  18.  
  19.         (setq piA (/ Pi 2.0) piB (* 1.5 pi))
  20.  
  21.  
  22.         (if
  23.  
  24.                                
  25.                 (and
  26.  
  27.                 (setq pt1 (getpoint "Please choose a start?"))          ; -Bottom left starting point of leg.
  28.  
  29.                 (setq LG1 (getreal "Please enter the 1st leg length?")) ; -Vertical leg length.
  30.  
  31.                 (setq LG2 (getreal "Please enter the 2nd leg length?")) ; -Horizontal leg length.
  32.  
  33.                 (setq THK1 (getreal "How thick is the member?"))        ; -Thickness of the angle member.
  34.  
  35.                 (setq ang1 (getreal "Set the angle please..."))         ; -Sets the angle.
  36.  
  37.                 ); Closes and
  38.  
  39.         (progn
  40.  
  41.                                        
  42.                 (setq pt2 (polar pt1 (+ piA ang1) LG1))
  43.  
  44.                 (setq pt3 (polar pt2 ang1 THK1))
  45.  
  46.                 (setq pt4 (polar pt3 (+ piB ang1) LG1))
  47.  
  48.                 (setq pt6 (polar pt1 (+ piB ang2) LG2))
  49.  
  50.                 (setq pt5 (polar pt6 ang2 thk1))
  51.  
  52.                 (setq pt7 (polar pt5  (- ang2 piB) LG2))
  53.  
  54.                 (setq pt6 (mapcar '* (mapcar '+ pt7 pt5) '(0.5 0.5)))
  55.  
  56.                 (setq pt7(mapcar '* (mapcar '+ pt3 pt4) '(0.5 0.5)))
  57.  
  58.                 (command "pline" pt4 pt3 pt2 pt1 pt6 pt5  pt7 "c")      ; -Polyline to make the angle.
  59.  
  60.                 (setvar 'filletrad (* THK1 0.5))
  61.  
  62.         (command "fillet"  pt6 pt7)
  63.  
  64.  
  65.          ); -Closes progn
  66.  
  67.          ); -Closes if
  68.  
  69.         (princ)
  70.  
  71.         (command "layer" "s" cl "")                                     ; -To set layer back to original.
  72.  
  73.         (setvar "limcheck" lm)                                          ; -To reset limit to starting limit.
  74.  
  75.  
  76. ); -Closes defun
  77.  

This is the code and the error I get back "; error: bad argument type: numerp: nil"

Any and all feedback as greatly appreciated.
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: ScottMC on July 12, 2022, 05:34:27 PM
No 'ang2'..  turn the fillet off too. Now it's getting the order of coords to work for the pline.
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: BIGAL on July 12, 2022, 09:24:38 PM
Curious drafter you only need to check say you have picked a point or maybe pressed esc.

Your welcome to use my multi getvals.lsp it is a library program can be used in any program just change the list to suit. Just make sure its saved in a support path or autoload on startup. You can cahnge the default values you can save the default values between goes can explain if required.

Code: [Select]
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))

(if (= (setq  pt1 (getpoint "Choose a starting point")) nil)
(alert "User interrupted an input")
(progn
  (setq ans (AH:getvalsm (list "Enter values " "Height  " 6 5 "100" "Length " 6 5 "150"  "Thick " 6 5 "10" "ANGLE" 6 5 "90")))
  (setq LG1 (atof (nth 0 ans))  LG2 (atof (nth 2 ans))  THK1 (atof (nth 4 ans)) ang1 (* pi (/ (atof (nth 3 ans)) 180.0)) )


Title: Re: Still learning, but now trying to make an "L" shape.
Post by: Curious Drafter on August 02, 2022, 11:51:37 AM
I decided to try and take it back a couple steps and make sure I get my head wrapped around everything again so I can see how and why things are or are not working for me. I altered my lisp back to the following:
Code - Auto/Visual Lisp: [Select]
  1. (defun C:BAA ( / pt1 LG1 LG2 THK1 pt2 pt3 pt4 pt5 pt6) ; -Localizes the variables.
  2.  
  3.  
  4.         (setq CL (getvar "clayer"))                                     ; -Gets the current layer.
  5.        
  6.         (command "layer" "m" "0" "c" 4 "" "l" "continuous" "" nil)      ; -Creates and sets layer 0.
  7.  
  8.         (setq lm (getvar "limcheck"))                                   ; -Gets the current limit setting.
  9.  
  10.         (setvar "limcheck" 0)                                           ; -Sets limits to 0 or off.
  11.  
  12.  
  13.         (if
  14.  
  15.                                
  16.                 (and
  17.  
  18.                 (setq pt1 (getpoint "Please choose a start?"))          ; -Bottom left starting point of leg.
  19.  
  20.                 (setq LG1 (getdist "Please enter the 1st leg length?")) ; -Vertical leg length.
  21.  
  22.                 (setq LG2 (getdist "Please enter the 2nd leg length?")) ; -Horizontal leg length.
  23.  
  24.                 (setq THK1 (getdist "How thick is the member?"))        ; -Thickness of the angle member.
  25.  
  26.                 (setq ang1 (getangle "Set the angle please..."))        ; -Sets the angle.
  27.  
  28.                 ); Closes and
  29.  
  30.         (progn                                                          ; -Code block that processes the inputs
  31.  
  32.                                        
  33.                 (setq pt2 (polar pt1 1.57 LG1))                         ; changed for testing
  34.  
  35.                 (setq pt3 (polar pt2 0 THK1))                           ; changed for testing
  36.  
  37.                 (setq pt4 (polar pt3 4.71 (- LG1 THK1) ))               ; changed for testing
  38.  
  39.                 (setq pt5 (polar pt4 6.28 (- LG2 THK1) ))               ; changed for testing
  40.  
  41.                 (setq pt6 (polar pt5 4.71 thk1))                        ; changed for testing
  42.  
  43.                 (command "pline" pt1 pt2 pt3 pt4 pt5 pt6 "c")           ; -Polyline to make the angle.
  44.  
  45.                 (setvar 'filletrad (* THK1 0.5))                        ; -Sets the fillet radius.
  46.  
  47.         ; -For later use -command "fillet" at outside point typical-    ; -Creates radius at external corner
  48.  
  49.  
  50.          ); -Closes progn
  51.  
  52.          ); -Closes if
  53.  
  54.         (princ)
  55.  
  56.         (command "layer" "s" cl "")                                     ; -To set layer back to original.
  57.  
  58.         (setvar "limcheck" lm)                                          ; -To reset limit to starting limit.
  59.  
  60.  
  61. ); -Closes defun

Still working out the kinks, but attached is the slightly cleaned up end goal for now. I am hoping to eventually have my lisp so all that is needed is to enter the known and needed values and have it generate a fully dimensioned shape like in the dwg. I finally have it making an "L" again and will change it so that it will use "dtr" instead of using radians as it does now.

I know I can use and I am grateful for the permission to use the multi getvals.lsp, but I am still hoping to create the routine from the ground up. Hopefully it helps me to better understand what I am doing instead of just poking in the dark.

For now I am going to read what I can find and have been sent again now that I have a clearer picture of what does and doesn't work so far. Any tips are still greatly appreciated and thank you for your patience when I am surely causing frustration.
Title: Re: Still learning, but now trying to make an "L" shape.
Post by: BIGAL on August 02, 2022, 11:26:25 PM
As you say use the getreal etc multiple times then when ready add the multi getvals.

Have a look at this re dims.

Code: [Select]
; simple draw a box and dimension it
; By Alan H March 2019


(defun ah:box ( / pt1 pt2 pt3 ahl ahh ahoff )
(setq oldsnap (getvar 'osmode))
(setq oldang (getvar 'angdir))
(setq pt1 (getpoint "\nPick lower left"))
(setvar 'osmode 0)
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Simple rectang" "Enter length" 8 7 "1" "Enter height " 8 7 "2")))
(setq ahL (atof (nth 0 ans)))
(setq ahH (atof (nth 1 ans)))
(setq pt2 (polar pt1 0.0 ahl))
(setq pt3 (polar pt2 (/ pi 2.0) ahH))
(command "rectang" pt1 pt3)
(setq ahoff (* 2.0 (* (getvar 'dimasz)(getvar 'dimscale)))) ; change offset as required
(setq pt4 (polar pt2  (* pi 1.5) ahoff))
(command "dim" "hor" pt1 pt2 pt4 "" "exit")
(setq pt4 (polar pt3 0.0 ahoff))
(command "dim" "Ver" pt2 pt3 pt4 "" "exit")
(setvar 'osmode oldsnap)
)
(ah:box)

Title: Re: Still learning, but now trying to make an "L" shape.
Post by: GDF on August 03, 2022, 02:53:25 PM
Look at AutoCADís dline.lsp that comes with AutoCAD.