ZWSOFT User Community > ZWSOFT Forums - Find. Share. Connect. > ZWCAD > Some lisp routines for beginners
Some lisp routines for beginners

Rank: 1

maker

Newbie

posts: 0

Registered: 2008-8-15

Message 1 of 7

Some lisp routines for beginners
02-05-2008 09:35 . am | View his/her posts only
Hi,
Some lisp routines for beginners. Unfortunately no error checking in it - since my knowledge is only basic. Still I hope it is of some help to anybody. Perhaps someone more knowledgeable can develop it furtherWink
(just copy - paste it into a blank notepad file; save it as starter.lsp - or whatever. Use the 'appload' command to load it...). Please test it, if possible. Comments (after the ;;) indicate the nature of the command. to call the command from ZwCad just type the name (after the 'c:' - eg vs for 'save view' vr for 'restore view' etc.



;;VIEW COMMANDS (vs, vr, vst, vrt)
(defun c:vs() ;;Saves view (of name to be supplied by user).
(command "-v" "s"))
(defun c:vr() ;;Use this to restore Named View created by 'vs' (Type in the name supplied earlier)
(command "-v" "r"))
(defun c:vst() ;;Creates view called 'temp'.
(command "-v" "s" "temp"))
(defun c:vrt() ;;Restores view "temp"
(command "-v" "r" "temp"))

;;ZOOM COMMANDS (z7, z12, ze, za, zp)
(defun c:z7() ;;Zooms (out) 0.7x
(command "zoom" ".7x"))
(defun c:z12() ;;zooms (in) 1.2x
(command "zoom" "1.2x"))
(defun c:ze() ;;Zooms extents, then zooms out 0.9x
(command "zoom" "e" "zoom" ".9x"))
(defun c:za() ;;Zoom all
(command "zoom" "all" "zoom" ".9x"))
(defun c:zp() ;;Zoom previous
(command "zoom" "p"))

;;VPORT COMMANDS (vps, vpr, vps1, vpst, , vpr1, vprt)
(defun c:vps() ;;Save vport with whatever name you want. Use 'vps' to restore
(command "-vports" "s"))
(defun c:vpr() ;;Use this to restore the vport created with prev command.
(command "-vports" "r"))
(defun c:vps1() ;;Saves viewport '1'
(command "-vports" "s" "1"))
(defun c:vpst() ;;Saves viewpot 'temp'
(command "-vports" "s" "temp"))
(defun c:vpr1() ;;Restores vport '1'
(command "-vports" "r" "1"))
(defun c:vprt() ;;restores viewport 'temp'
(command "-vports" "r" "temp"))

;;BREAK COMMANDS (brf, bra)
(defun c:brf() ;;selects 'first' point of entity to 'break'
(command "break" pause "f"))
(defun c:bra() ;;breaks entity at point you select
(command "break" pause "f" pause "@"))

;;UCS COMMANDS (uro, uro90, uro90x, ug, upr, uwo)
(defun c:uro() ;;rotates UCS around z axis
(command "ucs" "z"))
(defun c:uro90() ;;rotates UCS 90 degrees around z axis (Use it for creating side elev, etc)
(command "ucs" "z" "90" ))
(defun c:uro90x() ;;rotates UCS -90 degrees around z axis (Use it for creating side elev, etc)
(command "ucs" "z" "-90" ))
(defun c:ug() ;;creates 'orthographic' ucs. Right-click and select the 'view' you want.
(command "ucs" "g"))
(defun c:upr() ;;restores previous UCS
(command "ucs" "p"))
(defun c:uwo() ;;changes UCS to 'world' UCS
(command "ucs" "w"))


;;LAYER COMMANDS (lnc, lse, lne, lco)
(defun c:lnc() ;;new layer current
(command "-layer" "make" ))
(defun c:lse() ;;makes layer current
(command "-layer" "set" ))
(defun c:lne() ;;new layer
(command "-layer" "new" ))
(defun c:lco() ;;change layer color: use number between 1-255 OR red/green etc.
(command "-layer" "color" ))



TOP 0 Kudos

Rank: 1

zw_admin

Newbie

posts: 0

Registered: 2012-1-14

Message 2 of 7

Some lisp routines for beginners
05-05-2008 02:31 . am | View his/her posts only
Hello, Maker. Thank you! Hopefully, more and more visitors can share their experience on CAD software. Smile
TOP 0 Kudos

Rank: 1

maker

Newbie

posts: 0

Registered: 2008-8-15

Message 3 of 7

  Some lisp routines for beginners
31-05-2008 03:12 . pm | View his/her posts only


Hello,
Just thought I'd attach a version for International language users. It's the first time I'm trying something like this, so I'm no too sure if it works okay. If you're using the "international (/local) version" of Zwcad, please try it and give your comments ;).

To use, just unzip to your Zwcad path (the easiest way is to copy to the Zwcad folder). Load it using "Appload" command. Once loaded, click on "load" button in the "Appload" window. If you 'd like it to load everytime with Zwcad ;), load it in the "startup suite" in the box.


Quick view the "shortcuts" supplied (the actual commands and lisp code is after this block) Smile
***********************************************************
VIEW COMMANDS:
vs - Creates view (name to be supplied by user. Eg 1, 2, 3...)
vr - Restores view (use this to restore view 'name' as supplied in previous command.Eg 1, 2, 3..)
vst - Saves current view as "temp"
vrt - restores view "temp"
[Note copy-paste this bit of code and replace "temp" by "1" or "2"...to create your own view named "1", "2"...etc]

ZOOM COMMANDS:
z7 - Zooms out 0.7x times
z12 - Zooms in 1.2x times
ze - Zooms extents; then zooms out 0.9x
zp - Zoom Previous

VPORT COMMANDS:
vps - Saves current viewport configuration with user-supplied name (eg vp1, vp2...)
vpr - restores named viewport config (as supplied in last command. eg vp1, vp2...)
vps1 - Saves vport configuration as "1"
vpr1 - restores vport configuration "1"
[Note copy-paste this bit of code and replace "1" by "2" or "3"...to create your own vport configurations]
vpst - saves vport configuration as "temp"
vprt - Restores vport "temp"

BREAK COMMANDS:
brf - Selects "first" point of object (entity) to "Break".
bra - Breaks object at selected point.

UCS COMMANDS:
uro - Rotates UCS around z-axis.(Type in rotation angle)
uro90 - Rotates UCS around z-axis by 90 degrees (anti-clockwise, of course ;). Useful e.g. when you want to make Right-side Elevation.
uro90x - Rotates UCS around z-axis by -90 degrees.
ug - Creates "Orthographic" UCS (Front, Back, Right...)
upr - restores Previous UCS (You can use this and "ug" to quickly shift between "Plan view" and "Orthographic View"
uwo - restores world UCS.

LAYER COMMANDS:
lnc - makes new layer and makes it "current" layer.
lse - makes layer current (You'll have to type in the name, unfortunately ;(
lco - changes layer colour (Type in a number between 1-255 (1 is red, 255 is grey...) OR type red, blue...)
********************************************************

THE ACTUAL FILE (I'm afraid to upload the actual file, as there may be a virus in my comp)
please copy-paste this to a "notepad" file as "zwcad-starter.lsp" (without quotes ;)



;;VIEW COMMANDS (vs, vr, vst, vrt)
(defun c:vs() ;;Creates view (of name to be supplied by user).
(command "_view" "_save"))
(defun c:vr() ;;Use this to restore Named View created by 'vs' (Type in the name supplied earlier)
(command "_view" "_restore"))
(defun c:vst() ;;Creates view called 'temp'.
(command "_view" "_set" "temp"))
(defun c:vrt() ;;Restores view "temp"
(command "_view" "_restore" "temp"))


;;ZOOM COMMANDS (z7, z12, ze, za, zp)
(defun c:z7() ;;Zooms (out) 0.7x
(command "_zoom" ".7x"))
(defun c:z12() ;;zooms (in) 1.2x
(command "_zoom" "1.2x"))
(defun c:ze() ;;Zooms extents, then zooms out 0.9x
(command "_zoom" "_extents" "_zoom" ".9x"))
(defun c:za() ;;Zoom all
(command "_zoom" "_all" "_zoom" ".9x"))
(defun c:zp() ;;Zoom previous
(command "_zoom" "_previous"))


;;VPORT COMMANDS (vps, vpr, vps1, vpst, , vpr1, vprt)
(defun c:vps() ;;Save vport with whatever name you want. Use 'vps' to restore
(command "_vports" "_save"))
(defun c:vpr() ;;Use this to restore the vport created with prev command.
(command "_vports" "_restore"))
(defun c:vps1() ;;Saves viewport '1'
(command "_vports" "_save" "1"))
(defun c:vpst() ;;Saves viewpot 'temp'
(command "_vports" "_save" "temp"))
(defun c:vpr1() ;;Restores vport '1'
(command "_vports" "_restore" "1"))
(defun c:vprt() ;;restores viewport 'temp'
(command "-vports" "_restore" "temp"))


;;BREAK COMMANDS (brf, bra)
(defun c:brf() ;;selects 'first' point of entity to 'break'
(command "_break" pause "_first"))
(defun c:bra() ;;breaks entity at point you select
(command "_break" pause "_first" pause "_@"))


;;UCS COMMANDS (uro, uro90, uro90x, ug, upr, uwo)
(defun c:uro() ;;rotates UCS around z axis
(command "_ucs" "_z"))
(defun c:uro90() ;;rotates UCS 90 degrees around z axis (Use it for creating side elev, etc)
(command "_ucs" "_z" "90" ))
(defun c:uro90x() ;;rotates UCS -90 degrees around z axis (Use it for creating side elev, etc)
(command "_ucs" "_z" "-90" ))
(defun c:ug() ;;creates 'orthographic' ucs. Right-click and select the 'view' you want.
(command "_ucs" "_orthographic"))
(defun c:upr() ;;restores previous UCS
(command "_ucs" "_previous"))
(defun c:uwo() ;;changes UCS to 'world' UCS
(command "_ucs" "_world"))


;;LAYER COMMANDS (lnc, lse, lne, lco)
(defun c:lnc() ;;new layer current
(command "_layer" "_make" ))
(defun c:lse() ;;makes layer current
(command "_layer" "_set" ))
(defun c:lne() ;;new layer
(command "_layer" "_new" ))
(defun c:lco() ;;change layer color: use number between 1-255 OR red/green etc.
(command "_layer" "_color" ))










maker2008-05-31 15:45:03
0 Kudos

Rank: 1

dang xuan nguyen

Newbie

posts: 0

Registered: 2011-11-2

Message 4 of 7

  Some lisp routines for beginners
31-05-2008 03:12 . pm | View his/her posts only
I've been using autocad for almost as long as you and have been very interested by LISP programming since then, it has made my working life easier.
Here's my question:
after all this years, I created a custom menu containing what it could be percieved as a CAD Standard that could be used by any office. It is made out of a lot of routines, including LISP.
For some reason, since Autocad 2010, my menu is not responding adequatly. It's like every command works the first time in a drawing and then it stops working. I'm wondering if there is some ''variable'' blocking the way through.
For example; I insert a symbol through a menu routine.. a very simple ''_insert'' command and then it would not insert again..
When I do it manually, it works.
I realized, by doing it manually, that autocad ''alerts'' me about the block being allready inserted and if I would like to redefine it...Could that be blocking my automatic routine?
Thanks

Jenny2011-10-19 10:43:20
0 Kudos

Rank: 1

nero13

Newbie

posts: 0

Registered: 2011-10-31

Message 5 of 7

Some lisp routines for beginners
14-10-2011 08:36 . pm | View his/her posts only
To run a LISP routine
Advanced experience menu level
Do one of the following:
Choose Tools > Load LISP or SDS Application.
Type appload and then press Enter.
In the Load Application Files dialog box, choose the routine you want to run (make sure that it is the only one selected), and then click Load.
Some LISP routines are created in such a way that you can run them by simply typing the name of the routine, or by typing a keyword, directly in the command bar. If nothing happens when you attempt to run the LISP routine from within the Load Application Files dialog box, turn on the display of the command bar or Prompt History window by choosing View > Prompt History Window and look for an entry that is similar to the following:
Loading D:'path'routine.lsp
C:KEYWORD
where D:'path'routine.lsp is the complete drive, path, and file name of the LISP routine. You may need to scroll back several lines in the command bar or Prompt History window to find the lines indicating where the LISP routine was loaded. If you see an entry that looks like this, you can run the LISP routine by typing the name of the routine or keyword appearing after the C drive designation.
For example, if you loaded a LISP routine named drawbox.lsp and see the designation CRAWBOX in the command bar or Prompt History window, you can run the LISP routine by typing drawbox in the command bar.

_______________

Online Backup
Birthday SMS
TOP 0 Kudos

Rank: 1

techcraf

Newbie

posts: 0

Registered: 2011-12-4

Message 6 of 7

Some lisp routines for beginners
04-12-2011 06:41 . am | View his/her posts only
yap1 it is working. thank for this post.
Funny SMS

Birthday SMS

Send Free SMS


TOP 0 Kudos

Rank: 1

ava_lee

Newbie

posts: 0

Registered: 2011-12-5

Message 7 of 7

  Some lisp routines for beginners
31-05-2008 03:12 . pm | View his/her posts only
Thanks for you share!
0 Kudos
© 2012 ZWCAD Software Co., Ltd. All rights reserved. | About ZWSOFT | Privacy Policy | Terms and Conditions | Contact us | Site Map
All trademarks,trade names or company names referenced herein are used for identification only and are the property of their respective owners.