Autocad Slot Command

Autocad Slot Command Average ratng: 5,7/10 1389 votes
Lesson1
Sampleprogram, mslot
  1. Autocad Slot Command Block
  2. Autocad Slot Command
Autocad

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.

Learn AutoCAD LT hotkeys and commands with the AutoCAD LT Shortcut Keyboard guide to help you work faster and be more efficient while using AutoCAD LT software. Slot Generator (Tip #2101) from Steven Johnson accepts parameter input for drawing a slot at any angle. Load the LSP code and type SLOT at the Command line to activate. Two options are available. You can define a slot from end to end or from center to center. After making your choice, enter (or show) the slot angle, width and length. Adding Slots The Through Slot command is located on the ribbon, Contenttab, Holespaneldrop-down. Click the Holespanel title, select the Through Slot icon, and the Select a Slot- Through dialog box opens. You can see that there are several classifications of Through slotsthat can be added.

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 ------

; 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
Command

AutoCAD is one of the most used engineering programs across the globe. Here are the top 33 AutoCAD tricks and shortcuts from around the web!

Autocad

AutoCAD is one of the most used engineering programs across the world, and it’s likely that you have come in contact with the program sometime in your career.

SETUP & BASICS
1. Keyboard Shortcuts
2. Autosave
3. Quick Access Toolbar
4. Right-click
5. Layers
6. Draw Order

VIEWING
7. Zoom
8. Display Plot Styles
9. Shared Views

OBJECTS
10. Object Snaps
11. Isolate Objects
12. Move/Copy/Rotate
13. Associative Arrays
14. Dimensions

Autocad Slot Command

MODIFYING
15. Match Properties
16. Dynamic Blocks
17. Group
18. Explode Attributes
19. DWG Compare

ANNOTATION

20. Multiline Text
21. Spell Checker
22. Find and Replace
23. QuickCalc

DATA MANAGEMENT
24. External References
25. eTransmit
26. PDF Import
27. Sheet Set Manager

ECOSYSTEM
28. App Store
29. Specialized Toolsets
30. AutoCAD Web App
31. AutoCAD Mobile App

MINDSET
32. Make Mistakes
33. You Do You

Download PDF in Details :

AutoCAD tips and tricks pdf Free Download

Autocad slot command blocks

Other Some important Tips of AUTOCAD

Tip 1. The Command “Laydel”. This will allow you to delete everything on a layer, even the most stubborn of layers. Won’t delete “Layer 0” or “Defpoints”.

Tip 2. When doing a corner use the fillet command. Instead of typing in a radious of “0”, you can just hold the “shift” key to automatically get a corner.

Tip 3. You can select and move multiple grips by holding down the shift key.

Tip 4. System default PEDITACCEPT. Set this to “1”. This will get rid of that annoying prompt when converting a line to a polyline.

Tip 5. Command “Texttofront”. brings all text to front

Autocad Slot Command Block

Tip 6. Command “Hatchtoback”. Guess what this does!

Autocad Slot Command

Related posts: