SwChilly Posted June 2, 2011 Posted June 2, 2011 I'm working on a homework assignment that is due tomorrow. Basically all I want to be able to do is draw a grid based on a point the user gives us and how many rows and columns they want. So far I has this: ; Prompts the user to creat grid using Lower Left or Upper Left Starting points ; Prompts for Grid Spacing and size (in cells) ; Get Grid color and layer "MYGRID" ; prints grid with proper spacing , size and color ; Returns to Layer 0 (defun c:ygrid () (setq ans nil) (setq llpoint nil) (setq ulpoint nil) (prompt "\nAre you making a Lower Left starting point or an Upper Left starting point?" (yn_ll_ur) (if (= ans "LL") (make_grid_ll) (if (= ans "UL") (make_grid_ul) ))) ) (defun make_grid_ll () (setq llpoint (getpoint "Get Lower Left Point: ")) (setq grid_cell_size nil) (setq grid_cell_num nil) (setq cell_counter 1) (setq grid_cell_size (getreal "Please enter cell size: ")) (setq grid_cell_num (getint "Please enter number of cells in each row or column: ")) (command "_.line" llpoint (list (+ (nth 0 llpoint) grid_cell_num) (nth 1 llpoint)) "") (repeat grid_cell_num (setq pointx (nth 0 llpoint)) (setq pointy (nth 1 llpoint)) (command "_.line" [b] IT CRAPS OUT SOMEWHERE HERE [/b] ((pointx (+ pointy (* grid_cell_size cell_counter)))) ((+ pointx grid_cell_num) (+ pointy (* grid_cell_size cell_counter) "")) (setq cell_counter (+ cell_counter 1) ) ) ) ) It basically can draw the first line but in the reapeat loop is doesnt work... anyone know of a better way to write this or better lisp? Thanks! Quote
JohnM Posted June 3, 2011 Posted June 3, 2011 You should not wait until the last minute to do your homework. Here are a few pointers Always localize you variables (defun c:test ( / var1 var2 var……..) Try to keep variables to 6 characters or less if possible (it’s a memory thing) Look up the initget function to use with the getkword function to get specific user input in place of the prompt. Do not combined questions. Ask 2 questions if needed to get proper data. For grids I would suggest using rectangle not lines Look up the polar function for projecting points There is a lot more but this should get you going in the right direction Quote
BIGAL Posted June 3, 2011 Posted June 3, 2011 Sorry johnM use lines for grid back swchilly you need two repeats 1 for horizontal the second for vertical also num of rows num of columns I would also only ask for one start point else making it over complicated you should create two new points for each line, start & end using a ptx= ptx + x, pty = pty +y etc then ptxy = (list ptx pty) rather than working out all the points in one go a series of point then your line commnad becomes (Line start end "") then work out next line posted an example of this yesterday look at posts. this is bits of what you want not complete as its your assignment this labels the grids as well. (setq IP1 (getpoint "\nSTARTING POINT (TOP LEFT CORNER): ")) (setq X(car IP1)) (setq Y(cadr IP1)) (setq #EW(getint"Number of GRIDS across: ")) (setq EW1(getint"Dimension for first GRID: ")) .. .. (repeat #ns (Repeat #ew (command "line" start end "") (setq x (+ X EW1) (setq topx (+ topx ew1)) (setq start (list x y)) (setq end (list topx y)) ) Quote
troggarf Posted June 3, 2011 Posted June 3, 2011 Here's one approach that you may be able to learn from. It is an advanced approach that uses the grread function so I doubt that you could use this and claim it as your own if the teacher were to ask you how the grread function works. Not created by me. I'm just a beggar showing where the other beggars came find bread... Created by RonJon over at the Swamp. ~Hope this helps ; By RonJonP found @ http://www.theswamp.org/index.php?topic=25575.0 (defun c:detailgrid (/ cnt coldiv columnpts columns ll lr p pt rowdiv rowpts rows ul ur) (defun addplineforgrid (pt1 pt2 layer /) (vla-update (vlax-ename->vla-object (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") (cons 8 layer) '(100 . "AcDbPolyline") '(90 . 2) '(43 . 0.0) (cons 10 pt1) (cons 10 pt2) ) ) ) ) ) (defun rjp-vector_x (pt clr / l bl br ul ur) (setq l (* 0.015 (getvar 'viewsize)) bl (polar pt 3.926 l) br (polar pt -0.785 l) ul (polar pt -3.926 l) ur (polar pt 0.785 l) ) (grvecs (list clr bl ur br ul)) (princ) ) (if (and (setq rows (getint "\nEnter number of rows: ")) (setq columns (getint "\nEnter number of columns: ")) (setq ul (getpoint "\nSelect upper left corner of grid: ")) (not (or (<= rows 0) (<= columns 0))) ) (progn (while (and (setq p (grread 5)) (= (car p) 5)) (redraw) (if (setq lr (osnap (cadr p) "_end,_int,_mid,_cen")) (rjp-vector_x lr 1) (setq lr (cadr p)) ) (setq ur (list (car lr) (cadr ul)) ll (list (car ul) (cadr lr)) rowdiv (/ (distance ul ll) rows) coldiv (/ (distance ul ur) columns) columnpts nil rowpts nil cnt 0 ) (repeat (1- rows) (setq cnt (+ cnt rowdiv) pt (polar ul (angle ul ll) cnt) ) (repeat columns (setq rowpts (cons (list pt (setq pt (polar pt (angle ul ur) coldiv))) rowpts ) ) ) (grvecs (cons 3 (apply 'append rowpts))) ) (setq cnt 0) (repeat (1- columns) (setq cnt (+ cnt coldiv) pt (polar ul (angle ul ur) cnt) ) (repeat rows (setq columnpts (cons (list pt (setq pt (polar pt (angle ul ll) rowdiv))) columnpts ) ) ) (grvecs (cons 5 (apply 'append columnpts))) ) (grtext -2 (strcat "Row: " (rtos rowdiv) " X Column: " (rtos coldiv)) ) ) ) ) (redraw) (foreach x rowpts (addplineforgrid (car x) (cadr x) "gridline") ) (foreach x columnpts (addplineforgrid (car x) (cadr x) "gridline") ) (princ) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.