Dynamically draw grid (From Lee Mac)

Dynamically draw grid (From Lee Mac)

Anonymous
Not applicable
5,550 Views
25 Replies
Message 1 of 26

Dynamically draw grid (From Lee Mac)

Anonymous
Not applicable

Hi guys, I have found a useful lisp file from Lee Mac which draws x and y grids in a given space by enter no. of columns and rows. And you can visualize this with "dgridd" command as you draw which is really helpful for me.

 

I am drafting waffle footing slabs for houses so I was looking to modify the routine with following requirements.

 

1. I don't want to divide a space in equal parts with given no. of columns and rows. Instead I would like to set the distance of each increment = 1200mm

 

2. Instead of single lines, I would like to see fixed 1090mm x 1090mm box being drawn visually at 1200mm x and y spacing so in the end it should look like following: (I am not concerned about the total space, so as to say, I do not have a fixed boundary in which to fit this all).

 

Refer below the yellow lines. Each box is 1090x1090 mm and is spaced every 120mm so you get 100mm rib in between.

 

 

wasemrana8_0-1608341036334.png

 

0 Likes
Accepted solutions (2)
5,551 Views
25 Replies
Replies (25)
Message 2 of 26

Anonymous
Not applicable

Correction: 110mm rib. Also, ignore the pier circles.

0 Likes
Message 3 of 26

devitg
Advisor
Advisor

@Anonymous You can do  it by ARRAYclassic .  

0 Likes
Message 4 of 26

Anonymous
Not applicable

Hi @devitg thanks for your reply.

 

This is how I am doing it already by copy>array> command but I'd like to see it dynamically as I draw and stretch from a point to establish if the layout is perfect, as sometimes I have to change the starting position to have most feasible layout.

0 Likes
Message 5 of 26

hak_vz
Advisor
Advisor
Accepted solution

@Anonymous 

Test this code. Function CreateMyGrid creates grid with rectangle sized and spaced the way you described.

Grid is stored in selection set variable named MG so instead recreating grid you just use command move and

move it as many time you want to place it to desired position

 

 

Command: MOVE
Select objects: !MG
<Selection set: fd>
25 found
Select objects:Select objects: <enter>
.....
.....

 

 

With each run of CreateMyGrid function, last stores selection set in variable MG is overwriten with last created grid.

To store last created grid before running a command you can simply set it to new varible by writing in command line, let say:

 

(setq grid_room_101 mg)<enter> that is later called using !grid_room_101

 

 

