bpdav1 Posted August 9, 2012 Posted August 9, 2012 Hi, I am learning Autolisp and am trying to create a simple program but have run into the following problem. I am trying to draw a line of user defined length and therefore want to create a variable that allows the user to input the length of the line. When I try to assign "p1" with a value, with no quote mark it says "error: bad function:" If I put the quote mark in (as shown below) it makes the first entry literally the string "Length", not the value of the variable Length. I want the first entry of p1 to be assigned with the value the user inputs, so if you input "1000" into Length, p1 will display as "1000,0", so I can then use it as a coordinate for the Line command. (defun C:Line (/ Length p1) (setq Length (getint "Enter Length of Line: ")) (setq p1 (list '(Length 0))) (princ p1) (princ) ) Quote
MSasu Posted August 9, 2012 Posted August 9, 2012 This is from the use of quote instead of LIST function for a list that should be evaluated since contains a variable. (defun C:[color=red]LineX[/color] ( / [color=red]theLength[/color] p1) (setq [color=red]theLength[/color] (getint "Enter Length of Line: ")) (setq p1 (list ([color=red]list[/color] [color=red]theLength[/color] 0))) (princ p1) (princ) ) Also, please pay special attention when assign names to your variables/functions and avoid using reserved names! In your code you will redefine the built-in LINE command and also replace the LENGTH function. This may generate serious errors. I have renamed those in above example. However to get a string as you said, you need to use the STRCAT function; take care that accepts only strings as arguments, so user's input should be converted. (defun C:LineX ( / theLength p1 ) (setq theLength (getint "Enter Length of Line: ")) (setq p1 [color=red](strcat (itoa theLength) ",0")[/color]) (princ p1) (princ) ) Quote
MSasu Posted August 9, 2012 Posted August 9, 2012 I have rewritten your routine as example: (defun C:LineX( / theLength pointStart pointEnd ) (if (and (setq pointStart (getpoint "\nStarting point: ")) (setq theLength (getint "\nEnter Length of Line: "))) (progn (setq pointEnd (polar pointStart 0.0 theLength)) (command "_.LINE" "_non" pointStart "_non" pointEnd "") ) ) (princ) ) Should check the POLAR function in help if you want to adjust the angle of the line. Quote
Recommended Posts
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.