TheNewGuy Posted May 27, 2009 Author Posted May 27, 2009 Thanks again, I have been reading tutorials. I have read jeffery sanders completely. I have read two others also. I am starting to understand some of it, but it is not working as simply as they make it sound. For example I can write (command "line" "0,0" "0.5" "4,.5" "4,0" "0,0" "") at the command prompt and it works, I tried it. but I can't write (command "pline" "0,0,0" "0,sd2,0" "sd2,ol1,0" "ol1,0,0" "0,0,0" "") that does not work for some reason. So I am trying. I need the manual, I am going to down load the manual from some where...Thanks again for all your help. Quote
Lee Mac Posted May 27, 2009 Posted May 27, 2009 Thanks again, I have been reading tutorials. I have read jeffery sanders completely. I have read two others also. I am starting to understand some of it, but it is not working as simply as they make it sound. For example I can write at the command prompt and it works, I tried it. but I can't write that does not work for some reason. So I am trying. I need the manual, I am going to down load the manual from some where...Thanks again for all your help. it will not work as the variables inside the quote marks are being interpretted as strings, and their values are not being evaluated. Quote
TheNewGuy Posted May 28, 2009 Author Posted May 28, 2009 OK My brain is bubbling! And I still don't feel like I could write anything. I need some how to start with something simple. Lee Mac would you be willing to help me write a simple program that I can build from? The example I posted above is supposed to ask for input then draw a square. That's it! and I can't get it to work. I have no one I can talk to in person and these books I am reading try to tell you everything all at once! I just need to start somewhere..... (I am frustrated,can you tell?) Quote
TheNewGuy Posted May 28, 2009 Author Posted May 28, 2009 Thank you! I agree with you that it is important to develop good programing habits from the beginning, but I am trying to take in to much at a time. I need to start small and master (at least understand) parts before I move on to the next. So this is what I got so far... (defun c:gage (/ sd1 gd1 gr1 ol1 ul1 tl1 sh1 sd2 p1 p2 p3 p4 p5 p6 p7) (setq sd1 (getdist "\nSHOULDER DIAMETER: ") gd1 (getdist "\nGAGE DIAMETER: ") gr1 (getdist "\nGAGE RADIUS: ") ol1 (getdist "\nOver all length: ") ul1 (getdist "\nuniform length: ") tl1 (getdist "\nThread length: ") shl1 (getdist "\nshoulder length: ") ) ;Calculations (setq sd2 (/ sd1 2.0)) ) ;Program (command "pline" (list 0 0 0) (list 0 sd2 0) (list sd2 ol1 0) (list ol1 0 0) (list 0 0 0) (princ) ) ) Look familiar? It should because it is exactly the same thing I had yesterday!As I said all I am trying to do now is have it draw a square based off of the inputted values. Also could you make any changes in that red font you used before? And maybe a short comment about what it does and why I need it.... You know I appreciate your help. And soon I will be helping you by writing some of the requested programs so you don't have to! Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 Well, this is a VERY simplified version to create a box: (defun c:gage (/ oldos oldcmd len pt) (setq oldos (getvar "OSMODE") oldcmd (getvar "CMDECHO")) ; Store old variables so we can reset them later (if (and ; If BOTH the following things... (setq len (getdist "\nSpecify Side Length: ")) ; Get a Length (setq pt (getpoint "\nSpecify Insertion Point: ")) ; Get a Point ) ; End And (progn ; Wrap the following Statements (setvar "CMDECHO" 0) ; Turn off Command Echoing (setvar "OSMODE" 0) ; Turn off OSnaps (command "_pline" ; Invoke Pline command pt ; Start point ;;; + ;;; pt (setq pt (polar pt (/ pi 2) len)) ; Going up ;;; + ;;; | ;;; + ;;; pt (setq pt (polar pt 0 len)) ; Going Right ;;; +---+ ;;; | ;;; + ;;; pt (polar pt (/ (* 3 pi) 2) len) ; Going Down ;;; +---+ ;;; | | ;;; + + ;;; pt "_C" ; Close it. ) ; End Command ) ; End progn (princ "\n<!> Incorrect Specification <!>") ; Else something was not inputted. ) ; End if (setvar "OSMODE" oldos) ; reset os (setvar "CMDECHO" oldcmd) ; reset cmdecho (princ) ; exit cleanly ) ; end command Quote
TheNewGuy Posted May 28, 2009 Author Posted May 28, 2009 Wow that is so different from what I am used to! The "If" command is still evaluating all the way to the end. that is weird. I can hardly picture how that works in my head. But you didn't use any list's, and that is one place I was having trouble with! Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 The IF command just checks everything in the AND statement - then if everything in the AND returns T, it will run through everything wrapped in the PROGN statement OK, I couldn't resist, just a little fun with GRREAD - don't try to understand this just yet, just a bit of fun for you (defun c:sqr (/ oldos pt dis p1 p2 p3) (setq oldos (getvar "OSMODE")) (if (setq pt (getpoint "\nSelect Point for Square: ")) (progn (setvar "OSMODE" 0) (while (and (setq gr (grread t 5 0)) (= 5 (car gr))) (redraw) (setq dis (distance pt (cadr gr)) p1 (polar pt (/ pi 2) dis) p2 (polar pt 0 dis) p3 (polar p1 0 dis)) (grvecs (list -6 pt p1 pt p2 p1 p3 p2 p3))) (if (eq 3 (car gr)) (command "_.pline" pt p1 p3 p2 "_C")))) (setvar "OSMODE" oldos) (redraw) (princ)) Quote
TheNewGuy Posted May 28, 2009 Author Posted May 28, 2009 So in you first example how does (setq pt (polar pt (/ pi 2) len)) ; Going up make it go up? I would think all it does is set the value of pt. Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 Yes, it sets the value of pt to: a new point that is relative to the old value of pt, at an angle of pi/2 (upwards), and a displacement of the value of "len". Have you used polar coordinates before? Another to mess around with (defun c:sqr (/ oldos pt ang dis p1 p2 p3) (setq oldos (getvar "OSMODE")) (if (setq pt (getpoint "\nSelect Point for Square: ")) (progn (setvar "OSMODE" 0) (while (and (setq gr (grread t 5 0)) (= 5 (car gr))) (redraw) (setq ang (angle pt (cadr gr)) dis (* (distance pt (cadr gr)) (cos (/ pi 4))) p1 (polar pt (+ ang (/ pi 4)) dis) p2 (polar pt (- ang (/ pi 4)) dis) p3 (polar p1 (- ang (/ pi 4)) dis)) (grvecs (list -6 pt p1 pt p2 p1 p3 p2 p3))) (if (eq 3 (car gr)) (command "_.pline" pt p1 p3 p2 "_C")))) (setvar "OSMODE" oldos) (redraw) (princ)) Quote
TheNewGuy Posted May 28, 2009 Author Posted May 28, 2009 Have you used polar coordinates before? Yes I like to use polar coordinates in my drawing. But I am still not sure how that line of code made it GO to that point. Is autocad going to make what ever is entered next the next point, if it is a valid point? Quote
TheNewGuy Posted May 28, 2009 Author Posted May 28, 2009 Also I am beginning to notice one of my problems. How do I tell autocad to go to a point such as(0.5,0.5,0.0) do I need to do something similar to using the # sign like I would from the command line when I am trying to move an object? Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 The "PLINE" command will accept lists when making the points of the polyline. The value of pt will be a list of 3 elements, the x,y and z components. Does this clarify things better? Quote
TheNewGuy Posted May 28, 2009 Author Posted May 28, 2009 Sorta, thats what you said yesterday. So how do I create a list. For example; (setq sd1 (getdist "\nSHOULDER DIAMETER: ") How do I turn that into a list of (0,sd1,0)? Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 Well, the easiest way is: (list 0 sd1 0) But I would be inclined to use polar coordinates, as they are easier to manipulate and you can specify the points relative to a user selected point. Quote
TheNewGuy Posted May 28, 2009 Author Posted May 28, 2009 As I said this is just the beginning..... Now wait a minute how would I call that list back up? it is assigned to no variable. Quote
Lee Mac Posted May 28, 2009 Posted May 28, 2009 Well, you could assign it to a variable then: (setq var (list 0 sd1 0)) or just use it in straight in the pline command: (command "_.pline" (list 0 sd1 0) .... Quote
TheNewGuy Posted May 29, 2009 Author Posted May 29, 2009 Oh, Ok I will try that. I am currently trying to teach my self VB for Excel and Visual LISP for autocad so my brain was sizzling yesterday! Thanks for your continued help.(Don't suppose you are a VB master also?) Quote
Lee Mac Posted May 29, 2009 Posted May 29, 2009 Oh, Ok I will try that. I am currently trying to teach my self VB for Excel and Visual LISP for autocad so my brain was sizzling yesterday! Thanks for your continued help.(Don't suppose you are a VB master also?) 'fraid not, I've never done any VB at all - good luck with it all though Quote
TheNewGuy Posted May 29, 2009 Author Posted May 29, 2009 Yea I could use some luck! I am going to make a trip to the library this weekend and maybe a used book store or two are there any books on Lisp that you would recommend? 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.