Make a UTM Grid LISP inside closed polyline (model space)

Make a UTM Grid LISP inside closed polyline (model space)

Anonymous
Not applicable
2,295 Views
7 Replies
Message 1 of 8

Make a UTM Grid LISP inside closed polyline (model space)

Anonymous
Not applicable

Hi guys. Good evening! (posting time)

I'm pretty used by now to use the georef-grid-maker that is native in layout toolbar at Map 3D. Once I insert it at the paper space, I do a little editing on my own (rotate the texts, copy and paste to put them in more intersections of the grid rather than just at the edges... Simple things).

But somethings changed in the working process and now I have to do it quicker, and a lot more, than I was used to (and also, in model space).
Native grid-maker won't do anymore. So I did my research and found some pretty good stuff... Paid stuff.
I was ready to ask for my bosses to do the paying for at least 3 users here but I know that it will get nowhere. I'm using this one here: https://tbn2net.com/MLH2?lang=en-us
I will probably buy one license from here, since I do like to support other people's work, but I need a alternative.

Would you guys, perhaps, have one lisp nearly identical in your pocket? I really need to share with my coworkers - before I become the utmgridman at the office.

And a little bit of the usual stretch:
The ones I found so far creates the mtexts/texts only at the edge of each segment. As in the image bellow:

 

(being used)(being used)

 

It would be perfect beyond imagination if the lisp find a way to put these texts in every intersection of the grid, as bellow (today, I do the copy & paste manually):

 

(after I edit)(after I edit)

 

Well, that's it.
Thanks for reading!

I will appreciate any kind of direction you guys can give! 

0 Likes
Accepted solutions (1)
2,296 Views
7 Replies
Replies (7)
Message 2 of 8

Sea-Haven
Mentor
Mentor

Dont see any real problem making a grid if you just window a box it will give lower left upper right co ords so just need a question about grid spacing and start & finish co-ords. Say a confirm then draw. Can draw a rectang 1st confirm ok then do grid or else change co-ords

 

There is heaps of grid stuff out there in lisp.

 

so 

(setq pt1 (getpoint "Pick lower left"))
(setq pt2 (getpoint pt1 "pick upper right"))
(setq lx (rtos (car pt1) 2 0))
(setq ly (rtos (cadr pt1) 2 0))
(setq rx (rtos (car pt1) 2 0))
(setq ry (rtos (cadr pt2) 2 0))

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Enter grid co-ords" "Left X" 8 7 lx "Left Y" 8 7 ly "Right X" 8 7 rx "Right Y" 8 7 ry "Spacing" 5 4 "500")))
 
See image
 
Message 3 of 8

Anonymous
Not applicable

Thanks for the reply, sea.haven!

Although I'm not certain I got what you mean.
I'm not a native to the language, so perhaps I'm having a little bit of a hard time understanding your reply.
Would you elaborate a little more? Please? 😄

0 Likes
Message 4 of 8

Sea-Haven
Mentor
Mentor

If you google for GRID LISP you will find plenty of versions of creating a grid you should be able to find one that lables the way you want. They all tend to work from a lower left corner, grid spacing and how many grids. The idea of the dcl is to supply a suitable lisp with the range required.

 

Will try to find something but you look as well.

 

This is an old one I had and needs to be rewritten to match new input form.

 

(setq pt1 (getpoint "Pick 1st point cnr"))
(setq x1 (car pt1))
(setq y1 (cadr pt1))
(setq x 1)
(setq y 1)
(setq d1 (GETDIST PT1 "2nd point X"))
(setq d2  (getdist PT1 "2ND PT y"))
(SETQ Xmany (GETINT "How many in x direction"))
(setq ymany (getint "How many in Y direction"))
(setq ansx "A00")
(setq ansy "B00")

(repeat ( + ymany 1)
(repeat ( + xmany 1)
(setq  pt (list x1 y1))
(command "text" pt "1" "" (strcat ansx (rtos x 2 0) ansy (rtos  y  2 0)))
(setq x1 (+ x1 d1))
(setq  x (+  x 1))
)
(setq   x 1)
(setq  x1(car pt1))
(setq  y1 (+ y1 d2))
(setq Y (+ y 1))
)
0 Likes
Message 5 of 8

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Hi,

Try this!

 

(vl-load-com)
(defun des_vec (lst col / lst_sg)
	(setq lst_sg (list (cadr lst) (car lst)))
	(setq lst (cdr lst))
	(while lst
		(if (cadr lst)
			(setq lst_sg (cons (cadr lst) (cons (car lst) lst_sg)))
			(setq lst_sg (cons (last lst_sg) (cons (car lst) lst_sg)))
		)
		(setq lst (cdr lst))
	)
	(setq lst_sg (cons col lst_sg))
	(grvecs lst_sg)
)
(defun l-coor2l-pt (lst flag / )
	(if lst
		(cons (list (car lst) (cadr lst) (if flag (caddr lst) 0.0))
			(l-coor2l-pt (if flag (cdddr lst) (cddr lst)) flag)
		)
	)
)
(defun remove_doubles (lst)
	(cond
		((null lst) nil)
		(T
			(cons (car lst) (remove_doubles (vl-remove (car lst) lst)))
		)
	)
)
(defun c:DIM-GRID ( / unit_draw AcDoc Space UCS save_ucs WCS dx_u hview old_snapang pt_ins dx dy pt_tmp ang l_scale format_scale coeff
                      key pt_key n nb_column nb_raw pt_row count s_ang nw_style f_pat nw_pl ech htx hatch lst_pt str_x ori_txt_x str_y ori_txt_y nw_txt)
	(if (or (eq (getvar "USERS5") "") (not (eq (substr (getvar "USERS5") 1 2) "qz")))
		(setvar "USERS5" (strcat "qz" (itoa (setq unit_draw 1000))))
		(setq unit_draw (atoi (substr (getvar "USERS5") 3)))
	)
	(setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
	(vla-StartUndoMark AcDoc)
	(setq
		Space
		(if (eq (getvar "CVPORT") 1)
			(vla-get-PaperSpace AcDoc)
			(vla-get-ModelSpace AcDoc)
		)
		UCS (vla-get-UserCoordinateSystems AcDoc)
		save_ucs
		(vla-add UCS
			(vlax-3d-point '(0.0 0.0 0.0))
			(vlax-3d-point (getvar "UCSXDIR"))
			(vlax-3d-point (getvar "UCSYDIR"))
			"CURRENT_UCS"
		)
	)
	(vla-put-Origin save_ucs (vlax-3d-point (getvar "UCSORG")))
	(setq WCS (vla-add UCS (vlax-3d-Point '(0.0 0.0 0.0)) (vlax-3d-Point '(1.0 0.0 0.0)) (vlax-3d-Point '(0.0 1.0 0.0)) "TEMP_WCS"))
	(vla-put-activeUCS AcDoc WCS)
	(initget 6)
	(setq dx_u (getreal "\nDistance in millimeter of your template iso <210.0>: "))
	(if (not dx_u) (setq dx_u 210.0))
	(setq
		hview (getvar "VIEWSIZE")
		old_snapang (getvar "SNAPANG")
		pt_ins (list (- (car (getvar "VIEWCTR")) (* hview 0.5)) (- (cadr (getvar "VIEWCTR")) (* hview 0.5)))
		dx dx_u dy (* dx_u (sqrt 2)) pt_tmp pt_ins ang (getvar "SNAPANG")
		l_scale '(1.0 1.25 2.0 2.5 5.0 7.5)
		format_scale (car l_scale)
		coeff 1.0
	)
	(if (> (fix (/ hview dy)) 3)
		(while (> (fix (/ hview dy)) 3)
			(foreach value l_scale
				(if (> (fix (/ hview dy)) 3)
					(setq format_scale value dx (* dx_u format_scale) dy (* dx_u (sqrt 2) format_scale))
				)
			)
			(if (> (fix (/ hview dy)) 3)
				(setq
					coeff (* coeff 10.0)
					l_scale (mapcar '(lambda (x) (* x coeff)) l_scale)
					format_scale (car l_scale)
				)
			)
		)
	)
	(if (< (fix (/ hview dy)) 1)
		(while (< (fix (/ hview dy)) 1)
			(foreach value (reverse l_scale)
				(if (< (fix (/ hview dy)) 1)
					(setq format_scale value dx (* dx_u format_scale) dy (* dx_u (sqrt 2) format_scale))
				)
			)
			(if (< (fix (/ hview dy)) 1)
				(setq
					coeff (* coeff 0.1)
					l_scale (mapcar '(lambda (x) (* x coeff)) l_scale)
					format_scale (last l_scale)
				)
			)
		)
	)
	(princ (strcat "\nSpecify top rigth corner or: [P] for new Position of bottom left corner,[R] for make Rotate, [+/-] change scale <" (rtos (* unit_draw format_scale) 2 3) ">: "))
	(while (and (setq key (grread T 4 0)) (/= (car key) 3))
		(cond
			((eq (car key) 5)
				(setq pt_key (cadr key))
				(setq n
					(*
						(setq nb_column (fix (/ (+ (* (- (car pt_key) (car pt_ins)) (cos ang)) (* (- (cadr pt_key) (cadr pt_ins)) (sin ang))) dx)))
						(setq nb_raw (fix (/ (- (* (- (cadr pt_key) (cadr pt_ins)) (cos ang)) (* (- (car pt_key) (car pt_ins)) (sin ang))) dy)))
					)
					pt_row pt_ins count 0
				)
				(redraw)
				(repeat n
					(des_vec
						(list
							(list (car pt_ins) (cadr pt_ins))
							(list (+ (car pt_ins) (* dx (cos ang))) (+ (cadr pt_ins) (* dx (sin ang))))
							(setvar "LASTPOINT"
								(list
									(+ (car pt_ins) (- (* dx (cos ang)) (* dy (sin ang))))
									(+ (cadr pt_ins) (+ (* dy (cos ang)) (* dx (sin ang))))
								)
							)
							(list (- (car pt_ins) (* dy (sin ang))) (+ (cadr pt_ins) (* dy (cos ang))))
						)
						3
					)
					(setq count (1+ count))
					(if (< count nb_column)
						(setq pt_ins (list (+ (car pt_ins) (* dx (cos ang))) (+ (cadr pt_ins) (* dx (sin ang)))))
						(setq pt_ins (list (- (car pt_row) (* dy (sin ang))) (+ (cadr pt_row) (* dy (cos ang)))) pt_row pt_ins count 0)
					)
				)
				(setq pt_ins pt_tmp)
			)
			((or (eq (cadr key) 114) (eq (cadr key) 82))
				(initget 0)
				(setq s_ang
					(getorient pt_ins
						(strcat
							"\nNew angle<"
							(angtos (getvar "SNAPANG"))
							">: "
						)
					)
				)
				(if (not s_ang) (setq s_ang ang))
				(if (and (> s_ang (/ pi 2)) (<= s_ang (/ (* 3 pi) 2)))
					(setq ang (+ s_ang pi))
					(setq ang s_ang)
				)
				(setvar "SNAPANG" ang)
				(princ (strcat "\nSpecify top rigth corner or: [P] for new Position of bottom left corner,[R] for make Rotate, [+/-] change scale <" (rtos (* unit_draw format_scale) 2 3) ">: "))
			)
			((or (eq (cadr key) 112) (eq (cadr key) 80))
				(initget 9)
				(setq pt_ins (getpoint "\nSpecify down left corner: "))
				(setq pt_ins (list (car pt_ins) (cadr pt_ins)) pt_tmp pt_ins)
				(princ (strcat "\nSpecify top rigth corner or: [P] for new Position of bottom left corner,[R] for make Rotate, [+/-] change scale <" (rtos (* unit_draw format_scale) 2 3) ">: "))
			)
			((eq (cadr key) 43)
				(setq format_scale (cadr (member format_scale l_scale)))
				(if (not format_scale) (setq format_scale (car (setq l_scale (mapcar '(lambda (x) (* x 10.0)) l_scale)))))
				(setq dx (* dx_u format_scale) dy (* dx_u (sqrt 2) format_scale))
				(princ (strcat "\nSpecify top rigth corner or: [P] for new Position of bottom left corner,[R] for make Rotate, [+/-] change scale <" (rtos (* unit_draw format_scale) 2 3) ">: "))
			)
			((eq (cadr key) 45)
				(setq format_scale (cadr (member format_scale (reverse l_scale))))
				(if (not format_scale) (setq format_scale (last (setq l_scale (mapcar '(lambda (x) (* x 0.1)) l_scale)))))
				(setq dx (* dx_u format_scale) dy (* dx_u (sqrt 2) format_scale))
				(princ (strcat "\nSpecify top rigth corner or: [P] for new Position of bottom left corner,[R] for make Rotate, [+/-] change scale <" (rtos (* unit_draw format_scale) 2 3) ">: "))
			)
		)
	)
	(princ "\n")
	(redraw)
	(if (not (tblsearch "STYLE" "$DIM-GRID"))
		(progn
			(setq nw_style (vla-add (vla-get-textstyles AcDoc) "$DIM-GRID"))
			(mapcar
				'(lambda (pr val)
					(vlax-put nw_style pr val)
				)
				(list 'FontFile 'Height 'ObliqueAngle 'Width 'TextGenerationFlag)
				(list "SIMPLEX.SHX" 0.0 0.0 1.0 0.0)
			)
		)
  )
	(if (not (tblsearch "LAYER" "DIM-GRID"))
		(vlax-put (vla-add (vla-get-layers AcDoc) "DIM-GRID") 'color 7)
	)
	(if (not (findfile "REPQUADISO.pat"))
		(progn
			(setq f_pat (open (strcat (getvar "ROAMABLEROOTPREFIX") "support\\REPQUADISO.pat") "w"))
			(write-line "*REPQUADISO,Repere du quadrillage lambert" f_pat)
			(write-line "0, 0,0, 0,1" f_pat)
			(write-line "90, 0,0, 0,1" f_pat)
			(close f_pat)
		)
	)
	(setq
		nw_pl
		(vlax-invoke Space 'AddLightWeightPolyline
			(append
				pt_ins
				(polar pt_ins (+ (getvar "SNAPANG") (* pi 0.5)) (* (distance pt_ins (getvar "LASTPOINT")) (sin (- (angle pt_ins (getvar "LASTPOINT")) (getvar "SNAPANG")))))
				
				(list (car (getvar "LASTPOINT")) (cadr (getvar "LASTPOINT")))
				(polar pt_ins (getvar "SNAPANG") (* (distance pt_ins (getvar "LASTPOINT")) (cos (- (angle pt_ins (getvar "LASTPOINT")) (getvar "SNAPANG")))))
			)
		)
		ech (* unit_draw format_scale)
		htx (/ ech 500.0)
	)
	(vla-put-Closed nw_pl 1)
	(vla-put-layer nw_pl "DIM-GRID")
	(setvar "HPORIGINMODE" 0)
	(setvar "HPORIGIN" '(0.0 0.0))
	(setq hatch (vla-AddHatch Space acHatchPatternTypeCustomDefined "REPQUADISO" :vlax-True))
	(vlax-invoke hatch 'AppendOuterLoop (list nw_pl))
	(vla-put-patternscale hatch (/ ech 10.0))
	(vla-put-patternangle hatch 0.0)
	(vla-put-layer hatch "DIM-GRID")
	(vla-evaluate hatch)
	(setq lst_pt
		(l-coor2l-pt
			(vlax-invoke
				hatch
				'IntersectWith
				hatch
				acExtendThisEntity
			)
			T
		)
	)
	(setq lst_pt (remove_doubles lst_pt))
	(foreach el lst_pt
		(setq str_x (strcat " E=" (rtos (car el) 2 0) " ") ori_txt_x (* 3 pi 0.5))
		(setq str_y (strcat " N=" (rtos (cadr el) 2 0) " ") ori_txt_y 0.0)
		(mapcar
		 '(lambda (x / )
				(setq nw_txt (vla-AddText Space (car x) (vlax-3d-point el) htx))
				(vla-put-layer nw_txt "DIM-GRID")
				(vla-put-StyleName nw_txt "$DIM-GRID")
				(vla-put-Alignment nw_txt acAlignmentBottomLeft)
				(vla-put-Rotation nw_txt (cdr x))
				(vla-put-TextAlignmentPoint nw_txt (vlax-3d-point el))
				(if (vlax-invoke nw_pl 'IntersectWith nw_txt acExtendThisEntity)
					(vla-put-Alignment nw_txt acAlignmentBottomRight)
				)
			)
			(list (cons str_x ori_txt_x) (cons str_y ori_txt_y))
		)
	)
	(setq pt_ins (polar pt_ins (+ (* pi 0.25) (getvar "SNAPANG")) (* htx 10)))
	(setq nw_txt (vla-AddText Space (strcat " Scale 1/" (rtos ech 2 0)) (vlax-3d-point pt_ins) (* 2 htx)))
	(vla-put-layer nw_txt "DIM-GRID")
	(vla-put-StyleName nw_txt "$DIM-GRID")
	(vla-put-Alignment nw_txt acAlignmentMiddleLeft)
	(vla-put-Rotation nw_txt (getvar "SNAPANG"))
	(vla-put-TextAlignmentPoint nw_txt (vlax-3d-point pt_ins))
	(and save_ucs (vla-put-activeUCS AcDoc save_ucs))
	(and WCS (vla-delete WCS) (setq WCS nil))
	(vla-EndUndoMark AcDoc)
	(setvar "SNAPANG" old_snapang)
	(prin1)
)

 

 

Message 6 of 8

Anonymous
Not applicable

That's it.

Jesus.

Amazing ❤️

Thanks A LOT for this. My coworkers will be happier thx to you.

0 Likes
Message 7 of 8

Sea-Haven
Mentor
Mentor

Just a suggestion use NET its a Autocad hatch pattern rather than "REPQUADISO.pat"

0 Likes
Message 8 of 8

CADaSchtroumpf
Advisor
Advisor

Yes I could have used NET as a template, although it was a little less easy, but feasible for different scales.
And then this program comes from another version or I use another model (which looks like CROSS, but not offset)
So the adaptation of this code explains that.

0 Likes