Autocad Slot Command

Autocad Slot Command Rating: 8,2/10 9998 votes

Fillet all four by making the rectangle a polyline and at atht fillet command use the 'p' option. I use the following for slots, but there are others: (defun C:SLOT (/ A B B1 B2 C D PW). The command window and the ribbon complement each other i.e. You can type commands on the command line or click on the ribbon icons. However the command prompts that appear on the command window prevent the user from getting confused. Status Bar The status bar is a thin strip of the AutoCAD window found between the command window and the.

Lesson1
Sampleprogram, mslot

This first lesson is merely a sampleAutoLISP program with each line numbered and explained. Its purposeis simply to provide a first introduction to the 'look and feel' of anAutoLISP program.

The program is called mslot (whichis short for 'milled slot,' as shown above). The program asks theuser to enter the width of the slot (the diameter of the milling cutter),then to locate the centers at both ends of the slot. The programthen creates the 2D profile view of the milled slot using a closed polylinewith two straight segments and two arc segments, as shown below.

Autocad slot command blocks

Since this is the first sample program,it has been kept very simple. There are several things that wouldbe added if it were written as a 'finished' and 'fool proof' program. (For example, it would offer a carry-over default diameterforthe slot. Also, it would have an error routine.) However, eventhough it is simple, it is still a practical program which adds a new capabilityto AutoCAD.

These lessons are sprinkled withsamples of programming code -- sometimes just a single line, other timesseveral lines. However, when a complete program is given, the beginningand end are marked with green marker lines, as below. You shouldnot only study this program, but also try it out as explained in the 'Introduction'one page back (see 'Fifteen Lessons').

------marker ------ beginning of working program ------ try it out ------

Autocad Slot Command Tool

Command

; MSLOT, short for Milled SLOT
Copyright © 1998 Ronald W. Leigh
Requests width and two center points.
Draws a polyline with two straight and two arc segments.
Variables:
a/b Centers
a1/a2 Endpoints of arc around a
b1/b2 Endpoints of arc around b
ang Angle of slot centerline
obm Old blipmode setting, 0 or 1
r Radius of arcs
w Width of slot ;

(defun c:mslot (/ a a1 a2 ang b b1 b2 obm r w) ;line 1
(setq obm (getvar 'blipmode')) ;line 2
(initget 7) ;line 3
(setq w (getreal 'nWidth of slot: ')) ;line 4
(setq r (/ w 2)) ;line 5
(setvar 'blipmode' 1) ;line 6
(initget 1) ;line 7
(setq a (getpoint 'nLocate first center: ')) ;line 8
(initget 1) ;line 9
(setq b (getpoint a 'nLocate second center: ')) ;line 10
(setvar 'blipmode' 0) ;line 11
(setq ang (angle a b)) ;line 12
(setq a1 (polar a (- ang (/ pi 2)) r)) ;line 13
(setq a2 (polar a (+ ang (/ pi 2)) r)) ;line 14
(setq b1 (polar b (- ang (/ pi 2)) r)) ;line 15
(setq b2 (polar b (+ ang (/ pi 2)) r)) ;line 16
(setvar 'cmdecho' 0) ;line 17
(command '.pline' a1 b1 'A' b2 'L' a2 'A' 'CL') ;line 18
(setvar 'cmdecho' 1) ;line 19
(setvar 'blipmode' obm) ;line 20
(princ) ;line 21
) ;line 22

-------- marker-------- end of working program -------- try it out --------

Explanation

The comment section
The section of the program above thenumbered lines is the comment section. These comments state the nameand purpose of the program, the variables, etc. When you load thisfile into AutoCAD, the load function does not place comments in memory. Comments can be included in two different ways. They can be placedbetweenthe two two-character combinations (semicolon-fence, and fence-semicolon)similar to the twelve lines at the beginning of this program, or they canbe placed after a single semicolon similar to the twenty-twoline numbers.
Program sections
There are five sections in the program proper.
Lines 1-2, Prepare: (program name, local variables, saving system variable setting)
Lines 3-11, Get input: (width of slot, location of both centers)
Lines 12-16, Calculate: (determineendpoints of polyline segments)
Lines 17-19, Draw: (use thePLINE command to draw the slot)
Lines 20-22, Reset: (restoresystem variable setting)
Line 1
The program proper starts at line 1. The opening parenthesis beforedefun matches the very last closing parenthesis and thus encloses the entireprogram. The defun function defines the program name, which in thiscase is c:mslot. This name is the symbol by which the program willbe called. The c: makes this a program to be called at AutoCAD'scommand prompt, and has nothing to do with Drive C. To run the program,only MSLOT is entered at the command prompt. The list of variablesstarts with a forward slash, which make all the variables local.
Line 2
Since the program is going to turn blipmode on and off (see lines 6 and11), the program runs the risk of changing the setting that the user hadpreviously selected for blipmode. To avoid this, the value of blipmodeneeds to be saved so it can be restored by the setvar function in line20. The inner expression (getvar 'blipmode') is executed first. Thisexpression retrieves the current setting of the 'blipmode' system variable,which will be either 0 (for 'off') or 1 (for 'on'). Then the setqfunction assigns this value to the variable obm.
Line 3
The initget function initializes the next getreal function (in line 4)so that the user must enter a number rather than merely hitting 'Enter'. (Hitting 'Enter' would cause the getreal function to return nil, whichwould then be assigned to variable w, which would cause the program tocrash in line 5.) The initget setting of 7 also keeps the user fromentering either zero or a negative number for the width of the slot.
Line 4
The getreal function prompts the user for the width of the slot. After the user enters a number, the setq functions assigns that numberto variable w. The 'n' in front of the prompt forces the promptto appear at the left margin, at the beginning of a new line.
Line 5
The value in variable w (the width) is divided by 2 and assigned to variabler (radius). Notice that, in the expression which divides the widthby 2 (/ w 2), the divide function (indicated by the forwardslash) comes first. This is known as prefix notation. (By theway, don't confuse this forward slash with the one found in line 1. There it indicates local variables. Here it indicates the divisionfunction.)
Line 6
The setvar function turns blipmode on by setting system variable 'blipmode'to 1.
Lines 7
The initget function initializes the next getpoint function (in line 8)so that the user must indicate a point rather than merely hitting 'Enter'. (Hitting 'Enter' would cause the getpoint function to return nil, whichwould then be assigned to variable a, which would cause the program tocrash in line 10.)
Line 8
The getpoint function pauses and prompts the user to locate the first center. This location (actually a list of the three coordinates of the point) isthen assigned to variable a by the setq function.
Lines 9
(see line 7)
Line 10
Same as line 8 except the getpoint function has as its first argument thevariable a. If the user enters the two centers on screen rather thanusing the keyboard, this first argument connects a rubber-band cursor topoint a as the user moves the cursor to point b.
Line 11
The setvar function turns blipmode off so that later (in line 18) the pointssubmitted to the PLINE command will not place blips on the screen.
Line 12
The angle function returns the angle (in radians) between centers a andb, which is then assigned to variable ang.
Line 13
This line calculates the location of point a1 by using the polar function. The polar function uses a base point, an angle, and a distance. Thebase point is a. The angle is 90 degrees less than ang, but the polarfunction needs radians so the expression (/ pi 2) is used inplace of 90. The distance is the radius of the arc, stored in variabler.
Lines 14, 15, 16
Similar to line 13, except in lines 15 and 16 variable b is used as thebase point, and in lines 14 and 16 the '90 degrees' (/ pi 2) is added toang rather than subtracted.
Line 17
The setvar function is used to turn system variable 'cmdecho' (commandecho) off. This is done so that the next line, which draws a four-segmentpolyline, will not echo the PLINE prompts to the screen.
Line 18
The command function submits all of its arguments to the AutoCAD commandinterpreter. In effect, it runs the PLINE command and then submitsthe same information you would submit if you were running the PLINE commandfrom the keyboard, namely, point a1, point b1, 'A' for arc mode, pointb2, 'L' for line mode, point a2, 'A' for arc mode, and finally 'CL' forclose. The dot in front of the PLINE command forces AutoCAD to useits built-in PLINE command (just in case someone has undefined PLINE).
Line 19
Command echo is turned back on.
Line 20
Blipmode is set back to the setting it had before the program was run. The value of variable obm was set in line 2.
Line 21
Without this line, the last function in the program would be the setvarfunction which would return a number (0 or 1) which would be echoed tothe screen. The princ function echoes nothing, and thus providesa 'clean exit' for the program.
Line 22
This final parenthesis closes off the first opening parenthesis which isfound before the defun function in line 1.


HOME

Copyright ©1988, 1998 Ronald W. Leigh
Slot

The MIrror command creates a reverse copy of an object in AutoCAD. After you select some objects, AutoCAD prompts you to select two points that define a line about which the objects will be mirrored. You can then retain or delete the source objects. Follow these steps to use the MIrror command:

  1. Press Esc to make sure that no command is active and no objects are selected.
  2. Click the Mirror button on the Home tab’s Modify panel, or enter MI and press Enter.
  3. Select at least one object, and press Enter to end the object selection. AutoCAD prompts you to define the mirror line by picking points: Specify first point of mirror line:
  4. Specify the start of the mirror line by clicking a point or typing coordinates. AutoCAD prompts you: Specify second point of mirror line:
  5. Pick a second point. Most of the time, you’ll enable Polar Tracking mode or Ortho mode so that you can mirror objects precisely. You can also use object snaps on existing objects, including ones being mirrored, which ensure exact symmetry between the source and the mirrored objects. AutoCAD now prompts you: Erase source objects? [Yes/No] <N>:
  6. Finish the mirror by using one of these options:
  • Type Y at the final prompt. The source objects disappear, leaving only the new, mirrored copy.
  • Accept the default No option. The source objects are retained along with the mirrored copies.

Autocad Slot Command Tutorial

Normally, when you mirror text or dimensions, the words read backward. The system variable MIRRTEXT can handle this little problem. By default, MIRRTEXT is turned off (that is, its value is 0), so the text itself still reads the right way around after the objects are mirrored. If you really want your drawing text to appear in reverse, change the value of MIRRTEXT to 1.