 |
|
Exchange Forum >
AutoLISP and Visual LISP
Your favorite shortcut function |
|
|
|
|
|
| Your favorite shortcut function |
#1 |
|
|
Bennett |
 |
|
Join Date: |
|
07-26-2007 | |
Every day while at work we all use several shortcut functions. Some of these shortcuts we’ve written ourselves and some we’ve used so long we don’t know where they came from. In this thread briefly describe your favorite shortcut function, and include the AutoLISP code. Please limit your functions to one per post.
My favorite shortcut function is JP for join polyline. The user selects a line, arc or polyline and then several lines, arcs or polylines and then the function joins all that touch into one polyline.
Code:
(defun c:JP (/ EntType SS)
(princ "\nSelect lines, arcs or polylines to be joined into a polyline.")
(if (setq SS (ssget))
(progn
(setq EntType (cdr (assoc 0 (entget (ssname SS 0)))))
(if (or (= EntType "LINE")(= EntType "ARC"))
(command ".PEDIT" SS "Y" "J" SS "" "X")
)
(if (or (= EntType "POLYLINE")(= EntType "LWPOLYLINE"))
(command ".PEDIT" SS "J" SS "" "X")
)
)
(princ "\nNo lines, arcs or polylines selected.")
)
(princ)
)
| |
|
| Your favorite shortcut function |
#2 |
|
|
Omega |
 |
|
Join Date: |
|
08-20-2007 | |
My favorite is MI. It turns the orthomode on for the mirror command.
Code:
(defun c:MI ( )
(princ "\nMIRROR")
(setvar "ORTHOMODE" 1)
(command "MIRROR")
(princ)
)
| |
|
| Your favorite shortcut function |
#3 |
|
|
Sedgwick |
 |
|
Join Date: |
|
07-31-2007 | |
Here's one that I use quite often. CA for Calculator. It brings up the Windows Calculator in AutoCAD.
Code:
(defun c:CA ( )(princ "\nCalculator")(startapp "Calc.exe")(princ))
| |
|
| Your favorite shortcut function |
#4 |
|
|
Justin |
 |
|
Join Date: |
|
09-24-2007 | |
Here’s a shortcut that’s handy for opening up Windows Explorer in your current drawing folder.
Code:
(defun c:WE ( )
(princ "\nWindows Explorer")
(startapp "EXPLORER" (strcat "/E," (getvar "DWGPREFIX")))
(princ)
)
| |
|
| Your favorite shortcut function |
#5 |
|
|
Digital Rap |
 |
|
Join Date: |
|
08-23-2007 | |
Here is a shortcut that I find very useful named RR for Rotate with Reference points.
Code:
(defun c:RR (/ Ang AngR Pt1 Pt2 PtR Objects)
(princ "\nRotate with Reference points")
(if (setq Objects (ssget))
(progn
(setq PtR (getpoint "\nRotation base point: "))
(setq Pt2 (getpoint "\nPoint to rotate from: "))
(setq Pt1 (getpoint "\nPoint to rotate to: "))
(setq AngR (- (angle Pt1 PtR) (angle Pt2 PtR)))
(setq Ang (/ (* AngR 180) pi))
(command ".ROTATE" Objects "" PtR Ang)
)
(princ "\nNo objects selected.")
)
(princ)
)
| |
|
| Your favorite shortcut function |
#6 |
|
|
CadBrowser |
 |
|
Join Date: |
|
09-25-2007 | |
My favorite on is one I wrote called DX. It is a two key command written in AutoLISP that distinguishes between Dynamic Text, Multiple Text, Dimensions, Blocks with Attributes, and Attribute Definitions and selects the approprate AutoCAD text editor.
So instead of using the following commands:
edit or "ed"
ddatte
attdef
eattedit
or having to double click
I just type in DX and then select the text I want to edit.
Here is the code:
Code:
(defun c:dx (/ obj name entlist txt truefalse vers)
(setq vers (getvar "acadver"))
(setq fd (getvar "filedia"))
(setvar "filedia" 1)
(setq obj (entsel))
(while
(= obj nil)
(alert "Nothing selcted : Try Again!")
(setq obj (entsel))
)
(setq name (car obj))
(setq entlist (entget name))
(setq txt (cdr (assoc 0 entlist)))
(cond
((= txt "INSERT")
(setq truefalse (cdr (assoc 66 entlist)))
(cond ((= truefalse 1)
(if (or (= vers "16.0s (LMS Tech)")(= vers "16.1s (LMS Tech)"))
(command "eattedit" obj)
(command "ddatte" obj)
)
)
((= truefalse nil)
(alert "Block Chosen Has No Attributes Associated With It : Try Again!")
(quit)
)
)
)
((or (= txt "TEXT")(= txt "MTEXT")(= txt "DIMENSION")(= txt "ATTDEF"))
(command "ddedit" obj "")
)
((= txt "ARCALIGNEDTEXT")
(command "arctext" obj)
)
((or (/= txt "TEXT")(/= txt "MTEXT")(/= txt "DIMENSION")(/= txt "INSERT")(/= txt "ATTDEF")(/= txt "ARCALIGNEDTEXT"))
(alert "Object Is Unmodifiable With This LISP : Try Again!")
(quit)
)
)
(setvar "filedia" fd)
(princ)
)
| |
|
| Your favorite shortcut function |
#7 |
|
|
Cricket |
 |
|
Join Date: |
|
08-30-2007 | |
SA, Snap Angle, is one of the ones I use the most at work.
It sets the Snap Angle to the object selected or sets it back to 0.
Code:
(defun c:SA (/ EntPick Pt1 Pt2 SnapAng)
(initget "Entity")
(setq SnapAng (getangle "\nSnap Angle/<Entity>: "))
(cond
((numberp SnapAng)(setvar "SNAPANG" SnapAng))
((and (or (not SnapAng)(eq SnapAng "Entity"))
(setq EntPick (entsel))
(setq Pt1 (osnap (cadr EntPick) "QUI,END"))
(setq Pt2 (osnap (cadr EntPick) "QUI,MID"))
)
(setvar "SNAPANG" (angle Pt1 Pt2))
)
(t
(princ "\nNothing selected. Snap Angle set to 0.")
(setvar "SNAPANG" 0)
)
)
(setvar "ORTHOMODE" 1)
(princ)
)
| |
|
| Your favorite shortcut function |
#8 |
|
|
Cadeaux |
 |
|
Join Date: |
|
08-21-2007 | |
I use Array Polar a lot, so here is my AP function for Array Polar.
Code:
(defun c:AP(/ Number Pt Items)
(princ "\nARRAY Polar")
(if (setq Items (ssget))
(if (setq Pt (getpoint "\nSpecify center point of array: "))
(if (setq Number (getstring "\nEnter the number of items in the array: "))
(command "ARRAY" Items "" "P" Pt Number 360 "Y")
)
)
)
(princ)
)
| |
|
| Your favorite shortcut function |
#9 |
|
|
Garth |
 |
|
Join Date: |
|
08-18-2007 | |
We create our Mviews on layer Defpoints so we don't have to turn it off to plot.
Here's our version of MV to create Mviews.
Code:
(defun c:MV ( )
(princ "\nMVIEW")
(if (tblsearch "LAYER" "Defpoints")
(command "_LAYER" "T" "Defpoints" "U" "Defpoints" "ON" "Defpoints" "S" "Defpoints" "")
(command "_LAYER" "M" "Defpoints" "")
)
(if (/= (getvar "CTAB") "Model")
(command "_PSPACE")
)
(command "_MVIEW")
(princ)
)
| |
|
| Your favorite shortcut function |
#10 |
|
|
Terry Cadd |
 |
|
Join Date: |
|
09-10-2007 | |
My favorite shortcut is DOF, double offset. It’s the first LISP function I wrote. It was initially created to speed up drawing hydraulic cylinders. The user picks or enters the diameter, and the function offsets the line selected on both sides.
Code:
(defun c:DOF (/ Ang1 Ang2 EntList@ EntName^ EntType$ Offset~ Offset2~ Osmode# Pt Pt1 Pt2 SS&)
(setq Osmode# (getvar "OSMODE"))
(if (<= (getvar "OFFSETDIST") 0)
(setvar "OFFSETDIST" 0.5)
);if
(setq Offset2~ (* (getvar "OFFSETDIST") 2.0))
(princ "\nDouble Offset") (graphscr)
(setq Offset~
(getdist
(strcat "\nPick or enter twice the distance for double offset <"
(rtos Offset2~) ">: ")
);getdist
);setq
(if Offset~
(if (<= Offset~ 0.0)
(setq Offset~ nil)
);if
(setq Offset~ Offset2~)
);if
(if Offset~
(progn
(setq Offset~ (/ Offset~ 2.0))
(setvar "OSMODE" 512);nearest
(if (setq Pt (getpoint "\nSelect object to double offset: "))
(progn
(if (setq SS& (ssget Pt))
(progn
(setq EntName^ (ssname SS& 0))
(setq EntList@ (entget EntName^))
(setq EntType$ (cdr (assoc 0 EntList@)))
(if (or (= EntType$ "LINE")(= EntType$ "ARC")(= EntType$ "CIRCLE")
(= EntType$ "POLYLINE")(= EntType$ "LWPOLYLINE"))
(progn
(setvar "OSMODE" 4);center
(command ".LINE" Pt "")
(setq Pt2 (getvar "LASTPOINT"))
(if (equal Pt Pt2)
(progn ;Pt is on a line segment
(setvar "OSMODE" 1);endpoint
(command ".LINE" Pt "")
(setq Pt1 (getvar "LASTPOINT"))
(setvar "OSMODE" 2);midpoint
(command ".LINE" Pt "")
(setq Pt2 (getvar "LASTPOINT"))
(setq Ang1 (angle Pt1 Pt2))
(if (>= Ang1 pi)
(setq Ang1 (- Ang1 pi))
);if
(if (>= Ang1 (/ pi 2.0))
(setq Ang1 (+ Ang1 (/ pi 2.0)))
(setq Ang1 (- Ang1 (/ pi 2.0)))
);if
(setq Ang2 (+ Ang1 pi))
(setq Pt1 (polar Pt Ang1 Offset~))
(setq Pt2 (polar Pt Ang2 Offset~))
(setvar "OSMODE" 512);nearest
(command ".ZOOM" "C" Pt (* Offset~ 2.0))
(command ".OFFSET" Offset~ Pt Pt1 "")
(command ".OFFSET" Offset~ Pt Pt2 "")
(command ".ZOOM" "P")
(command ".LINE" Pt "")
);progn
(progn ;Pt is on an arc segment
(setq Ang1 (angle Pt2 Pt))
(setq Ang2 (- Ang1 pi))
(setq Pt1 (polar Pt Ang1 Offset~))
(setq Pt2 (polar Pt Ang2 Offset~))
(setvar "OSMODE" 512);nearest
(command ".ZOOM" "C" Pt (* Offset~ 2.0))
(command ".OFFSET" Offset~ Pt Pt1 "")
(command ".OFFSET" Offset~ Pt Pt2 "")
(command ".ZOOM" "P")
(command ".LINE" Pt "")
);progn
);if
);progn
(princ "\nCannot double offset that entity.")
);if
);progn
(princ "\nNo object selected.")
);if
);progn
);if
);progn
(princ "\nValue must be positive and nonzero.")
);if
(setvar "OSMODE" Osmode#)
(princ)
);defun c:DOF
| |
|
|
|
|
|