I know this is a really simple routine, if someone could help me out I'd be very appreciative. Here is the formula I would like to use:
(166.24 / X squared) * area of selected polyline. An example for clarity, if X is 12 and the area of the selected polyline was 100, it would be (166.24 / 144) * 100 = 115.
I would like to issue the command, enter the number for X, pick the polyline, and have the resultant whole number (no decimals) output on the command line. I would like it to remember whatever X is (for that drawing session) until I change it so that I can enter past that question if I'm not changing it.
Thanks again if you can help!
Solved! Go to Solution.
Solved by aliensinearth. Go to Solution.
Solved by mid-awe. Go to Solution.
Is this what you are looking for?
(DEFUN c:SP-n-AF (/ AREA CUROBJ TTL X)
(VL-LOAD-COM) (SETQ X (GETREAL "\nEnter a value for X: ") CUROBJ (VLAX-ENAME->VLA-OBJECT (CAR (ENTSEL))) AREA (VLA-GET-AREA CUROBJ) TTL (* (/ 166.24 (* X X)) AREA) ) (PRINC (strcat "\n\t=>> Total after formula applied: " (FIX ttl) " \n")) (PRINC) )
It works! When it returns the value though, it says (on the command line) "Select object: ; error: bad argument type: stringp" and then the formula result. Is that a quick fix?
Thanks so much, this will be a real time saver! Allison
Here is the modified code that will remember the last value of X until you close the drawing.
(DEFUN c:SP-n-AF (/ AREA CUROBJ TTL X) (VL-LOAD-COM) (IF (NOT *X) (SETQ *X 100) ) (PRINC "\nEnter a value for X or <") (PRINC *X) (SETQ X (GETREAL "> : ")) (IF (NOT X) (SETQ X *X) (SETQ *X X) ) (SETQ CUROBJ (VLAX-ENAME->VLA-OBJECT (CAR (ENTSEL))) AREA (VLA-GET-AREA CUROBJ) TTL (* (/ 166.24 (* X X)) AREA) ) (PRINC (strcat "\n\t=>> Total after formula applied: " (ITOA (FIX TTL)) " \n")) (PRINC) )
You need to remove X from the localized variables for the "remember the last value of X until you close the drawing" to work.
Hi mid-awe,
Thanks for your reponse.
Your code was very short and sweet.
I think, we don't need to remove X. Because, I have used another varibale as "*X". This "*X" will remember the last value of X.
Here's another way to write it:
(defun c:af ( / a e x ) (setq x (cond ((getreal (strcat "\nX-Value <" (rtos (cond(x)(100)) 2) ">: ")))(x)(100))) (if (setq e (car (entsel))) (if (vl-catch-all-error-p (setq a (vl-catch-all-apply 'vlax-curve-getarea (list e)))) (princ "\nInvalid object.") (princ (strcat "\nResult: " (itoa (fix (* a (/ 166.24 x x)))))) ) ) (princ) ) (vl-load-com) (princ)
@Lee_Mac wrote:
....
... (itoa (fix (* a (/ 166.24 x x))))
....
If what you want [it isn't clear to me from the original question] is actually the result rounded to the nearest whole number [up or down], rather than stripped of any decimal component no matter how large [i.e. rounded down only as the above does], replace the above part with:
(rtos (* a (/ 166.24 x x)) 2 0)
@mid-awe wrote:
(getreal (strcat "\nX-Value <" (rtos (cond(x)(100)) 2) ">: "))
& then you go and
(vl-catch-all-apply 'vlax-curve-getarea (list e))
you just
(itoa (fix (* a (/ 166.24 x x))))
says, Lee Mac.
"Were not worthy" 🙂 Thank you.
You're too kind mid-awe -
Though, looking back over my code, there is a slight mistake: the variable 'x' should be global (and perhaps renamed to something more obscure).
I've been studying your "Object Align" code. I see you used "oa|rot" & "oa|off", two globals. I thought it was good practice to wrap globals in **? Or, you are using an old trick for namespacing? ObjectAlign.rotation & ObjectAlign.offset?
I use javascript a lot and I do something simular with my globals.
$oa = { rot: value, off: value, } $oa.rot = value; $oa.off = value; if ($ao.rot === 'false') { $oa.rot = 0.0 } if ($ao.off === 'false') { $oa.off = 0.0 }
Or, it could be thought of as a local-global 😉 I refere to the unlikely event that you'd reuse the same global for two different things.
Whoops - sorry mid awe, I used the one from aliensinearth becuase it remembered my initial x value. I didn't notice that it wasn't you! I'm gonna see if I can accept two as solutions. Allison