Rectangle (square) with Holes

Rectangle (square) with Holes

Anonymous
Not applicable
1,825 Views
7 Replies
Message 1 of 8

Rectangle (square) with Holes

Anonymous
Not applicable

This topic may have been addressed before but i may have missed it. 

 

I need to write an Autolisp routine to do a rectangualar base plate where the user inputs the following parameters:

 

Length and Width of the rectangle (base plate)

 

Number of holes (Ideally between 4 and 10) and their sizes

 

Centre distances between the holes

 

 

0 Likes
1,826 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant

Welcome to these Forums!

 

That sounds like it should be doable, but so many questions arise....

 

What about distance(s) from plate edge(s) to hole center-lines?  Would the User specify that [or those?], or would that/they be just what's left over as a result of the number of holes and their spacing?

 

All holes always the same size in each plate, or might there be different sizes within one plate?

 

Always equally spaced holes?  If so, the same in both directions, or equally within each direction but possibly different in the two directions?

 

I think [from my experience with such things, limited as it is] I can assume it will always be an even number of holes.  But would they always be in two rows down opposite edges, or might there sometimes be configurations such as this?

BasePlate.png

 

Always only around the edges like that, or might there sometimes be any internal hole(s)?  [In which case, the number might be odd....]

 

A sample drawing or image showing the extremes of the range of possibilities would be helpful.

 

Meanwhile, since you say "I need to write" [always a welcome thing here], may we assume you already know enough to write some of the starting elements?  Prompts for the inputs, and saving them into variables, etc.  People here can help you with ways to create the plate outline and calculate what's needed to place the holes from there.

Kent Cooper, AIA
0 Likes
Message 3 of 8

Anonymous
Not applicable

Thank kent for the response and eye opener. We have sort of refined the problem but it has become more complexSmiley Frustrated 

I have attached the new base plate configuartion and possible pump configurations. NOTE there are more configurations that can be added.

Now the procedure should be like this:

1. The user selects the primary pump size (P1)after which

2. the user selects the secondary pump size (p2) after which

3. The programm draws up the base plate layout based on the correct data picked from the excel spreadsheet.

 

At this point i would appreciate help with the coding and the determination/calculations of variables and or linking to a spreadsheet or databse as provided.

 

Thanks a lot..

0 Likes
Message 4 of 8

smaher12
Advocate
Advocate

tgarikai,

 

Is your pump list going to be 50+ entries that you need the program to read from a (xls, cvs, txt) file? If you only have a small list of entries, I would just incorporate the list with some (cond.

 

In your sample spreadsheet it looks like Pump Size P1 does not apply as Pump Size P2 are all different numbers. Will this stay true?

 

I also see for Pump Size P1 (32-125) you have two 142 for Pump Size P2 which will propose a problem. Was that just a typo? 

0 Likes
Message 5 of 8

Anonymous
Not applicable

Hi Advocate Smaher12Smiley Tongue

 

Yes the entries exceed 50+

 

P1 is the main category for various pump sizes. In other words there are 7 pump sizes falling under size 32-125.1.

 

With regards to the two 142s, it was a bit of an oversight from me, the first 142 is a 2-pole and the second 142 is a 4-pole. In other words we can further define it as 142-2 and 142-4. 

 

I hope this helps. 

 

Thanks

0 Likes
Message 6 of 8

smaher12
Advocate
Advocate

With the help of Afralisp.net I was able to get the following together. Rather than reading from a excel file this program reads from .dat files. The program has good bones and the next step would probably be to solve the hole quanity. lsp and dat files are in the attached file.

 

(defun C:Test (/ item data dline maxs 
                    count chrct numb size)

  (setq ptype 
    (getstring "\nEnter Pump Type <32-125.1, 32-125>: "))

  (setq size 
    (getstring "\nEnter Size <100, 110, 121>: "))	;enter size req'd
  (setq dlist nil
	size  (strcat "*" size)				;add asterix to size
	ptype (strcat ptype ".dat")
	file  (findfile ptype)  			;find data file
	fp    (open file "r")				;open file to read
	item  (read-line fp)				;first line is label for file
  );setq

  (while item						;process each line of file
    (if	(= item size)					;compare values
      (setq data (read-line fp)				;read a line
	    item nil					;stop searching for item
      );setq
      (setq item (read-line fp))			;keep searching for item
    );if
  );while
  (if data						;if the size has been found
    (progn
      (setq maxs  (strlen data)				;establish length of input
	    count 1					;initiliaze count
	    chrct 1					;initiliaze char position
      );setq
      (while (< count maxs)				;process string one chr at a time
	(if (/= "," (substr data count 1))		;look for the commas
	  (setq chrct (1+ chrct))			;increment to next position
	  (setq	numb  (atof 
               (substr data 
		  (1+ (- count chrct)) chrct))  	;convert to real
		dlist (append dlist (list numb))	;add it to the list
		chrct 1					;resets field ct
	  );setq
	);if
	(setq count (1+ count))				;increment the counter
      );while
      (setq numb  (atof 
           (substr data 
                  (1+ (- count chrct))))        	;convert to real
	    dlist (append dlist (list numb))		;add it to the list
      );setq
    );progn
  );if data
  (close fp)						;close data file
(mapcar 'set '(a b c d e f) dlist)			;allocate to variables

  (setq p1 (getpoint "\nSpecify starting point: "))
  (command "_.pline"
    "_none" (list (- (car p1) (/ a 2)) (- (cadr p1) (/ d 2)))
    "_none" (list (+ (/ a 2) (car p1)) (- (cadr p1) (/ d 2)))
    "_none" (list (+ (/ a 2) (car p1)) (+ (/ d 2) (cadr p1)))
    "_none" (list (- (car p1) (/ a 2)) (+ (/ d 2) (cadr p1)))
    "c"
  )
  (setq p2 (list (- (car p1) (/ c 2)) (cadr p1))
        p3 (list (+ (/ c 2) (car p1)) (cadr p1))
  )
  (command 
    "_.circle" "_none" (list (car p1) (+ (/ e 2) (cadr p1))) f 
    "_.circle" "_none" (list (car p1) (- (cadr p1) (/ e 2))) f
    "_.circle" "_none" (list (car p2) (+ (/ e 2) (cadr p2))) f
    "_.circle" "_none" (list (car p2) (- (cadr p2) (/ e 2))) f
    "_.circle" "_none" (list (car p3) (+ (/ e 2) (cadr p3))) f
    "_.circle" "_none" (list (car p3) (- (cadr p3) (/ e 2))) f ""
  )
 (princ)
);defun

 

Credits: http://www.afralisp.net/autolisp/tutorials/external-data.php

0 Likes
Message 7 of 8

Anonymous
Not applicable

Thanks for this insight SMAHER12, i am looking at it now and will come back with a report shortly.

0 Likes
Message 8 of 8

smaher12
Advocate
Advocate

tgarikai,

 

I made a few updates with the attached file. As far as the error that you were receiving previously, don't forget to have the .dat files in the same location as your .lsp file. 

0 Likes