CALCAD Posted April 8, 2009 Posted April 8, 2009 For the curious, this lisp displays the delta X, Y, Z and 3D distance between picked points to up to 15 places. According to the help file, the PRECISION argument of the RTOS function corresponds to the LUPREC system variable. But LUPREC is limited to 8 place precision while the PRECISION of RTOS may be set at anything up to 15. This lisp was developed with and tested on Intellicad. I don't have Autocad to try it on. I think it will work. I would like to know if it doesn't work or doesn't display all 15 places. You could rewrite this to display the results in an Alert box if you prefer that to the command history. (defun c:pdx (/ *ERROR* p1 p2 xp1 yp1 zp1 xp2 yp2 zp2 dx dy dz d3d dxst dyst dzst d3dst dtstr) (defun *ERROR* (msg) (princ " - interrupted function ") (princ) ) (setq p1 (getpoint "\nFirst point")) (setq p2 (getpoint p1 "\nSecond point")) (setq xp1 (car p1)) (setq p1 (cdr p1)) (setq yp1 (car p1)) (setq p1 (cdr p1)) (setq zp1 (car p1)) (setq xp2 (car p2)) (setq p2 (cdr p2)) (setq yp2 (car p2)) (setq p2 (cdr p2)) (setq zp2 (car p2)) (setq dx (- xp2 xp1)) (setq dy (- yp2 yp1)) (setq dz (- zp2 zp1)) (setq d3d (sqrt (+ (* dx dx) (* dy dy) (* dz dz)))) (if (minusp dx) (setq dxst (strcat "DX = " (rtos dx 2 15))) (setq dxst (strcat "DX = " (rtos dx 2 15))) ) (if (minusp dy) (setq dyst (strcat "DY = " (rtos dy 2 15))) (setq dyst (strcat "DY = " (rtos dy 2 15))) ) (if (minusp dz) (setq dzst (strcat "DZ = " (rtos dz 2 15))) (setq dzst (strcat "DZ = " (rtos dz 2 15))) ) (setq d3dst (strcat "D3D = " (rtos d3d 2 15))) (setq dtstr (strcat dxst "\n " dyst "\n " dzst "\n" d3dst)) (princ "\n")(princ dtstr) (princ) ) Quote
lpseifert Posted April 8, 2009 Posted April 8, 2009 ran your code... results below My Luprec=4 $ (c:pdx) DX = 577.6934828948788 DY = 201.4911172458655 DZ = 0.000000000000000 D3D = 611.8238557854725 _$ I did a bit of experimenting, if you're interested 1$ (setq len1 (vlax-get-property obj 'length)) 295.109 _1$ (rtos len1 2 15) "295.1088455940600" _1$ (setq len2 (- len1 295.0)) 0.108846 _1$ (rtos len2 2 15) "0.108845594060029" _1$ If you send the results to an Alert box, it displays the same amount of decimal points. Quote
Lee Mac Posted April 8, 2009 Posted April 8, 2009 Why the IF statements? According the to code, won't it do the same either way? Quote
Lee Mac Posted April 8, 2009 Posted April 8, 2009 You could just re-write it more concisely to: (defun c:pdx (/ p1 p2) (while (and (setq p1 (getpoint "\nFirst point")) (setq p2 (getpoint p1 "\nSecond point"))) (alert (strcat "Distances: \n" "\nDX = " (rtos (abs (- (car p1) (car p2))) 2 15) "\nDY = " (rtos (abs (- (cadr p1) (cadr p2))) 2 15) "\nDZ = " (rtos (abs (- (caddr p1) (caddr p2))) 2 15) "\nD3D = " (rtos (distance p1 p2) 2 15)))) (princ)) Quote
CALCAD Posted April 8, 2009 Author Posted April 8, 2009 lpseifert, it appears that in your results the PRECISION argument is acting as a field width rather than precision after the decimal point. Strange. In Intellicad, the display is always 15 places after the decimal point. Thanks for taking the time to play with this. Lee Mac, thanks for questioning the code. Somehow the formatting of the lisp code got messed up and dropped some critical spaces. My intent was to provide a column for the minus sign and align the numbers regardless of sign. Your code displays the absolute value, which may be what you want. But I wanted to show the negative direction, if that's what the pick order produced. When it's my first effort, my code tends to be excessively explicit, to make it easy for me to understand! I will probably tighten it up with a rewrite. The code section should look like this : (if (minusp dx) (setq dxst (strcat "DX = " (rtos dx 2 15))) (setq dxst (strcat "DX = " (rtos dx 2 15))) ) (if (minusp dy) (setq dyst (strcat "DY = " (rtos dy 2 15))) (setq dyst (strcat "DY = " (rtos dy 2 15))) ) (if (minusp dz) (setq dzst (strcat "DZ = " (rtos dz 2 15))) (setq dzst (strcat "DZ = " (rtos dz 2 15))) ) (setq d3dst (strcat "D3D = " (rtos d3d 2 15))) I have updated the code in my first post. Quote
Lee Mac Posted April 8, 2009 Posted April 8, 2009 Oh, I see, perhaps this then? (defun c:pdx (/ p1 p2 dx dy dz) (while (and (setq p1 (getpoint "\nFirst point")) (setq p2 (getpoint p1 "\nSecond point"))) (setq dx (- (car p2) (car p1)) dy (- (cadr p2) (cadr p1)) dz (- (caddr p2) (caddr p1))) (alert (strcat "Distances: \n" "\nDX = " (if (not (minusp dx)) (chr 32) "") (rtos dx 2 15) "\nDY = " (if (not (minusp dy)) (chr 32) "") (rtos dy 2 15) "\nDZ = " (if (not (minusp dz)) (chr 32) "") (rtos dz 2 15) "\nD3D = " (rtos (distance p1 p2) 2 15)))) (princ)) Quote
CALCAD Posted April 8, 2009 Author Posted April 8, 2009 Very compact and now it runs continuously. Nice. Thanks Lee. Quote
Lee Mac Posted April 9, 2009 Posted April 9, 2009 Very compact and now it runs continuously. Nice. Thanks Lee. No Problem, I just like to keep things compact and concise... 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.