View Full Version : IF Function
mikecperez2002
2013-11-04, 07:08 PM
I have a lisp that I wrote to use the array command on rectangle with some variables that the user must input. Can the IF function be used if the user selects odd or even number of columns and rows in the array command? My issue is that the rectangle will be arrayed in 2 areas with a gap between them. I need to be able to specify which array will get the extra column or row. Any help will be appreciated.
Thanks,
Mike
BlackBox
2013-11-04, 08:11 PM
Not sure I fully understand... Could you please post your code?
Cheers
mikecperez2002
2013-11-04, 09:40 PM
Sorry...here is the code I have so far. The problem is that is a user decided to array the rectangle with 41 rows...how can I have the lisp decide where to put the odd number of rows?
(defun C:SDA ()
(setq
istpt (getpoint "\Select Strating Point (Lower Left)");
iTW (getint "\nWidth of Rectangle: ");
iTH (getint "\nHeight of Rectangle: ");
iNR (getint "\nNumber of Rows: ");
iRS 14;
iET 4;
iGAP 20;
SAStPt1 istpt;
SAStPt1a (Polar istpt 0 (- SAwd iTW ));
SAStPt4 (polar iStPt (dtr 90) (+ SAHT iGAP));
);setq
;Draw Array 1
(setq
ST1P1a SAStPt1a;
ST1P2a (polar ST1P1a 0 iTW);
ST1P3a (polar ST1P2a (dtr 90) iTH);
ST1P4a (polar ST1P1a (dtr 90) iTH);
);setq
(command "pline" ST1P1a ST1P2a ST1P3a ST1P4a "c")
;(command "rectang" ST1P1a ST1P3a)
(command "_.-array" "l" "" "R" (/ iNR 2) (/ iET 2) iRS iTW);
;Draw Array 2
(setq
ST4P1 SAStPt4;
ST4P2 (polar ST4P1 0 iTW );
ST4P3 (polar ST4P2 (dtr 90) iTH );
ST4P4 (polar ST4P1 (dtr 90) iTH);
);setq
(command "pline" ST4P1 ST4P2 ST4P3 ST4P4 "c")
;(command "rectang" ST41 ST4P3)
(command "_.-array" "l" "" "R" (/ iNR 2) (/ iET 2) iRS iTW);
);defun c:SDA
;;;( dtr a)
(defun DTR (a)(* pi (/ a 180.0)))
;;;Radian To Dergee
;;; a - angle in radian
;;;( R2D a)
(defun RTD (a)(/ (* a 180.0) pi))
mikecperez2002
2013-11-05, 09:41 PM
Can anyone help??????
how can I have the lisp decide where to put the odd number of rows?
I do not think anyone here can determine how the logic of your routine works.
How would you manually decide on where the odd number of rows should be placed? Start there.
mikecperez2002
2013-11-06, 02:56 AM
Thanks Opie, but how could I use the IF function on a lisp. I've never used it before. I've only done a hand full of lisp and none of them needed it. They were pretty basic.
Right now you have some calculation being handled while you are doing the actual array. I would suggest moving those calculation before you get to that point. You can then determine what to do with the leftover number of rectangles.
BTW, you are missing a definition of the variables SAwd and SAHT.
mikecperez2002
2013-11-08, 10:54 PM
ok after some search online I seem to be stuck. Let me try to rephrase the question. If I have a variable that the user must input, how can I round up or down the resulting variable. For example, if a user must input the variable iNR, for number of rows, and iNRS = iNR / 2, how can I round up the number if iNR is an odd number. So the user inputs 41 for iNR. If you divide by 2 it will equal 20.5. How can I get it to round up to 21?
This is my attempt, but not being very familiar with advanced lisp it's been a learning experince.
Thanks,
Mike
iNR (getreal "\nNumber of Rows: ")
iNRS (/ iNR 2)
(if (= odd) (setq iNRS (+ (/ iNR 2) 0.5))))
mikecperez2002
2013-11-08, 11:53 PM
ok after some long searching online, I'm stuck. I'm going to try to rephrase my question. Now please keep in mind that im not a very advance lisp user. If I have a routine that promps a user to input number of rows, and if the number of rows is an odd number, how can I use the if function to round up?. For example, in the code below, a user is prompt to insert "Number of Rows", variable iNR. But variable iNRS is (/ iNR 2) which if the iNR is an odd number iNRS would have a decimal. So if the user would select 41 rows, for iNR, then iNRS would be 20.5. How can I get iNRS to be 21?
iNR (getreal "\nNumber of Rows: ")
iNRS (/ iNR 2)
(if (= oddp) (setq iNRS (+ (/ iNR 2) 0.5))))
Thanks,
Mike
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.