 |
|
Exchange Forum >
AutoLISP and Visual LISP
Your favorite shortcut function |
|
|
|
|
|
| Your favorite shortcut function |
#21 |
|
|
Digital Rap |
 |
|
Join Date: |
|
08-23-2007 | |
Here are two very useful zoom functions for drawings with several layout tabs.
LZE, Layouts Zoom Extents, zooms extents in all layouts.
LZW, Layouts Zoom Window, zoom all layouts to the same window.
Code:
(defun c:LZE (/ Ctab Layout)
(princ "\nLayouts Zoom Extents")
(setq Ctab (getvar "CTAB"))
(foreach Layout (layoutlist)
(command "LAYOUT" "S" Layout)
(command "PSPACE")
(command "ZOOM" "E")
)
(setvar "CTAB" Ctab)
(princ)
)
(defun c:LZW (/ Ctab Layout P1 P2)
(princ "\nLayouts Zoom Window")
(if (/= (setq Ctab (getvar "CTAB")) "Model")
(progn
(command "PSPACE")
(if (setq P1 (getpoint "\nSpecify first corner: "))
(setq P2 (getcorner P1 "Specify opposite corner: "))
)
(if (and P1 P2)
(foreach Layout (layoutlist)
(command "LAYOUT" "S" Layout)
(command "PSPACE")
(command "ZOOM" "W" P1 P2)
)
)
)
(command "ZOOM" "W")
)
(setvar "CTAB" Ctab)
(princ)
)
| |
|
| Your favorite shortcut function |
#22 |
|
|
didier |
 |
|
Join Date: |
|
03-24-2008 | |
Hello
I am new to this forum,
I do not speak English well, but I know autocad...
quickly , cut my screen into two windows vertical
Amicalement
Code:
(defun c:f2 ()
(command "_-vports" "_2" "_v")
)
| |
|
| Your favorite shortcut function |
#23 |
|
|
Arch_Eric |
 |
|
Join Date: |
|
04-02-2008 | |
A couple of mine:
DSC - Dimension with surveyors coordinates; makes siteplans easier for me...you'll have to change the style line to your own style preference.
Code:
(defun c:dsc ( / p1 p2 d1 a1 mp t1 t2 t3)
(setvar "cmdecho" 0)
(setq p1 (getpoint "First point: "))
(setq p2 (getpoint "Second point: "))
(setq d1 (distance p1 p2))
(setq a1 (angle p1 p2))
(setq mp (polar p1 a1 (/ d1 2)))
(setq t1 (angtos a1 0 2))
(setq t2 (angtos a1 4 4))
(setq t3 (rtos (/ d1 12) 2 2))
(command "Style" "Archisel" "Archisel.shx" "12" "0.65" "" "" "")
(command "-text" "_c" mp t1 (strcat t2 " >" t3 "'"))
(setvar "cmdecho" 1))
This function is a mod of the copy/rotate function. I use it to copy my floorplan/roofline drawings for the 4 elevation views
Code:
(defun c:cel (/ sel pt)
(while (= sel nil) (setq sel (ssget)))
(princ "\Please select base point:")
(setq pt (getpoint))
(command "_.COPY" sel "" "0,0" "@")
(command "_.MOVE" "_P" "" pt "FROM" pt "@100',0")
(setq pt (getvar "LASTPOINT"))
(command "_.ROTATE" "_P" "" pt "90")
(command "_.COPY" sel "" "0,0" "@")
(command "_.MOVE" "_P" "" pt "FROM" pt "@100',0")
(setq pt (getvar "LASTPOINT"))
(command "_.ROTATE" "_P" "" pt "90")
(command "_.COPY" sel "" "0,0" "@")
(command "_.MOVE" "_P" "" pt "FROM" pt "@100',0")
(setq pt (getvar "LASTPOINT"))
(command "_.ROTATE" "_P" "" pt "90")
(princ)
)
| |
|
| Your favorite shortcut function |
#24 |
|
|
Space Cadet |
 |
|
Join Date: |
|
07-27-2007 | |
This is too cool. Have you ever wanted to clear the text screen real fast.
I call it N but you can rename it anything you like.
Code:
(defun c:N()
(repeat 35;or more if needed
(princ (strcat "\n"(chr 160)))
)
(princ)
)
| |
|
| Your favorite shortcut function |
#25 |
|
|
s.wickel |
 |
|
Join Date: |
|
06-24-2008 | |
Here one of my most used functions:
TL for total Length returns the Length of a line over many Points
Code:
(defun c:TL ( / I Laenge punktakt punktalt allepkt)
;Stefan Wickel, 2008
(defun grdraw_lst (ptlist col / pt1 pt)
(setq pt1 (nth 0 ptlist))
(foreach pt ptlist
(grdraw pt1 pt col)
(setq pt1 pt)
) ;foreach
) ;defun
(setq Laenge 0.0)
(setq punktakt (Getpoint "\nFirst point: "))
(setq allepkt (list punktakt))
(while punktakt
(setq punktalt punktakt)
(if (setq punktakt (getpoint punktalt "\nnext point: "))
(progn
(setq allepkt (cons punktakt allepkt))
(Setq Laenge (+ Laenge (distance punktalt punktakt)))
(grdraw punktalt punktakt -1)
)
)
(princ Laenge)
)
(princ "\nThe total Length is: ")
(princ Laenge)
(grdraw_lst allepkt -1)
(princ)
)
| |
|
| Your favorite shortcut function |
#26 |
|
|
s.wickel |
 |
|
Join Date: |
|
06-24-2008 | |
The next one returns the coordinates of a point in "ACAD-Format" "x,y,z", so you can copy it to Clipboard and use it for drawing.
Code:
(defun c:xyz ( / xyzkoord)
;Stefan Wickel, 2008
(setq xyzkoord (getpoint "choose point: "))
(setq xyzkoord (strcat (rtos (car xyzkoord) 2 (getvar "luprec"))
","
(rtos (cadr xyzkoord) 2 (getvar "luprec"))
","
(rtos (caddr xyzkoord) 2 (getvar "luprec"))
) ;strcat
) ;setq
;activate the following line to copy the Coordinates to Clipboard
;you need DOSLIB for this!
; (dos_clipboard xyzkoord)
(princ xyzkoord)
(princ)
)
If you use Doslib you can directly copy it to Clipboard.
Use this to enter the Numbers in three Cells in Excel:
Code:
(defun c:xyz2 ( / xyzkoord)
;Stefan Wickel, 2008
(setq xyzkoord (getpoint "choose point: "))
(setq xyzkoord (strcat (rtos (car xyzkoord) 2 (getvar "luprec"))
"\t"
(rtos (cadr xyzkoord) 2 (getvar "luprec"))
"\t"
(rtos (caddr xyzkoord) 2 (getvar "luprec"))
) ;strcat
) ;setq
;activate the following line to copy the Coordinates to Clipboard
;you need DOSLIB for this!
; (dos_clipboard xyzkoord)
(princ xyzkoord)
(princ)
)
| |
|
| Your favorite shortcut function |
#27 |
|
|
Russell |
 |
|
Join Date: |
|
07-31-2007 | |
I thought about this one after reading the post by s.winkel. I sometimes use this one to quickly get a point in reference to another in a lsp routine. Then I just highlight and copy and paste the line into my code.
Quote:
Command: Polar
First point: Second point:
(setq p2 (polar p1 (dtr 71.09009633) 2.05155704))
Here's the lsp file.
Code:
(defun c:Polar (/ p1 p2 deg rad)
(setq p1 (getpoint "\nFirst point: "))
(setq p2 (getpoint " Second point: "))
(setq rad (angle p1 p2))
(setq deg (rtd (angle p1 p2)))
(princ "\n(setq p2 (polar p1 (dtr ")(princ (rtos deg 2 8))(princ ") ")
(princ (rtos (distance p1 p2) 2 8))(princ "))")
(princ)
)
| |
|
| Your favorite shortcut function |
#28 |
|
|
Tomoko |
 |
|
Join Date: |
|
08-08-2007 | |
Here is one that I use from time to time to sort a text file of data that I need to be sorted. It removes all duplicate text lines and extra left and right spaces. It is meant for a data type text file.
Code:
; SortTextFile sorts a text file removing duplicate text and extra left and right spaces
(defun c:SortTextFile (/ OpenFile Text TextFile TextList)
(if (setq TextFile (getfiled "Select a Text file to sort" "" "txt" 2))
(progn
(setq OpenFile (open TextFile "r"))
(while (setq Text (read-line OpenFile))
(setq Text (vl-string-trim " " Text))
(if (not (member Text TextList))
(setq TextList (cons Text TextList))
)
)
(close OpenFile)
(setq TextList (acad_strlsort TextList))
(setq OpenFile (open TextFile "w"))
(foreach Text TextList
(write-line Text OpenFile)
)
(close OpenFile)
(princ (strcat "\n" TextFile " sorted."))
)
)
(princ)
)
| |
|
| Your favorite shortcut function |
#29 |
|
|
Underwood |
 |
|
Join Date: |
|
01-09-2009 | |
Here are two simple but useful functions I use while debugging my programs.
The "P" function prints an item to the command line, and the "PL" function prints each item in a list to the command line.
Code:
(defun P (Item)
(princ "\n")(princ Item)
(princ)
)
(defun PL (Lst)
(foreach Item Lst
(princ "\n")(princ Item)
)
(princ)
)
| |
|
| Your favorite shortcut function |
#30 |
|
|
Laison |
 |
|
Join Date: |
|
03-11-2009 | |
Here are my favorite routines that change the color and linetypes of entities.
Code:
;These routines will change entities color and linetype.
;By Laison Albarado March 2, 2009
;Change entities to color 1
(defun c:1 (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "C" "1" "")
(princ)
)
;Change entities to color 2
(defun c:2 (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "C" "2" "")
(princ)
)
;Change entities to color 3
(defun c:3 (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "C" "3" "")
(princ)
)
;Change entities to color 4
(defun c:4 (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "C" "4" "")
(princ)
)
;Change entities to color 5
(defun c:5 (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "C" "5" "")
(princ)
)
;Change entities to color 6
(defun c:6 (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "C" "6" "")
(princ)
)
;Change entities to color 7
(defun c:7 (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "C" "7" "")
(princ)
)
;Change entities to color 8
(defun c:8 (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "C" "8" "")
(princ)
)
;Change entities to color 9
(defun c:9 (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "C" "9" "")
(princ)
)
;Change entities to color bylayer
(defun c:BC (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "C" "BYLAYER" "")
(princ)
)
;Change entities to linetype bylayer
(defun c:BL (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "LT" "BYLAYER" "")
(princ)
)
;Change entities to linetype hidden2
(defun c:HN (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "LT" "HIDDEN2" "")
(princ)
)
;Change entities to linetype center2
(defun c:CN (/ ens)
(setq ens (ssget))
(command "change" ens "" "P" "LT" "CENTER2" "")
(princ)
)
| |
|
|
|
|
|