(defun c:createMyGrid ( / p nr nc e)
(setq  mg(ssadd))
(setq nr (getint "\nNumber of grid rows >"))
(setq nc (getint "\nNumber of grid columns >"))
(setq p (getpoint "\nPick Lower left point of bottom left rectangle >"))
(command "_.rectang" "non" p "non" (mapcar '+ p (list 1090 1090)))
(ssadd (setq e(entlast)) mg)
(command "-array" (setq e (entlast)) "" "R" nr nc 1200 1200)
(while (and(setq e (entnext e)))(setq mg(ssadd e mg)))
(princ "\nSelection set stored to variable MG")
(princ "\nUse in commands like MOVE using !MG")
(princ)
)

 

If this is what you asking for, then hit button "Accept solution"

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 6 of 26

Anonymous
Not applicable

HI @hak_vz 

Thanks very much for the effort. The end result is exactly what I want.

 

However,

 

1. I do not need to store the selection. So function not required.

2. Is there a way, I can see the grid visually growing up as I move my mouse? I don't really need to put pre defined no of x and y.

 

Otherwise it looks good.

0 Likes
Message 7 of 26

hak_vz
Advisor
Advisor

@Anonymous wrote:

HI @hak_vz 

Thanks very much for the effort. The end result is exactly what I want.

 

However,

 

1. I do not need to store the selection. So function not required.


In your previous post you stated:

"This is how I am doing it already by copy>array> command but I'd like to see it dynamically as I draw and stretch from a point to establish if the layout is perfect, as sometimes I have to change the starting position to have most feasible layout."

 

When you have grid selection set stored in a variable, you can call it in any command you like as long as

current file is open. So you can move it, stretch it..... instantly or two hours later. No need to start all over again.

Convert grid to block to make uneven  scaling.......

 


@Anonymous wrote:

2. Is there a way, I can see the grid visually growing up as I move my mouse? I don't really need to put pre defined no of x and y.

 Someone can converts Lee's script. I've created simple script that offers a lots of options

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 8 of 26

Sea-Haven
Mentor
Mentor

Wrote a waffle routine like 30 years ago will draw waffles for any pline shape including does a trim on curves. You just pick pline and control point where the 1st waffle will be laid.

 

Its one of those interesting programs wrote it gave to company for testing they were impressed it takes like a blink these days to do. The gotcha never got paid for it. I know they were using it as years later called in on a company that had bought out the 1st company and they bragged how good the waffle program was went vey quite when I remarked that we were never paid. I dont own the code only wrote it for the company I was working for and its one of a few bits of code I dont have .

 

Happy to discuss more the method is very simple and does not involve grids. 

Message 9 of 26

Anonymous
Not applicable

Hi @hak_vz Thanks for your solution. I might not have been clear in my question and thanks again for providing these functionalities, however, I really don't require move, stretch or uneven scaling.

 

I just have the fixed box size of 1090x1090 and fixed spacing of 1200. The only other functionality I really require is to select a start point and see visually these boxes as I drag my mouse away from the corner filling up that space with 1090x1090mm boxes spaced at 1200mm.

 

So that if I feel I need to change the starting point because it is not really filling up as I wish, I just can cancel the command and start over from another starting point and so on.

0 Likes
Message 10 of 26

Anonymous
Not applicable

Hi @Sea-Haven I can understand. Been into this position from programs I wrote in VBA. Unfortunately I am completely new to LISP. It is only when I started my own practice recently that I needed to draft myself as well and was wondering why can't I use LISP like I have been using VBA for every other thing for my structural design applications.

0 Likes
Message 11 of 26

hak_vz
Advisor
Advisor

@Anonymous wrote:

The only other functionality I really require is to select a start point and see visually these boxes as I drag my mouse away from the corner filling up that space with 1090x1090mm boxes spaced at 1200mm.


This functionality is completely different from what you've in Lee's script for dynamic grid.

Description of Lee's script is:

This program will prompt the user for a number of rows and columns then proceed to construct a grid composed of Line Entities between two corner poins.
If called with 'DGrid' (Draw Grid) at the AutoCAD command-line, the program will operate in standard mode, with all standard AutoCAD functionality (such as Object Snap / Tracking / Orthomode etc.) available to the user.
If called with 'DGridD' (Draw Grid Dynamic) at the AutoCAD command-line, the program will display a real-time preview of the grid constructed between the two corner points; however, Object Snap is imitated during the preview, and most other AutoCAD functionality (such as Tracking / Orthomode etc.) is unavailable in this mode.

The program will remember the last used number of rows and columns during the active drawing session, and these values will be available as defaults for the next use.

 

So you have to enter number of rows and cols and then you can fit this grid inside rectangle area. For your request, one would have to track position of cursor and add or remove rectangles if they fit inside dynamic selection rectangle created using grxxx functions. This is not an easy task to accomplish (haven't seen anything similar) .

 

That's why I proposed  a simple solution with storing a grid inside a variable so it can be easily moved around or aligned to let say wall edge. 

I'll try to write something that would work as you asking for, but this is really not an easy stuff to be written in short time.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 12 of 26

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this routine using a dynamic array.

Unfortunately, there is an extra step that I can't figure out how to automate - you need to pick a grip manually.

 

(defun c:ArrayWaffle (/ p e)

  (and (setq p (getpoint "\nInitial point: "))
       (setq e (entmakex (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 4) '(70 . 1))
				 (mapcar '(lambda (r) (cons 10 (mapcar '+ p r))) '((0 0) (1090 0) (1090 1090) (0 1090))))))
       (not (command-s "_.arrayrect" e "" "_c" 2 2 "_s" 1200 1200))
       (command "_.explode" "_l")
       )
  (princ)
  )

 

Message 13 of 26

Anonymous
Not applicable

@hak_vz Thanks for educating. I did not know this. No worries and I will keep using your routine until I get something else.

0 Likes
Message 14 of 26

Anonymous
Not applicable

@ВeekeeCZ 

Thanks. Yes, this is something interesting. Let's see if someone can post a solution to the step you are referring, otherwise I can manually enter the no. of rows and columns.

0 Likes
Message 15 of 26

ВeekeeCZ
Consultant
Consultant

Sure, you can do that... but I thought that you want have a dynamic preview - see THIS 

0 Likes
Message 16 of 26

hak_vz
Advisor
Advisor

@ВeekeeCZ wrote:

Unfortunately, there is an extra step that I can't figure out how to automate - you need to pick a grip manually.


 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 17 of 26

Sea-Haven
Mentor
Mentor

Ok the secret ignore grid use array, the sequence is pick control point this is where the 1st waffle goes normally a corner so the correct point is 300,300 offset concrete edge beam. Pick lower left, upper right outside pline. Work out lower left point based on the waffle sizes then draw an array covering all the shape, do say extrim as using a offset cut pline all done need to patch the cut waffles on the cut edge. Need some time to redo the code, anyone else jump in.

 

screenshot308.png

 

 

 

0 Likes
Message 18 of 26

elliot_
Observer
Observer

Did you ever implement this next step?

0 Likes
Message 19 of 26

Sea-Haven
Mentor
Mentor

I did not rewrite it but will add to my to do list, need a sample dwg to make edge beam offset etc is correct as well as the spacing the waffles being 1090x1090 ? Is it imperial or metric ?

0 Likes
Message 20 of 26

Sea-Haven
Mentor
Mentor
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/dynamically-draw-grid-from-lee-mac/td-p/9950301
; do waffles
: By alanh June 2023

(defun c:waffle ( / oldsnap pt1 ent co-ord pointmin pointmax xd yd xsp ysp)
(setq oldsnap (getvar 'osmode))
(setq osmode 1)
(setq oldlay (getvar 'clayer))
(setq sq 1090 2sq 2180 gap 300)
(setq pt1 (getpoint "select control point "))
(setq ent (ssname (ssget pt1) 0))
(setq obj (vlax-ename->vla-object  ent))
(setq ptc (osnap (vlax-curve-getStartPoint obj) "gcen"))
(setq lay (vla-get-layer obj))
(vla-GetBoundingBox obj 'minpoint 'maxpoint)
(setq pointmin (vlax-safearray->list minpoint))
(setq pointmax (vlax-safearray->list maxpoint))
(setq pointmin (mapcar '+ pointmin (list (- (+ 2sq gap))(- (+ 2sq gap)) 0.0)))
(setq pointmax (mapcar '+ pointmax (list (+ 2sq gap)(+ 2sq gap) 0.0)))
(setq xd (abs (- (car pointmin)(car pointmax))))
(setq yd (abs (- (cadr pointmin)(cadr pointmax))))
(setq xsp (fix (/ xd (+ sq gap))))
(setq ysp (fix (/ yd (+ sq gap))))
(command "-layer" "m" "Waffle" "C" 1 "" "")
(command "rectang" pointmin (mapcar '+ pointmin (list sq sq  0.0)))
(command "array" (entlast) "" "R" ysp xsp (+ sq gap) (+ sq gap))
(command "explode" (entlast))
(setq ent2 (entlast))
(command "-layer" "m" "Waffledummy" "C" 32 "" "")
(command "offset" gap ent ptc "")
(setq ent3 (entlast))
(command "chprop" ent3 "" "la" "Waffledummy" "")
(command "layiso" ent2 ent3 "")
(setvar 'osmode 0)
(command "offset" 0.5 ent3 (getvar 'extmax) "")
(setq ent4 (entlast))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))
(setq co-ord (cons (last co-ord) co-ord))
(command "trim" ent3 "" "F" co-ord "" "")
(setq ss (ssget "CP" co-ord (list (cons 8  "Waffle"))))
(entdel ent3)
(entdel ent4)
(command "chprop" ss "" "LA" "Waffledummy" "")
(command "layuniso")
(command "layiso" ent2 "")
(command "erase" "W" (getvar 'extmin)(getvar 'extmax) "")
(command "layuniso")
(command "chprop" ss "" "LA" "Waffle" "")
(setq ss (ssget "CP" co-ord (list (cons 8  "Waffle"))))
(repeat (setq x (sslength ss))
(setq entg (entget (ssname ss (setq x (1- x)))))
(if (= (cdr (assoc 70 entg)) 0)
(entmod (subst (cons 70 1) (assoc 70 entg) entg))
)
)
(setvar 'clayer oldlay)
(command "-purge" "La" "Waffledummy" "N")
(princ)
)

 ; waffle

Try this I still have to perfect the trimming of the pods but its close, the original code was done like 30 years ago so trying to remember how I did it.

 

SeaHaven_0-1685756473355.png

 

0 Likes