Creating custom shape with formed leg

Creating custom shape with formed leg

JCKRU47
Advocate Advocate
535 Views
8 Replies
Message 1 of 9

Creating custom shape with formed leg

JCKRU47
Advocate
Advocate

I am working on a LISP routine to create a formed angle. I have been slowly adding to my routine to go from a simple box to a 90 degree angle shape. I am hoping to have one of the legs be able to be set to a different angle than 90 degrees based on user input, similar to how the leg lengths are set. I know this code has a long way to go, but any and all help and input would be greatly appreciated.

 

The following is what I have so far:  

 

(defun C:BAA ( / pt LG1 LG2 THK1 pty ptx ipty iptx ipt dtr ang1) 	; -Localizes the variables.

	(setq CL (getvar "clayer"))					; -Gets the current layer.
	
	(command "layer" "m" "0" "c" 4 "" "l" "continuous" "" nil)	; -Creates and sets layer 0.

	(setq lm (getvar "limcheck"))					; -Gets the current limit setting.

	(setvar "limcheck" 0)						; -Sets limits to 0 or off.

	
	(defun dtr (d)							; -Defines the degrees to radians. Remember to change it back.

		(* pi (/ d 180.0))					; -Angle divided by 180, then total is multiplied by Pi.

		); -Closes Rad function.


	(defun rtd (r)							; -Defines the radians to degrees.

		(* 180.0 (/ r pi))

		); -Closes Deg function.


	(if 

		(and 

		(setq pt (getpoint "Please choose a start?"))		; -Bottom left starting point of leg.

		(setq LG1 (getreal "Please enter the 1st leg length?"))	; -Vertical leg length.

		(setq LG2 (getreal "Please enter the 2nd leg length?"))	; -Horizontal leg length.

		(setq THK1 (getreal "How thick is the member?"))	; -Thickness of the angle member.

		(setq ang1 (getreal "Set the angle please..."))		; -Sets the angle.

		); Closes and
	

	(progn 								; -code block that processes the inputs

		(setq pty (polar '+ pt ( (dtr 0) 0.0 LG1 0.0))) 	; -Outside of vertical leg.

		(setq ptx (polar '+ pt ( (dtr ang1) LG2 0.0 0.0))) 	; -Outside of horizontal leg.

		(setq ipty (polar '+ pty ( (dtr 0) THK1 0.0 0.0))) 	; -Inside of vertical leg.

		(setq iptx (polar '+ ptx ( (dtr ang1) 0.0 THK1 0.0))) 	; -Inside horizontal leg.

		(setq ipt (polar '+ pt ( THK1 THK1 0.0)))		 ; -Inside intersection.

		(command "pline" pt ptx iptx ipt ipty pty "c") 		; -Polyline to make the angle.

	); -Closes progn

	); -Closed if


	(command "rtd")							; -To convert back to degrees.

	(command "layer" "s" cl "")					; -To set layer back to original.

	(setvar "limcheck" lm)						; -To reset limit to starting limit.

); -Closes defun
0 Likes
536 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

The first thing I notice is that your (polar) functions are wacky.  Study the entry in the AutoLisp reference for it, to get the required arguments to it correct and in the correct order -- point, angle, distance.  Maybe in most cases you mean (mapcar) instead, to add coordinate values to a base point, but then I think you're missing list function names in what follows the point variable you want to add to, and most appear to have 4 coordinates, which won't be allowed.

 

Also, you don't need to convert 0 between degrees and radians.  (dtr 0) can be simply 0.

 

And (command "rtd") is invalid -- a (command) function can only accept native AutoCAD command names.  But there's no need to "reset" anything after using (dtr) functions, anyway.

Kent Cooper, AIA
0 Likes
Message 3 of 9

JCKRU47
Advocate
Advocate

It's in a slightly different format, but this is what the code was to make a 90 degree angle. 

(defun C:BAA ( / pt LG1 LG2 THK1 pty ptx ipty iptx ipt ) ; Localizes the variables.

(setq CL (getvar "clayer")); Gets the current layer.
	
(command "layer" "m" "0" "c" 4 "" "l" "continuous" "" nil); Creates and sets layer 0.

(setq lm (getvar "limcheck")); Gets the current limit setting.

(setvar "limcheck" 0); Sets limits to 0 or off.

	(if 

		(and 

			(setq pt (getpoint "Please choose a start?")); Bottom left starting point of leg.

				(setq LG1 (getreal "Please enter the 1st leg length?")); Vertical leg length.

					(setq LG2 (getreal "Please enter the 2nd leg length?")); horizontal leg length.

						(setq THK1 (getreal "How thick is the member?")); Thickness of the angle member.

							); Closes and

								(progn ; code block that processes the inputs

									(setq pty (mapcar '+ pt (list 0.0 LG1 0.0))) ; Outside of vertical leg.

								(setq ptx (mapcar '+ pt (list LG2 0.0 0.0))) ; Outside of horizontal leg.

							(setq ipty (mapcar '+ pty (list THK1 0.0 0.0))) ; Inside of vertical leg.

						(setq iptx (mapcar '+ ptx (list 0.0 THK1 0.0))) ; Inside horizontal leg.

					(setq ipt (mapcar '+ pt (list THK1 THK1 0.0))) ; Inside intersection.

				(command "pline" pt ptx iptx ipt ipty pty "c") ; Polyline to make the angle.

								); Closes progn

	); Closed if

(command "layer" "s" cl ""); To set layer back to original.

(setvar "limcheck" lm); To reset limit to starting limit.

); Closes defun

 

This is an ever evolving 1st lisp I am trying to make.

 

I will start to update everything based on your feedback and information in the link. Hopefully I can get everything squared away in the morning. 

0 Likes
Message 4 of 9

Sea-Haven
Mentor
Mentor

Have a look at post #6 here may be useful, yes the 2 angles can be added to the input. 

 

http://www.theswamp.org/index.php?topic=57649.0

is that you ?

 

 

0 Likes
Message 5 of 9

Sea-Haven
Mentor
Mentor

Had another go a little confusing but I think you can work it out try 1 angle at a time. 

 

 

 

; 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 pt7 pi90 pi270 ) ; 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)

 

 

Dont forget multi getvals. Limited testing I think some combo's will bowtie.

 

SeaHaven_0-1657164404206.png

 

 

0 Likes
Message 6 of 9

JCKRU47
Advocate
Advocate

Would it be possible to replace the "filletrad" with (setvar 'filletrad (* THK1 0.5) and have it work? Also, there seems to be an extra parenthesis I am having a hard time locating.

0 Likes
Message 7 of 9

devitg
Advisor
Advisor

@JCKRU47 As I can see there is no extra or miss parenthesis at the original . 

 

But there is a miss one at your change  

 (setvar 'filletrad (* THK1 0.5) )

 

 (setvar 'filletrad (* THK1 0.5) )

 

 

 

0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor

Thanks would have gone looking for extra ).

 

JCKRU47 you can add a fllet rad to the code thk /2 = ?  is pretty easy to work out just look at this.

 

 

 

(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" "Fillet rad " 6 5 "5")))

(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)) rad (atof (nth 5 ans)))

(setvar 'filletrad rad)

 

 

 

0 Likes
Message 9 of 9

JCKRU47
Advocate
Advocate

I am very grateful for the pre made codes, 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 all 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 line by line I can transfer what 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.

0 Likes