Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

My ACAD.LSP file 5

Status
Not open for further replies.

Sparweb

Aerospace
May 21, 2003
5,109
I felt like sharing today.

Code:
;	Extra commands for AutoCAD
;	Steven Fahey
;	7 JANUARY 2015
;

(defun c:VRA    () (command "view" "r" "A"))
(defun c:VRB    () (command "view" "r" "B"))
(defun c:VRC    () (command "view" "r" "C"))
(defun c:VRD    () (command "view" "r" "D"))
(defun c:VRE    () (command "view" "r" "E"))
(defun c:VRF    () (command "view" "r" "F"))

(defun c:VSA    () (command "view" "s" "A"))
(defun c:VSB    () (command "view" "s" "B"))
(defun c:VSC    () (command "view" "s" "C"))
(defun c:VSD    () (command "view" "s" "D"))
(defun c:VSE    () (command "view" "s" "E"))
(defun c:VSF    () (command "view" "s" "F"))

(defun c:ZA     () (command "zoom" "all"))
(defun c:ZE     () (command "zoom" "e"))
(defun c:ZP     () (command "zoom" "previous"))
(defun c:ZI     () (command "zoom" "2x"))
(defun c:ZO     () (command "zoom" ".8x"))
(defun c:ZOO    () (command "zoom" ".5x"))
(defun c:Z1P    () (command "zoom" "1xp"))

(defun c:BRA    () (command "break" pause "f" "int" pause "@"))

(defun c:U1     () (command "luprec" "1"))
(defun c:U2     () (command "luprec" "2"))
(defun c:U3     () (command "luprec" "3"))
(defun c:U4     () (command "luprec" "4"))
(defun c:U5     () (command "luprec" "5"))

(defun c:cttr   () (command "circle" "ttr" "tan" pause "tan"))
(defun c:c3p    () (command "circle" "3p"))
(defun c:c2p    () (command "circle" "2p"))

(defun c:filt   () (command "fillet" "trim" "t"))
(defun c:filn   () (command "fillet" "trim" "n"))

(defun c:xv     () (command "xline" "v"))
(defun c:xh     () (command "xline" "h"))

(defun c:purgall () (command "purge" "a" "" "n"))

(defun c:coro   () (command "copy" pause "" "0,0" "@" "rotate" "p" "" pause "90"))

(defun c:bam    () (command "base" "0,0,0" "move" "all" "" pause "0,0,0" "zoom" "e" "zoom" "0.75x"))

AutoCAD is designed to be used with a keyboard. Users who don't maximize their use of a keyboard are not maximizing their efficiency in AutoCAD.

Here is an explanation of the keyboard shortcuts I like:

I make multi-sheet drawings. Saved views allow me to switch easily from one sheet to another. VRA jumps to sheet A, no matter where I started from.
I dodn't always have a scroll wheel mouse, eg Laptop trackpad. ZI and ZO allow quick zooming in without selecing windows over and over.
I still frequently use ZE to see EVERYTHING - and find all the stuff people drew 6 miles to the left of the main view.
Breaking lines takes a lot of clicks. BRA saves clicks.
Many users don't configure units, and I may open their drawing to find either 10 decimal places, or none. U1 through U5 saves many clicks.
Making Circles requires more clicks than necessary.
I don't do Filleting without trimming very often, but when I do I want to switch back and forth frequently during the process, so this helps.
Construction lines are valuable so I shortened the typing to have horizontal and vertical XLINES.
Making drawings inevitably means bringing in blocks, styles, and "stuff" you don't need when you're done. Purgall in one command dumps all the chaff.
How often do you want a copy of a line rotated 90 degrees? Do both steps in one CORO.
Did you create a block file, but set its base in the wrong spot? BAM and you're done. It even resizes the view to fit the preview.


STF
 
Replies continue below

Recommended for you

Add to to that one, if it works, great
 
Thank you IFRs, I've added your MText block, now.

STF
 
Hello. I copied this on my acad.lsp file and I get an error that says: "; error: AutoCAD variable setting rejected: "CLayer" "TEXT""

IFRs said:
(DEFUN C:MT () ; MText on layer TEXT
(setq CLA (getvar "CLayer"))
(progn
(setvar "CLayer" "TEXT")
(command "MTEXT" pause "J" "bl" pause)
(setvar "Clayer" CLA)
)
(PRINC)
)

What am I doing wrong?

JBC
.......
"The more I read, the more I acquire, the more certain I am that I know nothing"
 
Another question:

I've got a bunch of different long lisps in different files (each file, a long command)

Do you think I should "merge" everything on a really long and messy ACAD.LSP or there is a more orderly way of doing it?

I have all my lisps files on my documents folder

JBC
.......
"The more I read, the more I acquire, the more certain I am that I know nothing"
 
To the first JuanBC question:
Before executing (MT) your have to create layer named "TEXT":
Manually in the current drawing.
Manually but once in your drawing template,
or some additional Lisp code where the "TEXT" Layer have to be created if not exists.
Try to put this:
Code:
(DEFUN C:MT () ; MText on layer TEXT
(setq CLA (getvar "CLayer"))
(progn
(if (not (tblsearch "layer" "TEXT")) 
 (command "-layer" "m" "TEXT" "c" "80" "" "L" "continuous" "")
)
(setvar "CLayer" "TEXT")
(command "MTEXT" pause "J" "bl" pause)
(setvar "Clayer" CLA)
)
(PRINC)
)

To the second question:
In your acad.lsp your could to write:
Code:
(vl-load-com)
(load "C:\\...\\your favorite.lsp")
And all your favorite Lisp functions drop to "your favorite.lsp"

Also there in Autocad Options is Startup Suite, where you can set any Lisp file to start in every session.
 
I usually mash all the smaller ones into Acad.lsp, separated by semi-colons and keep the large ones separate. Makes it easier to edit if needed, for me anyway.
 
For some that are large but I seldom need I put this in Acad.lsp

(DEFUN C:Cutube () (IF (NOT C:Cutube) (LOAD "Cutube")) (C:Cutube) (PRINC))
 
Hi maripali,

Thank you for both codes! I really appreciate your help since I'm really noob to ACAD Lisps.

The second code (autoloading lisps) works perfect (using / instead of \), but something went wrong with your MT lisp. This is what I got when I write "MT" on command line:

¿Any ideas? Thank you!

Code:
Command: MT
-layer
Current layer:  "0"
Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: m
Enter name for new layer (becomes the current layer) <0>: TEXT Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: c
New color [Truecolor/COlorbook] : 80
Enter name list of layer(s) for color 80 <TEXT>: Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: L
Enter loaded linetype name or [?] <Continuous>: continuous
Enter name list of layer(s) for linetype "continuous" <TEXT>: Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: MTEXT
Invalid option keyword.
; error: Function cancelled
Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: *Cancel*



JBC
.......
"The more I read, the more I acquire, the more certain I am that I know nothing"
 
Change
(command "-layer" "m" "TEXT" "c" "80" "" "L" "continuous" "")
to
(command "-layer" "m" "TEXT" "c" "80" "" "L" "continuous" "" "")
 
Thank you! Worked!

JBC
.......
"The more I read, the more I acquire, the more certain I am that I know nothing"
 
JuanBC - the "COMMAND" syntax is exactly what you type on the command line. If you do the -layer command yourself, you will see why the additional "" (representing either a space or return keypress) is needed. Many times this is the key to understanding or making a macro in Acad.lsp. Good luck in future programming!
 
JaunBC... there are a couple of really good AutoLisp tutorials on the web... if curious, you can look them up... almost a walk through the park...

Dik
 
dik said:
JaunBC... there are a couple of really good AutoLisp tutorials on the web... if curious, you can look them up... almost a walk through the park...

Yes, I want to start learning to program in lisp but I am currently short on free time. When I start programming, I'll probably come back with more questions! ;)

JBC
.......
"The more I read, the more I acquire, the more certain I am that I know nothing"
 
You're welcome any time Juan!
Old threads tend to get locked after a period of inactivity, so don't hesitate to start a new one to expand this topic.

STF
 
SparWeb... you've created a really good thread.

Dik
 
You're welcome.
I've been thinking about sharing a number of things to help user configuration of AutoCAD. The LISP file was the obvious starting point.
Given the interest in this thread, I now want to create more new threads about other user configuration details, such as "Workspace", desktop link switches, keyboard shortcuts in the PGP file, etc.

I find that users new and old are presented with the default workspace of AutoCAD and are either overwhelmed by the mess or offended by the clutter. (I'm the latter).
There's a dramatic difference between the user experience of AutoCAD (keyboard+mouse) compared to nearly every other professional software interface (mouse exclusively).
I guess I'm wandering into "user interface" issues... probably worth a thread of its own, too.

STF
 
Some folks on Eng-Tips know this already, but for the rest of you: I started a new job last week.

They only use AutoCAD LT.

LT doesn't accept LISP.

BOOHOOO [CRY]


STF
 
Try and see if they can use Bricscad... 99.9% AutoCAD compatible, costs less than LT and
has 4 or 5 programming environments as well as Lisp, and does 3D. I've opened 50 meg 3D
files from Autocad using Bricscad, modified them and reopened them with AutoCAD.
You also buy a license, not rent one.

Wordwrap doesn't seem to be working... Put in 'hard' breaks.

Dik
 
Thank you dik, for the suggestion. It's greatly appreciated.
Unfortunately, the PC's are all "locked down" and I do not have ADMIN privileges, either! [banghead]
I can't even delete the "bloatware" icons on my desktop!


STF
 
Locked down, eh... wanna know how? I do nearly all my work on my laptop.
I can be working on it before the login screen comes up on the office
desktop. I'm not a cad operator, but, use it and often provide details
for normal CAD operators. I also have thousands of standard details that
I use for projects.

You may want to talk to management about changing... if you need to provide
a client with an 'official' autocad drawing, then have one dedicated work
station for this. Look into Bricscad, you could save your company several
thousand dollars. I know how difficult it is... I tried approaching our
company for the same reason.

Dik
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor