Draw grid line specified intervals and coordinate text place all of side

Draw grid line specified intervals and coordinate text place all of side

Anonymous
Not applicable
3,378 Views
4 Replies
Message 1 of 5

Draw grid line specified intervals and coordinate text place all of side

Anonymous
Not applicable

Help please Draw grid with given grid interval with coordinate text place all of side

 

Thank you

 

(defun dtr (a)
  (* pi (/ a 180.00))
)

(defun gr:err (s)
  (if (/= s "Function cancelled") 
     (princ (strcat "\nError: " s)) 
  )
  (setq *error* olderr) 
  (setvar "cmdecho" cmd)
  (setvar "blipmode" blip)
  (setvar "osmode" osm)
  (setvar "gridmode" g_ant)
  (setvar "snapmode" s_ant)  
  (princ)
)

(defun gr_dat ()
  (cond
    ((/= (getvar "userr1") 0)
     (initget (+ 2 4))
     (if (setq esc (getreal (strcat
			    "\nHorizontal Scale <"
			     (rtos (getvar "userr1") 2)
			     ">: "
			    )
		   )
	 )
       (setvar "userr1" esc)
       (setq esc (getvar "userr1"))
     )
    )
    ((= (getvar "userr1") 0)
     (initget (+ 1 2 4))
     (setq esc (getreal "\nHorizontal Scale: "))
     (setvar "userr1" esc)
    )
  )


  (if esc:v
    (progn
      (setq esc:va esc:v)
      (initget (+ 2 4))
      (if (setq esc:v (getreal (strcat "\nVertical Scale <"                                   
				       (rtos esc:v 2)
				     ">: " 
			       )
		      )
	  )
	()    
	(setq esc:v esc:va)
      )
    )
    (progn
      (initget (+ 2 4))
      (if (setq esc:v (getreal (strcat "\nVertical Scale <"
				       ;(rtos (/ esc 10.00) 2)
				       (rtos esc 2)
				     ">: " 
			       )
		      )
	  )
		   
	()
	(setq esc:v esc)
      )
    )
  )

  (if e:hor
    (progn
      (setq e:hora e:hor)
      (initget (+ 2 4))
      (if (setq e:hor (getint (strcat
			      "\nHorizontal Spacing <"
			      (rtos e:hor 2)
			      ">: "
			      )
		      )
	  )
	()
	(setq e:hor e:hora)
      )
    )
    (progn
      (initget (+ 1 2 4)) 
      (setq e:hor (getint "\nHorizontal Spacing: "))
    )
  )  


  (if e:coord
    (progn
      (setq e:coorda e:coord)
      (initget (+ 2 4))
      (if (setq e:coord (getint (strcat
			    "\nVertical Spacing <"
			    (rtos e:coord 2)
			    ">: "
				 )
			 )
	   )
	()
	(setq e:coord e:coorda)
      )
    )   
    (progn
       (initget (+ 2 4))
       (if (setq e:coord (getint (strcat
			     "\nVertical Spacing <"
			     (rtos e:hor 2)
			     ">: "
				  )
			  )
	  )
	 ()
	 (setq e:coord e:hor)
       )
    )
  )




  
  (setq s_ant (getvar "snapmode"))
  (setq g_ant (getvar "gridmode"))

  (command "snap" "a" e:hor e:coord
	   "grid" "a" e:hor e:coord
  )

  (setvar "blipmode" 1)
  (initget 1)
  (setq pt1 (getpoint "\nLower left corner: "))
  (initget 1)
  (setq pt3 (getcorner pt1 "\nTop right corner: "))
  (setvar "blipmode" 0)

  (setvar "gridmode" g_ant)
  (setvar "snapmode" s_ant)
  (initget (+ 1 2 4))

  (if a:txt 
    (progn
      (setq a:txta a:txt)
      (initget (+ 2 4))
      (if (setq a:txt (getreal (strcat
			    "\nText Height (mm) <"
			    (rtos a:txt 2)
			    ">: "
			       )
		       )
	  )
	()
	(setq a:txt a:txta)
      )
    )
    (progn
      (initget (+ 1 2 4))
      (setq a:txt (getreal "\nText Height (mm): "))
    )
  )


  ;;Verification height of text and existing Style
  ;;existing :

  (if (tblsearch "style" "ROMANS")
    (progn
      (setq a:act (cdr (assoc 40 (tblsearch "style" "ROMANS"))))
      (if (/= a:act 0)
	(progn
	  (setq rgm (getvar "regenmode"))
	  (command "style" "ROMANS" "romans" "0.0" "1" "0.0" "n" "n" "n")
	  (prompt "\n*** Text style redefined ROMANS.   ***")
	  (setvar "regenmode" rgm)
	)
      )
    )
    (progn
      (setq rgm (getvar "regenmode"))
      (command "style" "ROMANS" "romans" "0.0" "1" "0.0" "n" "n" "n")
      (prompt "\n***   The text style was created ROMANS.   ***")
      (setvar "regenmode" rgm)
    )
  )

;; Missing obtaining coordinates for the other points
;; the rectangle:

  (setq pt2 (list (car pt3) (cadr pt1)))
  (setq pt4 (list (car pt1) (cadr pt3)))

  ;;Preparation of layers:
  (command "layer" "m" "GRID-LINE" "c" "253" "GRID-LINE" ""
	   "layer" "m" "GRID-TEXT" "c" "7" "GRID-TEXT" ""
  )

)

;;Function gr_dib to draw the grid and texts :
(defun gr_dib  ()
  (command "layer" "m" "GRID-LINE" ""
	   "line" pt1 (polar pt1 (dtr 0.00)  
		  (* (fix (/ (distance pt1 pt2) e:hor)) e:hor)) ""

	   "array" "l" "" "r" (setq txt:h (+ (fix (/ (distance pt1 pt4) e:coord)) 1))
		   "1" e:coord

	   "line" pt1  (polar pt1 (dtr  90.00)
		  (* (fix (/ (distance pt1 pt4) e:coord)) e:coord)) ""

	   "array" "l" "" "r" "1" (setq txt:v (+ (fix (/ (distance pt1 pt2) e:hor)) 1))
		   e:hor
  )

  ;;Drawing indications Support (Axis y):
 (setq c:y (cadr pt1))
 (setq c:x (- (car pt1) (* 0.01 esc)))

  (command "layer" "m" "GRID-TEXT" "")


  (repeat txt:h ;; txt:h is the number of rows for the rectangular array.
    (setq p:ins (list c:x c:y))
    (command "textstyle" "ROMANS"
	     "text" "BL" p:ins (* esc (/ a:txt 1000.00)) "0" (strcat  "N" (itoa (fix (/ c:y (/ esc esc:v)))))
    )
    (setq c:y (+ c:y e:coord))
  )

  ;;Drawing indications Support (Axis x):

  ;;(setq c:y (- (cadr pt1) (* 0.0125 esc)))
  (setq c:y (- (cadr pt1) (* 0.01 esc)))
  (setq c:x (car pt1))

  (command "layer" "m" "GRID-TEXT" "")

  (repeat txt:v
    (setq p:ins (list c:x c:y))
    (command "textstyle" "ROMANS"
	     "text" "BL" p:ins (* esc (/ a:txt 1000.00)) "90" (strcat  "E" (itoa (fix c:x) ) )
    )

    (setq c:x (+ c:x e:hor))
  )
)
;;Funcion principal:
(defun c:DRAW_GRID (/ cmd rgm blip  pt1 pt2   pt3   pt4
		   a:text  e:act a:act   esc txt:h txt:v c:x
		   c:y     p:ins s_ant   g_ant     esc:va
		   e:hora  e:coorda      a:txta
		)
  ;(setq olderr  *error* 
;        *error* gr:err
;  )
  (setq cmd (getvar "cmdecho"))
  (setq blip (getvar "blipmode"))
  (setvar "cmdecho" 0)
  (setvar "blipmode" 0)
  (gr_dat)
  (gr_dib)
  (setvar "cmdecho" cmd)
  (setvar "blipmode" blip)
  (princ)
)
;;===================================================================
(prompt "\nType Command DRAW_GRID ")
(princ)
0 Likes
3,379 Views
4 Replies
Replies (4)
Message 2 of 5

jonnyrobson
Observer
Observer
Is this a working lisp?
Thanks
0 Likes
Message 3 of 5

vladimir_michl
Advisor
Advisor

Does the attached LISP code do what you need or do you need something different? See also DrGrid for rectangular (2D/3D) and polar grids:

http://www.cadforum.cz/cadforum_en/drgrid-parametric-grid-for-autocad-drawings-tip9829

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

0 Likes
Message 4 of 5

jonnyrobson
Observer
Observer

So I did acquire a few LISP's from online but none of them seem to do exactly what I am looking for.

 

LISPs are new to me and I am slowly learning how to write them.

 

To try increase workflow I am looking for a co-ordinate grid to be drawn with northings and eastings - like this:

 

 http://www.autocadproblems.com/2015/11/lisp-to-draw-grid-lines-with-northing.html?m=1

 

but I would like the E's and N's to be active so that if the grid is moved then the E's and N's update when I regen the drawing.

 

Do you think this is possible?

 

Many thanks,

 

0 Likes
Message 5 of 5

jonnyrobson
Observer
Observer

Found a solution here:

 

https://forums.autodesk.com/t5/autocad-civil-3d-forum/northing-easting-grid-lines/td-p/2777466

 

I'm using civil 3D and didn't know about mapreferencesystem command!

0 Likes