+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Forum Newbie
    Using
    AutoCAD 2004
    Join Date
    Dec 2005
    Location
    Germany (orig. Australia)
    Posts
    5

    Default Help please....first Lisp code I've tried to write!

    Registered forum members do not see this ad.

    I'm trying to create a command that will draw a grid reference down the side and across the top (or all sides) of a drawing.

    Something like this:



    Close up of one corner:



    I would like the small grid reference numbers (ie. 569,000) to relate dynamically to the x-y coordinates within the dwg, so that no matter where it is drawn, or even it is moved later, the numbers will automatically display the corresponding coordinates.

    This can then be drawn around survey plans to provide a handy grid reference for objects that have not been given an exact survey location.

    My idea is to get the user to input a scale (which will be the same as the scale used for zooming thru the viewport later on), a spacing (in metres) for the grid spacing, and pick two points (for each end of the grid reference line). Using these values, the command will automatically draw all the lines and text in the appropriate scale down the side (or across the top) of the page.

    The main problems I have at the moment are:
    1. Making the ends of the line which runs parallel with the edge of the page (the dashed line) snap immediately to the closest coordinate with a whole number (ie. if the first point picked has x = 569.234, it will snap to x = 569.000)

    2. Making polar tracking function to help pick the points in a vert. or horiz. direction

    I have started writing the routine, but I'm learning out of a book and have got an embarrassingly small amount to show for my efforts. I have done a test run of the code below, but it gives an error when I load it into the drawing.

    My grasp of Autolisp is tragic at best, so any help at all would be greatly appreciated!

    Code:
    (defun C:DYC (/ sc sp pt1 pt2)
    	(setq sc (getint "Enter scale: "))
    
    	(setq sp (getint "Enter grid spacing: "))
    
    	(setq pt1 (getpoint "Pick first point: "))
    		(setq pt1 (/ (car pt1) sc) (/ (cadr (pt1)) sc))
    		(setq pt1 (fix (car pt1)) (fix (cadr (pt1)))
    		(setq pt1 (* (car pt1) sc) (* (cadr (pt1))))
    	
    	(setq pt2 (getpoint "Pick second point: "))
    		(setq pt2 (/ (car pt2) sc) (/ (cadr (pt2)) sc))
    		(setq pt2 (fix (car pt2)) (fix (cadr (pt2)))
    		(setq pt2 (* (car pt2) sc) (* (cadr (pt2))))
    
    	(command "line" pt1 pt2 "")
    )
    Think I need to study more of the book first.....

  2. #2
    Luminous Being dbroada's Avatar
    Computer Details
    dbroada's Computer Details
    Operating System:
    XP Pro
    Computer:
    Dell
    CPU:
    Intel Xeon 2.13GHz
    RAM:
    2GB
    Graphics:
    NVIDA Quadro FX 580
    Monitor:
    DELL 23" & SAMSUNG 21"
    Discipline
    Electro/Mech
    dbroada's Discipline Details
    Occupation
    Design Engineer
    Discipline
    Electro/Mech
    Using
    Electrical 2013
    Join Date
    Nov 2005
    Location
    Sussex, UK
    Posts
    5,059

    Default

    you certainly have an error in the line
    Code:
    (setq pt1 (/ (car pt1) sc) (/ (cadr (pt1)) sc))
    I'm no longer quick with LISP. I can see what you are trying to do but can't see how to change it. I think you need a couple more variables such as...
    Code:
    (setq Pt1Scaled (/ (car pt1) sc)) etc
    (setq pt1 ([function to reconstrust variable] Pt1Scaled Pt2Scaled))
    "That's it. It's one thing for a ghost to terrorize my children, but quite another for him to play my Theremin." Homer Simpson

    Dave

  3. #3
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    What you want is indeed doable, just a bit complicated for a first routine.

    I see problems with things like text size, grid spacing, rounding etc.

    Also having it update with a move is very very complicated. -David
    R12 (Dos) - A2K

  4. #4
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    Here's how I'd start just to get the corners and the grid section size

    Code:
    (defun getrect (/ p1 p2)
      (initget 1)
      (setq p1 (getpoint "\n1st Corner:   "))
      (initget 1)
      (setq p2 (getcorner p1 "\n2nd Corner:   "))
      (setq ll (list (min (car p1) (car p2))
                     (min (cadr p1) (cadr p2))
                     (caddr p1))
            ur (list (max (car p1) (car p2))
                     (max (cadr p1) (cadr p2))
                     (caddr p1))
            lr (list (car ur) (cadr ll) (caddr p1))
            ul (list (car ll) (cadr ur) (caddr p1)))
      (prin1))
    
      (getrect)
      (setq xscl (- (car lr) (car ll))
            yscl (- (cadr ur) (cadr lr))
            mscl (max xscl yscl)
            i 0)
      (while (>= mscl (expt 10 i))
             (setq i (1+ i)))
      (setq defs (expt 10 (1- i)))
      (prin1 defs)
      (while (or (not scl)
                 (> scl defs))
             (initget 6)
             &#40;setq scl &#40;getdist &#40;strcat "\nGrid Section Size <" &#40;rtos defs 2&#41; ">&#58;   "&#41;&#41;&#41;
             &#40;and &#40;not scl&#41;
                  &#40;setq scl defs&#41;&#41;&#41;
    -David
    R12 (Dos) - A2K

  5. #5
    Forum Newbie
    Using
    AutoCAD 2004
    Join Date
    Dec 2005
    Location
    Germany (orig. Australia)
    Posts
    5

    Default

    Thanks David,

    It will take me a while to figure out what you have written, but I'll have a go at continuing on with it.

    As you suggested, making it update dynamically is quite difficult, especially for my first code, so I will leave it out for now.

    I haven't even got up to inserting text yet, so I may be way off track, but I thought text size would be relatively easy. Can't you just use the 'Specify height:' option within the 'dtext' command, and multiply it by a figure based on the overall scale initially specified by the user?

    Anyway, thanks again for the help. I really have thrown myself in the deep end with this one. I'll keep plugging away at it, and see how I go.

  6. #6
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    Here is bit different approach. Force ACAD to do the grid work. Tell the operator not mess with the snap settings while the program is running. ( I don't know of a way to disable transaperent stuff )

    Code:
    &#40;defun getrect &#40;/ p1 p2&#41;
      &#40;initget 1&#41;
      &#40;setq p1 &#40;getpoint "\n1st Corner&#58;   "&#41;&#41;
      &#40;initget 1&#41;
      &#40;setq p2 &#40;getcorner p1 "\n2nd Corner&#58;   "&#41;&#41;
      &#40;setq ll &#40;list &#40;min &#40;car p1&#41; &#40;car p2&#41;&#41;
                     &#40;min &#40;cadr p1&#41; &#40;cadr p2&#41;&#41;
                     &#40;caddr p1&#41;&#41;
            ur &#40;list &#40;max &#40;car p1&#41; &#40;car p2&#41;&#41;
                     &#40;max &#40;cadr p1&#41; &#40;cadr p2&#41;&#41;
                     &#40;caddr p1&#41;&#41;
            lr &#40;list &#40;car ur&#41; &#40;cadr ll&#41; &#40;caddr p1&#41;&#41;
            ul &#40;list &#40;car ll&#41; &#40;cadr ur&#41; &#40;caddr p1&#41;&#41;&#41;
      &#40;prin1&#41;&#41;
    
    
      &#40;initget 7&#41;
      &#40;setq scl &#40;getdist "\nGrid Size&#58;   "&#41;&#41;
    
      &#40;setvar "ELEVATION" 0&#41;
      &#40;setvar "THICKNESS" 0&#41;
      &#40;setvar "CECOLOR" "BYLAYER"&#41;
      &#40;setvar "CELTYPE" "BYLAYER"&#41;
      &#40;setvar "SNAPBASE" &#40;list 0 0&#41;&#41;
      &#40;setvar "SNAPUNIT" &#40;list scl scl&#41;&#41;
      &#40;setvar "SNAPMODE" 1&#41;
      &#40;setvar "OSMODE" 0&#41;
    
      &#40;getrect&#41;
    
      &#40;foreach p '&#40;ll lr ul ur&#41;
         &#40;if &#40;or &#40;/= 0 &#40;rem &#40;car &#40;eval p&#41;&#41; scl&#41;&#41;
                 &#40;/= 0 &#40;rem &#40;car &#40;eval p&#41;&#41; scl&#41;&#41;&#41;
             &#40;prong
               &#40;price "\Grid Is Not To The Snap - Abort"&#41;
               &#40;exit&#41;&#41;&#41;&#41;
    
      &#40;setvar "SNAPBASE" &#40;list 0 0&#41;&#41;
      &#40;setvar "SNAPUNIT" &#40;list 1 1&#41;&#41;
      &#40;setvar "SNAPMODE" 1&#41;
      &#40;setvar "OSMODE" 0&#41;
    
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 ll&#41;
                     &#40;cons 11 lr&#41;&#41;&#41;
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 lr&#41;
                     &#40;cons 11 ur&#41;&#41;&#41;
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 ur&#41;
                     &#40;cons 11 ul&#41;&#41;&#41;
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 ul&#41;
                     &#40;cons 11 ll&#41;&#41;&#41;
    
      &#40;setq lx &#40;car ll&#41;
            rx &#40;car lr&#41;
            y &#40;cadr ll&#41;
            i 0&#41;
      &#40;while &#40;<= &#40;+ y &#40;* i scl&#41;&#41; &#40;cadr ul&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                            &#40;cons 10 &#40;list lx &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;- lx &#40;* scl 0.5&#41;&#41; &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                            &#40;cons 10 &#40;list rx &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ rx &#40;* scl 0.5&#41;&#41; &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;&#41;&#41;
             &#40;setq i &#40;1+ i&#41;&#41;&#41;
    
      &#40;setq uy &#40;cadr ul&#41;
            ly &#40;cadr ll&#41;
            x &#40;car ll&#41;
            i 0&#41;
      &#40;while &#40;<= &#40;+ x &#40;* i scl&#41;&#41; &#40;car ur&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                            &#40;cons 10 &#40;list &#40;+ x &#40;* i scl&#41;&#41; &#40;- ly &#40;* scl 0.5&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ x &#40;* i scl&#41;&#41; ly 0&#41;&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                            &#40;cons 10 &#40;list &#40;+ x &#40;* i scl&#41;&#41; &#40;+ uy &#40;* scl 0.5&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ x &#40;* i scl&#41;&#41; uy 0&#41;&#41;&#41;&#41;
             &#40;setq i &#40;1+ i&#41;&#41;&#41;
    I would defintly look into (entmaking) the text. You can specify the justification flags, rotation angles, point values a lot easier IMO.

    I picked the lines to be 50% of the scale. I would start with the text being 5% of it as well. -David
    R12 (Dos) - A2K

  7. #7
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    Not the most robust as far as error trapping and resetting values, but here goes:

    Code:
    ;;;GET GRID SIZE
      &#40;initget 7&#41;
      &#40;setq scl &#40;getdist "\nGrid Size&#58;   "&#41;&#41;
    ;;;SET SYSVARs
      &#40;setvar "ELEVATION" 0&#41;
      &#40;setvar "THICKNESS" 0&#41;
      &#40;setvar "CECOLOR" "BYLAYER"&#41;
      &#40;setvar "CELTYPE" "BYLAYER"&#41;
      &#40;setvar "SNAPBASE" &#40;list 0 0&#41;&#41;
      &#40;setvar "SNAPUNIT" &#40;list scl scl&#41;&#41;
      &#40;setvar "SNAPMODE" 1&#41;
      &#40;setvar "OSMODE" 0&#41;
    
    ;;;GET RECTANGLE
      &#40;initget 1&#41;
      &#40;setq p1 &#40;getpoint "\n1st Corner&#58;   "&#41;&#41;
      &#40;initget 1&#41;
      &#40;setq p2 &#40;getcorner p1 "\n2nd Corner&#58;   "&#41;&#41;
      &#40;setq ll &#40;list &#40;min &#40;car p1&#41; &#40;car p2&#41;&#41;
                     &#40;min &#40;cadr p1&#41; &#40;cadr p2&#41;&#41;
                     &#40;caddr p1&#41;&#41;
            ur &#40;list &#40;max &#40;car p1&#41; &#40;car p2&#41;&#41;
                     &#40;max &#40;cadr p1&#41; &#40;cadr p2&#41;&#41;
                     &#40;caddr p1&#41;&#41;
            lr &#40;list &#40;car ur&#41; &#40;cadr ll&#41; &#40;caddr p1&#41;&#41;
            ul &#40;list &#40;car ll&#41; &#40;cadr ur&#41; &#40;caddr p1&#41;&#41;&#41;
    
      &#40;foreach p '&#40;ll lr ul ur&#41;
         &#40;if &#40;or &#40;/= 0 &#40;rem &#40;car &#40;eval p&#41;&#41; scl&#41;&#41;
                 &#40;/= 0 &#40;rem &#40;car &#40;eval p&#41;&#41; scl&#41;&#41;&#41;
             &#40;prong
               &#40;price "\Grid Is Not To The Snap - Abort"&#41;
               &#40;exit&#41;&#41;&#41;&#41;
    
    ;;RESET SYSVARS
      &#40;setvar "SNAPBASE" &#40;list 0 0&#41;&#41;
      &#40;setvar "SNAPUNIT" &#40;list 1 1&#41;&#41;
      &#40;setvar "SNAPMODE" 1&#41;
      &#40;setvar "OSMODE" 0&#41;
      &#40;setvar "DIMZIN" 0&#41;
    
    ;;;DRAW THE BOX
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 ll&#41;
                     &#40;cons 11 lr&#41;&#41;&#41;
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 lr&#41;
                     &#40;cons 11 ur&#41;&#41;&#41;
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 ur&#41;
                     &#40;cons 11 ul&#41;&#41;&#41;
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 ul&#41;
                     &#40;cons 11 ll&#41;&#41;&#41;
    
    ;;;DRAW AND LABEL THE HORIZONTAL LINES
      &#40;setq lx &#40;car ll&#41;
            rx &#40;car lr&#41;
             y &#40;cadr ll&#41;
             i 0&#41;
      &#40;while &#40;<= &#40;+ y &#40;* i scl&#41;&#41; &#40;cadr ul&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                            &#40;cons 10 &#40;list lx &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;- lx &#40;* scl 0.5&#41;&#41; &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "TEXT"&#41;
                            &#40;cons 1 &#40;rtos &#40;+ y &#40;* i scl&#41;&#41; 2&#41;&#41;
                            &#40;cons 7 &#40;getvar "TEXTSTYLE"&#41;&#41;
                            &#40;cons 40 &#40;* scl 0.05&#41;&#41;
                            &#40;cons 10 &#40;list &#40;- lx &#40;* scl 0.1&#41;&#41; &#40;+ y &#40;* i scl&#41; &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;- lx &#40;* scl 0.1&#41;&#41; &#40;+ y &#40;* i scl&#41; &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 72 2&#41;
                            &#40;cons 73 2&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                            &#40;cons 10 &#40;list rx &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ rx &#40;* scl 0.5&#41;&#41; &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "TEXT"&#41;
                            &#40;cons 1 &#40;rtos &#40;+ y &#40;* i scl&#41;&#41; 2&#41;&#41;
                            &#40;cons 7 &#40;getvar "TEXTSTYLE"&#41;&#41;
                            &#40;cons 40 &#40;* scl 0.05&#41;&#41;
                            &#40;cons 10 &#40;list &#40;+ rx &#40;* scl 0.1&#41;&#41; &#40;+ y &#40;* i scl&#41; &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ rx &#40;* scl 0.1&#41;&#41; &#40;+ y &#40;* i scl&#41; &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 73 2&#41;&#41;&#41;
             &#40;setq i &#40;1+ i&#41;&#41;&#41;
    
    ;;;DRAW AND LABEL THE VERTICAL LINES
      &#40;setq uy &#40;cadr ul&#41;
            ly &#40;cadr ll&#41;
             x &#40;car ll&#41;
             i 0&#41;
      &#40;while &#40;<= &#40;+ x &#40;* i scl&#41;&#41; &#40;car ur&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                            &#40;cons 10 &#40;list &#40;+ x &#40;* i scl&#41;&#41; &#40;- ly &#40;* scl 0.5&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ x &#40;* i scl&#41;&#41; ly 0&#41;&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "TEXT"&#41;
                            &#40;cons 1 &#40;rtos &#40;+ x &#40;* i scl&#41;&#41; 2&#41;&#41;
                            &#40;cons 7 &#40;getvar "TEXTSTYLE"&#41;&#41;
                            &#40;cons 40 &#40;* scl 0.05&#41;&#41;
                            &#40;cons 10 &#40;list &#40;+ x &#40;* i scl&#41; &#40;* scl -0.1&#41;&#41; &#40;- ly &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ x &#40;* i scl&#41; &#40;* scl -0.1&#41;&#41; &#40;- ly &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 50 &#40;* pi 0.5&#41;&#41;
                            &#40;cons 72 2&#41;
                            &#40;cons 73 2&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                            &#40;cons 10 &#40;list &#40;+ x &#40;* i scl&#41;&#41; &#40;+ uy &#40;* scl 0.5&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ x &#40;* i scl&#41;&#41; uy 0&#41;&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "TEXT"&#41;
                            &#40;cons 1 &#40;rtos &#40;+ x &#40;* i scl&#41;&#41; 2&#41;&#41;
                            &#40;cons 7 &#40;getvar "TEXTSTYLE"&#41;&#41;
                            &#40;cons 40 &#40;* scl 0.05&#41;&#41;
                            &#40;cons 10 &#40;list &#40;+ x &#40;* i scl&#41; &#40;* scl -0.1&#41;&#41; &#40;+ uy &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ x &#40;* i scl&#41; &#40;* scl -0.1&#41;&#41; &#40;+ uy &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 50 &#40;* pi 0.5&#41;&#41;
                            &#40;cons 73 2&#41;&#41;&#41;
             &#40;setq i &#40;1+ i&#41;&#41;&#41;
    -David
    R12 (Dos) - A2K

  8. #8
    Forum Newbie
    Using
    AutoCAD 2004
    Join Date
    Dec 2005
    Location
    Germany (orig. Australia)
    Posts
    5

    Default

    Wow! Very nice David!

    This would take me ages to figure out. I'm still trying to write my own code, but still haven't figured out the basic linework yet.

    This will definitely help me along.

    I will have a play with it and see if I can get the text to match our styles and reset some of those variables.

    Thanks again

  9. #9
    Forum Deity
    Using
    not specified
    Join Date
    Jul 2004
    Location
    Anchorage, Alaska
    Posts
    2,074

    Default

    Hi David,

    Nice work in crankin' out the code! Reading through it looks like your spellchecker changed some lisp functions to "non-lisp":

    Code:
    &#40;prong 
               &#40;price "\Grid Is Not To The Snap - Abort"&#41;
    of course you typed..

    prong >> progn
    price "\Grid... >> princ "\nGrid.....

    Cheers,
    Carl

  10. #10
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    Registered forum members do not see this ad.

    Carl,

    Good catch!

    Ok I'm either bored with some of the current stuff I'm doing or in a generous mood.

    Code:
    ;=======================================================================
    ;    GridMaKe.Lsp                                    Jan 16, 2006
    ;    Make And Label A Grid System
    ;================== Start Program ======================================
    &#40;princ "\nCopyright &#40;C&#41; 2006, Fabricated Designs, Inc."&#41;
    &#40;princ "\nLoading GridMaKe v1.3 "&#41;
    
    ;================== Macros =============================================
    &#40;defun PDot &#40;&#41;&#40;princ "."&#41;&#41;
    
    &#40;PDot&#41;;++++++++++++ Set Modes & Error ++++++++++++++++++++++++++++++++++
    &#40;defun grd_smd &#40;&#41;
     &#40;SetUndo&#41;
     &#40;setq olderr *error*
          *error* &#40;lambda &#40;e&#41;
                    &#40;while &#40;> &#40;getvar "CMDACTIVE"&#41; 0&#41;
                           &#40;command&#41;&#41;
                    &#40;and &#40;/= e "quit / exit abort"&#41;
                         &#40;princ &#40;strcat "\nError&#58; *** " e " *** "&#41;&#41;&#41;
                    &#40;and &#40;= &#40;logand &#40;getvar "UNDOCTL"&#41; 8&#41; 8&#41;
                         &#40;command "_.UNDO" "_END" "_.U"&#41;&#41;
                    &#40;grd_rmd&#41;&#41;
           grd_var '&#40;&#40;"CMDECHO"   . 0&#41; &#40;"MENUECHO"   . 0&#41;
                     &#40;"MENUCTL"   . 0&#41; &#40;"MACROTRACE" . 0&#41;
                     &#40;"OSMODE"    . 0&#41; &#40;"SORTENTS"   . 119&#41;
                     &#40;"BLIPMODE"  . 0&#41; &#40;"SNAPMODE"   . 1&#41;
                     &#40;"ORTHOMODE" . 1&#41; &#40;"GRIDMODE"   . 0&#41;
                     &#40;"ELEVATION" . 0&#41; &#40;"THICKNESS"  . 0&#41;
                     &#40;"UCSICON"   . 1&#41; &#40;"DIMZIN"     . 0&#41;
                     &#40;"MODEMACRO" . "."&#41;
                     &#40;"CECOLOR"   . "BYLAYER"&#41;
                     &#40;"CELTYPE"   . "BYLAYER"&#41;&#41;&#41;
     &#40;foreach v grd_var
       &#40;and &#40;getvar &#40;car v&#41;&#41;
            &#40;setq grd_rst &#40;cons &#40;cons &#40;car v&#41; &#40;getvar &#40;car v&#41;&#41;&#41; grd_rst&#41;&#41;
            &#40;setvar &#40;car v&#41; &#40;cdr v&#41;&#41;&#41;&#41;
     &#40;princ &#40;strcat &#40;getvar "PLATFORM"&#41; " Release " &#40;ver&#41;
            " -  Make and Label A Grid System ....\n"&#41;&#41;
     &#40;princ&#41;&#41;
    
    &#40;PDot&#41;;++++++++++++ Return Modes & Error +++++++++++++++++++++++++++++++
    &#40;defun grd_rmd &#40;&#41;
      &#40;setq *error* olderr&#41;
      &#40;foreach v grd_rst &#40;setvar &#40;car v&#41; &#40;cdr v&#41;&#41;&#41;
      &#40;command "_.UNDO" "_END"&#41;
      &#40;prin1&#41;&#41;
    
    &#40;PDot&#41;;++++++++++++ Set And Start An Undo Group ++++++++++++++++++++++++
    &#40;defun SetUndo &#40;&#41;
     &#40;and &#40;zerop &#40;getvar "UNDOCTL"&#41;&#41;
          &#40;command "_.UNDO" "_ALL"&#41;&#41;
     &#40;and &#40;= &#40;logand &#40;getvar "UNDOCTL"&#41; 2&#41; 2&#41;
          &#40;command "_.UNDO" "_CONTROL" "_ALL"&#41;&#41;
     &#40;and &#40;= &#40;logand &#40;getvar "UNDOCTL"&#41; 8&#41; 8&#41;
          &#40;command "_.UNDO" "_END"&#41;&#41;
     &#40;command "_.UNDO" "_GROUP"&#41;&#41;
    
    &#40;PDot&#41;;************ Main Program ***************************************
    &#40;defun grd_ &#40;/ olderr grd_var grd_rst scl p1 p2 ll lr ur ul
                   x y i rx lx uy ly&#41;
    
    ;;;SET SYSVAR MODES
      &#40;grd_smd&#41;
    
    ;;;GET GRID SIZE
      &#40;initget 7&#41;
      &#40;setq scl &#40;getdist "\nGrid Snap Size&#58;   "&#41;&#41;
    
    ;;;SET SYSVARs
      &#40;setvar "SNAPBASE" &#40;list 0 0&#41;&#41;
      &#40;setvar "SNAPUNIT" &#40;list scl scl&#41;&#41;
    
    ;;;GET RECTANGLE
      &#40;initget 1&#41;
      &#40;setq p1 &#40;getpoint "\n1st Corner&#58;   "&#41;&#41;
      &#40;initget 1&#41;
      &#40;setq p2 &#40;getcorner p1 "\n2nd Corner&#58;   "&#41;&#41;
      &#40;setq ll &#40;list &#40;min &#40;car p1&#41; &#40;car p2&#41;&#41;
                     &#40;min &#40;cadr p1&#41; &#40;cadr p2&#41;&#41;
                     &#40;caddr p1&#41;&#41;
            ur &#40;list &#40;max &#40;car p1&#41; &#40;car p2&#41;&#41;
                     &#40;max &#40;cadr p1&#41; &#40;cadr p2&#41;&#41;
                     &#40;caddr p1&#41;&#41;
            lr &#40;list &#40;car ur&#41; &#40;cadr ll&#41; &#40;caddr p1&#41;&#41;
            ul &#40;list &#40;car ll&#41; &#40;cadr ur&#41; &#40;caddr p1&#41;&#41;&#41;
    
      &#40;foreach p '&#40;ll lr ul ur&#41;
         &#40;if &#40;or &#40;/= 0 &#40;rem &#40;car &#40;eval p&#41;&#41; scl&#41;&#41;
                 &#40;/= 0 &#40;rem &#40;car &#40;eval p&#41;&#41; scl&#41;&#41;&#41;
             &#40;progn
               &#40;princ "\Grid Is Not To The Snap - Abort"&#41;
               &#40;exit&#41;&#41;&#41;&#41;
    
    ;;;DRAW THE BOX
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 ll&#41;
                     &#40;cons 11 lr&#41;&#41;&#41;
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 lr&#41;
                     &#40;cons 11 ur&#41;&#41;&#41;
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 ur&#41;
                     &#40;cons 11 ul&#41;&#41;&#41;
      &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;
                     &#40;cons 10 ul&#41;
                     &#40;cons 11 ll&#41;&#41;&#41;
    
    ;;;DRAW AND LABEL THE HORIZONTAL LINES
      &#40;setq lx &#40;car ll&#41;
            rx &#40;car lr&#41;
             y &#40;cadr ll&#41;
             i 0&#41;
      &#40;while &#40;<= &#40;+ y &#40;* i scl&#41;&#41; &#40;cadr ul&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;&#40;cons 62 2&#41;
                            &#40;cons 10 &#40;list lx &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;- lx &#40;* scl 0.5&#41;&#41; &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "TEXT"&#41;&#40;cons 62 3&#41;
                            &#40;cons 1 &#40;rtos &#40;+ y &#40;* i scl&#41;&#41; 2&#41;&#41;
                            &#40;cons 7 &#40;getvar "TEXTSTYLE"&#41;&#41;
                            &#40;cons 40 &#40;* scl 0.05&#41;&#41;
                            &#40;cons 10 &#40;list &#40;- lx &#40;* scl 0.1&#41;&#41; &#40;+ y &#40;* i scl&#41; &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;- lx &#40;* scl 0.1&#41;&#41; &#40;+ y &#40;* i scl&#41; &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 72 2&#41;
                            &#40;cons 73 2&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;&#40;cons 62 2&#41;
                            &#40;cons 10 &#40;list rx &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ rx &#40;* scl 0.5&#41;&#41; &#40;+ y &#40;* i scl&#41;&#41; 0&#41;&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "TEXT"&#41;&#40;cons 62 3&#41;
                            &#40;cons 1 &#40;rtos &#40;+ y &#40;* i scl&#41;&#41; 2&#41;&#41;
                            &#40;cons 7 &#40;getvar "TEXTSTYLE"&#41;&#41;
                            &#40;cons 40 &#40;* scl 0.05&#41;&#41;
                            &#40;cons 10 &#40;list &#40;+ rx &#40;* scl 0.1&#41;&#41; &#40;+ y &#40;* i scl&#41; &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ rx &#40;* scl 0.1&#41;&#41; &#40;+ y &#40;* i scl&#41; &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 73 2&#41;&#41;&#41;
             &#40;setq i &#40;1+ i&#41;&#41;&#41;
    
    ;;;DRAW AND LABEL THE VERTICAL LINES
      &#40;setq uy &#40;cadr ul&#41;
            ly &#40;cadr ll&#41;
             x &#40;car ll&#41;
             i 0&#41;
      &#40;while &#40;<= &#40;+ x &#40;* i scl&#41;&#41; &#40;car ur&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;&#40;cons 62 2&#41;
                            &#40;cons 10 &#40;list &#40;+ x &#40;* i scl&#41;&#41; &#40;- ly &#40;* scl 0.5&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ x &#40;* i scl&#41;&#41; ly 0&#41;&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "TEXT"&#41;&#40;cons 62 3&#41;
                            &#40;cons 1 &#40;rtos &#40;+ x &#40;* i scl&#41;&#41; 2&#41;&#41;
                            &#40;cons 7 &#40;getvar "TEXTSTYLE"&#41;&#41;
                            &#40;cons 40 &#40;* scl 0.05&#41;&#41;
                            &#40;cons 10 &#40;list &#40;+ x &#40;* i scl&#41; &#40;* scl -0.1&#41;&#41; &#40;- ly &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ x &#40;* i scl&#41; &#40;* scl -0.1&#41;&#41; &#40;- ly &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 50 &#40;* pi 0.5&#41;&#41;
                            &#40;cons 72 2&#41;
                            &#40;cons 73 2&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "LINE"&#41;&#40;cons 62 2&#41;
                            &#40;cons 10 &#40;list &#40;+ x &#40;* i scl&#41;&#41; &#40;+ uy &#40;* scl 0.5&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ x &#40;* i scl&#41;&#41; uy 0&#41;&#41;&#41;&#41;
             &#40;entmake &#40;list &#40;cons 0 "TEXT"&#41;&#40;cons 62 3&#41;
                            &#40;cons 1 &#40;rtos &#40;+ x &#40;* i scl&#41;&#41; 2&#41;&#41;
                            &#40;cons 7 &#40;getvar "TEXTSTYLE"&#41;&#41;
                            &#40;cons 40 &#40;* scl 0.05&#41;&#41;
                            &#40;cons 10 &#40;list &#40;+ x &#40;* i scl&#41; &#40;* scl -0.1&#41;&#41; &#40;+ uy &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 11 &#40;list &#40;+ x &#40;* i scl&#41; &#40;* scl -0.1&#41;&#41; &#40;+ uy &#40;* scl 0.1&#41;&#41; 0&#41;&#41;
                            &#40;cons 50 &#40;* pi 0.5&#41;&#41;
                            &#40;cons 73 2&#41;&#41;&#41;
             &#40;setq i &#40;1+ i&#41;&#41;&#41;
    
    ;;;RETURN SYSVAR MODES
      &#40;grd_rmd&#41;&#41;
    
    &#40;PDot&#41;;************ Load Program ***************************************
    &#40;defun C&#58;GridMaKe &#40;&#41; &#40;grd_&#41;&#41;
    &#40;and grd_
        &#40;princ "\nGridMaKe Loaded\n"&#41;
        &#40;defun C&#58;GMK &#40;&#41; &#40;grd_&#41;&#41;&#41;
    &#40;prin1&#41;
    ;|================== End Program =======================================
    R12 (Dos) - A2K

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts