chelsea1307 Posted January 16, 2009 Posted January 16, 2009 Im new to writing my own lisps. Ive been hesitent to try because I cant think of anything that I do enough to want a lisp for that my company doesnt already have a lisp for. I found someone on here wanting to select a line, divide the distance by either 12 or 24 whichever they enter and then insert that number. I dont want someone to write the whole lisp for me but a push in the right direction. Ive got to the point of selecting 12 or 24 but I dont know if that should be first or if selecting the line should be first, and how to put " if 12 selected divide distance of line by 12" and "if 24 selected divide distance by 24" any help would be great Quote
Lee Mac Posted January 16, 2009 Posted January 16, 2009 Ahh Chelsea, I was also looking to make that LISP, when I found out how to calculated the stud number Its up to you really in which order you put the prompts - I would normally put the line selection first and include it within an IF statement/WHILE statement to account for the possibility that the user does not select anything. As you probably know, with the 12/24 selection, you could use an initget with either a getkword - or, if there is some formula to working the number of bolts, just use either getreal or getint. Then, if you are using a keyworded prompt - use a cond statement to determine the outcomes of various possibilities... Quote
chelsea1307 Posted January 16, 2009 Author Posted January 16, 2009 So this is what I have so far, no laughing this is the first time ive tried to write my own. to me this means if you type stud in the command line its gonna ask you for two points to measure dist then ask for 12 or 24 and then it divides dist1 by size1(12 or 24) and thats where im stuck (defun C:stud () (setq dist1 (distance pnt1 pnt2)) (setq size1 (getint "\12 or 24 :") (setq size2 (/ dist1 size1) ( Quote
chelsea1307 Posted January 16, 2009 Author Posted January 16, 2009 Ive tried to run it to see if everything works and it wont let me. Ive loaded it like ive done a million times with other lisps but it says stud is an unknown command, i was hoping i would at least have gotten that part right Quote
Lee Mac Posted January 16, 2009 Posted January 16, 2009 So this is what I have so far, no laughing this is the first time ive tried to write my own. to me this means if you type stud in the command line its gonna ask you for two points to measure dist then ask for 12 or 24 and thats where im stuck, also please let me know if im wrong in what i think ive written highly possible. (defun C:stud() (setq dist1 (distance pnt1 pnt2)) (getint "\12" or 24":") (if ( OK, OK, I'll try to explain it best I can - but I think you may be better with a proper tutorial If you want to prompt the user for a distance, you could use the "getdist" command, something like this: (setq pt1 (getpoint "\nSelect First End of Beam: ")) (setq dist (getdist pt1 "\nSelect Other End of Beam: ")) You will need to use the "getxxx" when you want to prompt the user for something. As for the 12" or 24"... To make it keyworded: (initget 7 "12 24") (setq ans (getkword "\n12\" or 24\"? ")) The "Initget" sets the input restrictions and is bit-coded. 7 = 1 + 2 + 4 which means, "no pressing enter", "no zeros", "no negatives". When setting text in the (getkword) statement, I would start with "\n" which means "newline" and then, if you are going to use " for inches, you must prefix it with \ as " means something else otherwise. As for what to do with the returns: (cond ((= ans "12") (/ dist 12) ) ; end condition 1 ((= ans "24") (/ dist 24) ) ; end condition 2 ) ; end cond As a side note, any text after a ";" is not read by the program, so can be comments. Remember that the getkword returns strings and so you won't be able to just divide the length by these. Ok, that'll do for now, my fingers are getting tired and there is so much I want to explain. I would suggest looking through tutorials - search Jefferey Sanders AutoLISP in Google - that is where I learnt much of what I know. Hope this helps without spelling it out too much. Cheers Lee Quote
Lee Mac Posted January 16, 2009 Posted January 16, 2009 So this is what I have so far, no laughing this is the first time ive tried to write my own. to me this means if you type stud in the command line its gonna ask you for two points to measure dist then ask for 12 or 24 and then it divides dist1 by size1(12 or 24) and thats where im stuck(defun C:stud () (setq dist1 (distance pnt1 pnt2)) (setq size1 (getint "\12 or 24 :") (setq size2 (/ dist1 size1) ( The reason your code will not even load is because you haven't finished the parenthesis: Yours: (defun C:stud () (setq dist1 (distance pnt1 pnt2)) (setq size1 (getint "\12 or 24 :") (setq size2 (/ dist1 size1) ( Correct: (defun C:stud () (setq dist1 (distance [b][color=Red]pnt1 pnt2[/color][/b])) (setq size1 (getint "\[b][color=Red]n[/color][/b]12 or 24 :")[b][color=Red])[/color][/b] (setq size2 (/ dist1 size1)[b][color=Red])[/color][/b] [b][color=Red])[/color][/b] Obviously the above still won't run properly, as the program doens't know what pnt1 and pnt2 are and there are other errors, but see my last post. Quote
chelsea1307 Posted January 16, 2009 Author Posted January 16, 2009 thanks for that ill see if i can get mine working now, I found one tutorial on afralisp im working through but Ill check yours out too. Quote
Lee Mac Posted January 16, 2009 Posted January 16, 2009 What are you using to write these? Notepad? Because, I used to use Notepad, but now I have seen the light and use Visual Lisp Editor (provided with ACAD) - just type VLIDE at the comman prompt. Use the help file in that - its actually very helpful. Quote
chelsea1307 Posted January 16, 2009 Author Posted January 16, 2009 is this better? still wont run but i think i have all the needed parentheses (Defun C:stud () (setq pt1 (getpoint "\nSelect First End of beam: ")) (setqdist (getdist pt1 "nselect other end of beam: ")) (setq ans (getkword "\n12 or 24? ")) (cond ((= ans "12") (/ dist 12) ) ((=ans "24") (/ dist 24) ) ) Quote
Lee Mac Posted January 16, 2009 Posted January 16, 2009 You need one more parenthesis: (Defun C:stud () (setq pt1 (getpoint "\nSelect First End of beam: ")) (setq dist (getdist pt1 "[b][color=Red]\[/color][/b]nselect other end of beam: ")) [b][color=Red] (initget "12 24")[/color][/b] (setq ans (getkword "\n12 or 24? ")) (cond ((= ans "12") (/ dist 12) ) ((=ans "24") (/ dist 24) ) ) [b][color=Red])[/color][/b] Quote
Lee Mac Posted January 16, 2009 Posted January 16, 2009 This routine will echo the last return, which will be one of the cond statements. To suppress the echo you will need a "princ" at the end: (defun c:stud ([b][color=Red]/ pt1 dist ans[/color][/b]) (setq pt1 (getpoint "\nSelect First End of beam: ")) (setq dist (getdist pt1 "\nselect other end of beam: ")) (initget "12 24") (setq ans (getkword "\n12[b][color=Red]\"[/color][/b] or 24[b][color=Red]\"[/color][/b]? ")) (cond ((= ans "12") (/ dist 12) ) ((=ans "24") (/ dist 24) ) ) [b][color=Red](princ)[/color][/b] ) And localise variables for good measure Quote
chelsea1307 Posted January 16, 2009 Author Posted January 16, 2009 yes i have been using notepad, as was suggeested in my tutorial but I will try visual lisp editor. I just tried the lisp and it finally works, now im off to figure out how to insert the answer. Thanks so much for the help. and I just noticed you posted again and I will update mine. One other question, is there a purpose to indenting or does that just make it easier to read? Quote
chelsea1307 Posted January 16, 2009 Author Posted January 16, 2009 I just tried the vlide... way cool!!! it tells you when you have unclosed parentheses and gives you a green box when you good to continue.. thanks for letting me know about that! Quote
Lee Mac Posted January 16, 2009 Posted January 16, 2009 You are typing into the console... If you want to create LISP files, click on the icon for "new file". Also, about the indentation - yes, its just for ease of reading. Quote
Lee Mac Posted January 16, 2009 Posted January 16, 2009 If you are having errors when loading the LISPs, you can normally tell what is wrong by the type of error: i.e. "Malformed list on input" means that you have left off a right bracket ")" "Extra Right Paren..." obviously means an extra right bracket ")" "bad argument - " means you have tried supplying a function with the wrong type of data i.e. diving a string by a number.. and there are loads more... Take a read of this: http://www.midpointcad.com/au/docs/lakose_The_Visual_LISP_Developers_Bible.pdf Here are some helpful pics: 1) how to format 2) how to create a new file 3) how to load a LISP 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.