Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Coordinate Grid

10 REPLIES 10
Reply
Message 1 of 11
brandzo
2098 Views, 10 Replies

Coordinate Grid

Hello everybody,

I'm trying to make a lisp which will draw a grid of lines at certain offset inside the rectangle and to label every line with its Y value (for horizontal lines) and X value (for vertical lines) at the endpoints. By now, I managed to do that with only "orthogonal" rectangles, not with rotated ones. Any kind of help would be greatly appreciated.

Thanks in advance!

Brandzo
10 REPLIES 10
Message 2 of 11
Hallex
in reply to: brandzo

This will get you started
Sorry I haven't a time to rewrite it
to your suit
{code}
(defun C:GB (/ cnt deltax deltay dis lddx lddy ldx
ldy maxx maxy pnt1 pnt2 pnt3 stepx stepy)


(setq pnt1 '(0. 0. 0.)) ;<--lower left point
(setvar "orthomode" 1)
(setq maxx (getdist "\nLength by \"Õ\" axis : ")
maxy (getdist "\nLength by \"Y\" axis : ")
stepx (getreal "\nStep by \"Õ\" axis : ")
stepy (getreal "\nStep by \"Y\" axis : ")
deltax (/ stepx 10)
deltay (/ stepy 10))
(setq pnt2 (list maxx (cadr pnt1) (caddr pnt1))
pnt3 (list (car pnt2) maxy (caddr pnt2)))
(command "zoom" "w" pnt1 pnt3)
(command "zoom" ".9x")
(entmake
(list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(62 . 3)
'(90 . 4)
'(70 . 1)
(cons 10 pnt1)
(list 10 (car pnt3) (cadr pnt1) (caddr pnt1))
(cons 10 pnt3)
(list 10 (car pnt1) (cadr pnt3) (caddr pnt1))
(cons 43 1.)
)
)

(setq ldx (list pnt1))
(setq cnt 1)
(while (<= (setq dis (* cnt stepx)) maxx)
(setq ldx (cons (list dis (cadr pnt1)) ldx))
(setq cnt (1+ cnt)))
(setq ldx (reverse ldx))

(setq lddx '())
(setq cnt 1)
(while (<= (setq dis (* cnt deltax)) maxx)
(setq lddx (cons (list dis (cadr pnt1)) lddx))
(setq cnt (1+ cnt)))
(setq lddx
(vl-remove-if
(function (lambda (x)
(member x ldx)))
(reverse lddx)))

(setq ldy (list pnt1))
(setq cnt 1)
(while (<= (setq dis (* cnt stepy)) maxy)
(setq ldy (cons (list (car pnt1) dis) ldy))
(setq cnt (1+ cnt)))
(setq ldy (reverse ldy))

(setq lddy '())
(setq cnt 1)
(while (<= (setq dis (* cnt deltay)) maxy)
(setq lddy (cons (list (car pnt1) dis) lddy))
(setq cnt (1+ cnt)))
(setq lddy
(vl-remove-if
(function (lambda (x)
(member x ldy)))
(reverse lddy)))
(setvar "cecolor" "5")
(foreach p ldx

(entmake (list (cons 0 "LINE")
(cons 10 p)
(cons 11 (polar p (* pi 1.5) 20.))))

(entmake
(list
'(0 . "TEXT")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
'(62 . 1)
'(71 . 0)
'(72 . 0)
'(73 . 0)
(cons 1 (rtos (car p) 2 2))
(cons 7 "Standard") ;<--textstyle
(cons 8 "0")
(cons 10 (polar p (* pi 1.5) 25.))
(cons 11 (polar p (* pi 1.5) 25.))
(cons 40 2.) ;text height
(cons 41 0.8) ;text width
(cons 50 (/ pi 2)) ;vertical, 0 - horizontal
(cons 51 0.0)))
)
(setvar "cecolor" "2")
(foreach p lddx
(entmake (list (cons 0 "LINE")
(cons 10 p)
(cons 11 (polar p (* pi 1.5) 10.))))
)
(setvar "cecolor" "5")
(foreach p ldy
(entmake (list (cons 0 "LINE")
(cons 10 p)
(cons 11 (polar p pi 20.))))

(entmake
(list
'(0 . "TEXT")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
'(62 . 1)
'(71 . 0)
'(72 . 2)
'(73 . 2)
(cons 1 (rtos (cadr p) 2 2))
(cons 7 "Standard") ;<--textstyle
(cons 8 "0")
(cons 10 (polar p pi 25.))
(cons 11 (polar p pi 25.))
(cons 40 2.) ;text height
(cons 41 0.8) ;text width
(cons 50 0.0) ;horizontal
(cons 51 0.0)))
)
(setvar "cecolor" "2")
(foreach p lddy
(command "line" p (polar p pi 10.) "")
(entmake (list (cons 0 "LINE")
(cons 10 p)
(cons 11 (polar p pi 10.)))))
(setvar "cecolor" "8")
(foreach p ldx
(command "line" p (polar p (* pi 0.5) maxy) "")
)
(foreach p ldy
(command "line" p (polar p 0 maxx) "")
)


(setvar "plinewid" 0.0)
(setvar "cecolor" "bylayer")
(princ)
)
(princ "\n >>> Type GB to draw grid")
(prin1)
{code}

~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 11
Kent1Cooper
in reply to: brandzo

Not seeing your version that does orthogonal rectangles, it's hard to say for sure, but:

I expect you could get by with doing little more than changing the UCS to align with a non-orthogonal rectangle, and adding some (trans) functions to convert X and Y values and perhaps text insertion points to the new UCS.

--
Kent Cooper
Kent Cooper, AIA
Message 4 of 11
brandzo
in reply to: brandzo

Actually, this is what I'm trying to achieve (see attached dwg). Based on given rectangle (regardless of its rotation) to draw the grid of lines and label every endpoint of line with coordinates. I hope this is a bit clearer.

Thank you in advance!

Brandzo
Message 5 of 11
brandzo
in reply to: brandzo

Actually, this is what I'm trying to achieve (see attached dwg). Based on given rectangle (regardless of its rotation) to draw the grid of lines and label every endpoint of line with coordinates. I hope this is a bit clearer.

Thank you in advance!

Brandzo
Message 6 of 11
cab2k
in reply to: brandzo

No Drawing attached!
Message 7 of 11
brandzo
in reply to: brandzo

Here's the drawing, sorry...

Edited by: brandzo on Dec 12, 2009 6:20 AM Edited by: brandzo on Dec 12, 2009 6:21 AM
Message 8 of 11
Hallex
in reply to: brandzo

Good joke, thanks

~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 9 of 11
brandzo
in reply to: brandzo

Don't know why the dwg is not attached... 😞
Message 10 of 11
bsaikmr
in reply to: brandzo

dear sir,
hai
Message 11 of 11
bsaikmr
in reply to: brandzo

 
Tags (1)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost