Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lisp routine - select polyline and apply formula help

21 REPLIES 21
SOLVED
Reply
Message 1 of 22
mpa-la
1526 Views, 21 Replies

lisp routine - select polyline and apply formula help

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!

 

21 REPLIES 21
Message 21 of 22
Lee_Mac
in reply to: mid-awe


@mid-awe wrote:

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 **?


It is good practice to enclose global variables inside asterisks in so much as the resulting symbols are more obscure and less likely to conflict with other symbols defined in the document namespace; however, this is the only purpose of the asterisks - it is not mandatory to use asterisks for all global variables.

 

In general, you can use any global variable naming convention which ensures a low probability that the symbol is not already defined in the document namespace by another program. The suggestion of using asterisks is a good tip for beginners when first introduced to global variables, without getting into the details.

 

I have used several variations for globals in the past - some with asterisks, some with vertical bars (as you have noted), and most recently I now tend to use the function symbol as a prefix, followed by a semi-colon, e.g.:

 

(defun c:af ( / a e )
    (setq af:x (cond ((getreal (strcat "\nX-Value <" (rtos (cond(af:x)(100)) 2) ">: ")))(af: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 af:x af:x))))))
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Message 22 of 22
Lee_Mac
in reply to: Anonymous


@Anonymous wrote:

Hi Lee_Mac,
Special Thanks to you.
You will always have another way of coding which is out of Box.

Thank you aliensinearth Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost