BAD FUNCTION using while loop to copy or insert block

BAD FUNCTION using while loop to copy or insert block

Anonymous
Not applicable
1,080 Views
3 Replies
Message 1 of 4

BAD FUNCTION using while loop to copy or insert block

Anonymous
Not applicable

I work with a solar company, and I am tasked with designing the sites. Doing this, we use a block for the solar panels I place on  a site.

 

I am trying to write a function that will:

  1. ask us how many arrays we want to place (this works)
  2. ask us where we want to insert the first array (this works)
  3. then based on the answer to 1, adds more arrays in the format we want.

Our arrays are spaced 20ft appart from the bottom of an array to the top of the next array. I have commented out the lines in the loop I think are causing the problem. 6.42 is the width of one row in the array, and 284.26 is the length of a row in the array, as you will see I used these lengths to make the insertion point at the top left of my array, the original insertion point is the bottom right side of the array. 

 

I have  a function that works that just sets down a single array at my wanted insertion point (identical to the top part of my code here), but I'd like it to put down multiple arrays if the user wants it.

 

Whats wierd is that it:

  1. changes the x position to something different than my "final X'
  2. it seems to only put one array down, and its the 'last' one of the total arrays I want. 

We don't use the 'row' quantity in rectangle array for these solar modules because we want to be able to adjust each row as needed to fit our sites. Thus, we use rect array and adjust the 'columns' quantity to add or subtract the modules. 

 

Here's the function that works for laying down a single set of modules:

(defun c:RBI84()
	(setq pointA (getpoint "\n Select the insertion point: "))
	(setq FinalX (+ (car pointA) 6.42))
	(setq FinalY (- (car (cdr pointA)) 284.26))
	(setq FinalPoint (list FinalX FinalY 0.0))
(command "-Insert" "1-RBI 84" FinalPoint "1.0" "1.0" "0.0")
(command "Arrayrect" (entlast) "" "1"  "19" "Rows" "1" "1" "0" "COLumns" "2" "19" "")
)

That looks like this when its done:

example1.PNG

 

Here's how I'd like the function that doesn't work to look when its done (if the user wants 2 arrays):

 

example2.PNG

 

Heres the function that doesn't work:


(defun c:TestRBI84() (setq NumberOfRows (getint "\n How many arrays do you want to place")) (setq pointA (getpoint "\n Select the insertion point: ")) (if (<= NumberofRows 1) ( (setq FinalX (+ (car pointA) 6.42)) (setq FinalY (- (car (cdr pointA)) 284.26)) (setq FinalPoint (list FinalX FinalY 0.0)) (command "-Insert" "1-RBI 84" FinalArrayPoint "1.0" "1.0" "0.0") (command "Arrayrect" (entlast) "" "1" "19" "Rows" "1" "1" "0" "COLumns" "2" "19" "") ) ( (while (>= NumberOfRows 2) ( (setq FinalArrayX FinalX) (setq FinalArrayY (+ FinalY (* NumberOfRows 304.26))) ;20ft plus array length (setq FinalArrayPoint (list FinalX FinalArrayY 0.0)) ;(command "Copy" (entlast) FinalPoint FinalArrayPoint) ;(command "-Insert" "1-RBI 84" FinalArrayPoint "1.0" "1.0" "0.0") ;(command "Arrayrect" (entlast) "" "1" "19" "Rows" "1" "1" "0" "COLumns" "2" "19" "") (setq NumberofRows (- NumberOfRows 1)) ) ) ) ) )

Those three commented out lines are where the problem is, but I keep just getting "bad function" in cad.

 

Should I copy the original, or insert new blocks? Is there a different processing for duplicating the first array that I should go about? 

 

Thanks!!

0 Likes
Accepted solutions (1)
1,081 Views
3 Replies
Replies (3)
Message 2 of 4

CodeDing
Advisor
Advisor
Accepted solution

@Anonymous,

 

I don't have your block to test with... Try this to see if it works. Or post your block to test please.

(defun c:TestRBI84()
(initget 7);prevents - no val, 0 val, neg numbers
(setq numRows (getint "\n How many arrays do you want to place"))
(setq startPnt (getpoint "\n Select the insertion point: "))
(setq ptX (+ (car startPnt) 6.42) ptY (cadr startPnt) tmp 1) ;(- (cadr startPnt) 284.26)
(repeat numRows
	(if (= 1 tmp) (setq ptY (+ ptY 284.26)) (setq ptY (+ ptY 304.26)))
  	(setq ptFinal (list ptX ptY 0.0))
	(command "-Insert" "1-RBI 84" ptFinal "1.0" "1.0"  "0.0")
	(command "Arrayrect" (entlast) "" "1"  "19" "Rows" "1" "1" "0" "COLumns" "2" "19" "")
  	(setq tmp (1+ tmp))
);repeat
);defun

Best,

~DD

0 Likes
Message 3 of 4

jwhite
Advocate
Advocate

You need to use progn after the if...

(if (<= NumberofRows 1)
		(progn
			(setq FinalX (+ (car pointA) 6.42))

The else portion needs progn as well.

0 Likes
Message 4 of 4

CodeDing
Advisor
Advisor

@Anonymous,

 

That first one was a bit sloppy. Here, I cleaned up a bit. Sorry!

(defun c:TestRBI84(/ numRows startPnt ptX ptY tmp)
(initget 7);prevents - no val, 0 val, neg numbers
(setq numRows (getint "\n How many arrays do you want to place"))
(setq startPnt (getpoint "\n Select the insertion point: "))
(setq ptX (+ (car startPnt) 6.42) ptY (cadr startPnt) tmp 1)
(repeat numRows
	(if (= 1 tmp) (setq ptY (+ ptY 284.26)) (setq ptY (+ ptY 304.26)))
  	(setq ptFinal (list ptX ptY 0.0) tmp (1+ tmp))
	(command "-Insert" "1-RBI 84" ptFinal "1.0" "1.0"  "0.0")
	(command "Arrayrect" (entlast) "" "1"  "19" "Rows" "1" "1" "0" "COLumns" "2" "19" "")
);repeat
);defun

Best,

~DD

 

0 Likes