You have done the first step already:
1) Determine what you need to construct the grid;
2) Determine what information (variables) you want the user to input.
For your grid you need an origin and horizontal and vertical lines at some spacing, all of which your user will specify. These values need to be stored in memory so that you can recall them for your line endpoint calculations.
Your program needs to be entirely contained in a (DEFUN <command name> ( / ) ...) statement.
The origin can be queried and stored using (SETQ origin_pt (GETPOINT "\nPick the origin: "))
The horizontal grid line spacing is the Y-distance desired between successive horizontal lines. This can be queried using:
(SETQ Y-spacing (GETREAL "\nVertical spacing between horizontal lines: "))
The number of horizontal lines can be queried using: (SETQ horiz# (GETINT "\nNumber of horizontal lines: "))
The vertical grid line spacing can be done similarly:
(SETQ X-spacing (GETREAL "\nHorizontal spacing between vertical lines: "))
The number of vertical lines can be queried using: (SETQ vert# (GETINT "\nNumber of vertical lines: "))
Likewise, the elevation of the bottom horizontal line can be queried using: (SETQ base-elev (GETINT "\nBase grid elevation: ")); and
the starting station of the left vertical grid line can be queried using: (SETQ start-sta (GETINT "\nFirst station: "))
With the collected information you can calculate the horizontal and vertical line endpoints and the text insertion points.
If your grid should have a vertical scale exaggeration then you will need to query this too.
As a beginner, you can easily use the (COMMAND ...) function to draw the lines and text since you are already familiar with the LINE and TEXT commands; however, A better method is to use (ENTMAKE ...) to create them as @john.uhden mentioned.
The above put inside a (DEFUN ...) statement:
(DEFUN c:mygrid ( / )
(SETQ origin_pt (GETPOINT "\nPick the origin: "))
(SETQ Y-spacing (GETREAL "\nVertical spacing between horizontal lines: "))
(SETQ horiz# (GETINT "\nNumber of horizontal lines: "))
(SETQ X-spacing (GETREAL "\nHorizontal spacing between vertical lines: "))
(SETQ vert# (GETINT "\nNumber of vertical lines: "))
(SETQ base-elev (GETINT "\nBase grid elevation: "))
(SETQ start-sta (GETINT "\nFirst station: "))
(SETQ end1 origin_pt end2 (POLAR end1 0.0 (* (1- vert#) X-spacing)))
(REPEAT horiz#
(COMMAND "._LINE" "non" end1 "non" end2 "")
(SETQ txt-pt (POLAR end1 PI (* X-spacing 0.25)))
(COMMAND "._TEXT" "j" "mc" "non" txt-pt "0.1" 0.0 (RTOS base-elev 2 0));Use RTOS here to handle calculated values that are not integers
; Text height is hard coded 0.1 here. May need to calculate text height to fit user input for grid.
(SETQ base-elev (+ base-elev Y-spacing))
(SETQ end1 (POLAR end1 (* PI 0.5) Y-spacing) end2 (POLAR end1 0.0 (* (1- vert#) X-spacing)))
)
(SETQ end1 origin_pt end2 (POLAR end1 (* PI 0.5) (* (1- horiz#) Y-spacing)))
(REPEAT vert#
(COMMAND "._LINE" "non" end1 "non" end2 "")
(SETQ txt-pt (POLAR end1 (* PI 1.5) (* Y-spacing 0.25)))
(COMMAND "._TEXT" "j" "mc" "non" txt-pt "0.1" 0.0 (RTOS start-sta 2 0));Use RTOS here to handle calculated values that are not integers
; Text height is hard coded 0.1 here. May need to calculate text height to fit user input for grid.
(SETQ start-sta (+ start-sta X-spacing))
(SETQ end1 (POLAR end1 0.0 X-spacing) end2 (POLAR end1 (* PI 0.5) (* (1- horiz#) Y-spacing)))
)
(PRINC)
)
Remaining issues are: appropriate text height; formatting Station text; Layering; Major label text for horizontal and vertical, etc.
AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
8.6.52.0 AutoCAD Architecture 2024