Go Back   Tech Support Forum > Design Forum > Design Discussion & FAQs

User Tag List

Tutorial: 3d autocad shortcuts using autolisp

This is a discussion on Tutorial: 3d autocad shortcuts using autolisp within the Design Discussion & FAQs forums, part of the Tech Support Forum category. program: autocad 14+ level: advanced (for autocad, easy for programers) time: quick this example and others to follow, are designed


Closed Thread
 
Thread Tools Search this Thread
Old 02-20-2006, 06:05 AM   #1
Guest
 
Join Date: Apr 2005
Posts: 1,836
OS:



program: autocad 14+
level: advanced (for autocad, easy for programers)
time: quick

this example and others to follow, are designed to cut 3d modeling time in autocad. These files will be short and consist of autolisp instructions and autocad commands.

here is a colour highlighted view of a LISP file that quickly changes your view to a southwest isometric. essentially all it is doing is using the command "vpoint" with a value of "-1,-1,1" and then zooming 0.9x., but all you'll type is 4 at the command line to run these commands


you can type these out in notepad and save as type txt document, while renaming the file extension as LSP. in this case the name of the file is 4.LSP.

you can also open these in a LISP editor through autocad. type VLISP on the command line and then browse to the file to open, or start a new one. you will get the colour highlights and automatic indents (tabs), which help you visually as you type.

lets start at the top then.

anything to the right of ; will be ignored completely! so use these to put in remarks for yourself or anyone else who might need to look at the file. these can be put anywhere in the file as you will see in the next LSP file i'll upload.

each LISP file starts the same and needs to be contained in parentheses i.e. ( ). hence the ) at the end and if you notice there are only 3 in the first line. also in the first line is
DEFUN C: [letters to run the file, in this case 4] (/ [variables seperated by a space])

there is only one variable is this script and it's 'osm' which will hold the value of the Object Snap Mode. i could have called the variable anything eg 'x' or 'objectsnapmode', but osm is short and to the point.

(defun C:4 (/ osm) explained above...

(setvar "cmdecho" 0) sets the system variable CMDECHO=0. it's not important for the moment.

(setq osm(getvar "osmode")) assigns a numeric value to the variable 'osm' which is the current object snap settings

(command "-osnap" "off") turns off object snaps

(command "vpoint" "-1,-1,1") the diagram shows you the view line trajectory


(command "zoom" ".9x") zooms out a little

actual view you'll get


(setvar "osmode" osm) sets the object snaps back to what it was.

(setvar "cmdecho" 1) sets the CMDECHO=1. again not important at the moment.

(princ) this isn't absolutely needed, but i've always put it in.

) the last parethesis.

remember the code needs to be enclosed in these and this closes it up. all LISP files will end like this. i turn the object snaps off before i use the vpoint and zoom commands, because in autocad14 the view could snap to anywhere and was unpredictable.

so a quick look over it.
DEFUN C: defines this function to be a {C} command line entry.
SETVAR changes an AutoCAD system variable. CMDECHO was the only one changed here.
SETQ (autolisp command) assigns a value to the variable after it - 'osm'.
COMMAND activates the AutoCAD commands that you type at the command line.

these will be used over and over in the next autolisp files. finally how do you load this file? type 'ap' or 'appload' on the command line, then browse to this file and click load. now press 4 and enter - does the view change?

so now you can create the next 3 views, se, ne and nw isometric. you need to copy this file 3 times and rename them 5.LSP 6.LSP and 7.LSP. remember to change the number after DEFUN C:[5, 6 or 7 go here in each LISP file] and also change the vpoints to
(1,-1,1) (1,1,1) and (-1,1,1) respectively. you can load these the same way as you did 4.LSP. so now all you need to type is 4, 5, 6 or 7 to switch to the sw, se, ne and nw isometric views.

the next tutorial will show you how to load these automaticly everytime you start autocad and anymore autolisp files you write. one last thing the keystroke/s you assign to run a lisp file will over ride the autocad shortcut (ACAD.PGP file). e.g 's' is normally assigned to 'stretch' command, so if you had used 's' to tun one of these, then 's' will change the view and not 'stretch'.

lastly i have attached the LISP file to download.
Attached Files
File Type: zip 4.zip (279 Bytes, 166 views)
Inactive is offline  
Sponsored Links
Advertisement
 
Old 03-08-2006, 03:12 AM   #2
Guest
 
Join Date: Apr 2005
Posts: 1,836
OS:


program: autocad 14+
level: advanced (for autocad, easy for programers)
time: quick


okay. i have attached the four LISP files for switching the views from southwest throught to northwest. i've also included a lisp file to automatically load these 4 files and you can add a line for each lisp file you want to load everytime you start or open a autocad file. there are a few things to do for this to happen.


1) create a folder (anywhere you want) and copy the lisp files you want to load along with the TOOLS.LSP into that folder.


2) you need to find and edit the acad.mnl file. it will be in the support folder and that will be either in the root of the autocad install folder or

C:\Documents and Settings\Administrator\Application Data\Autodesk\AutoCAD 2004\R16.0\enu\Support

administrator being replaced with whoever you log in as. you might need tell windows to 'show all hidden files' to find it. open it with wordpad and scroll down to the bottom of the file and put in this line

(load "tools")

just before the very last line which is

(princ)

it's always best to make a copy of any of autocad files before you edit them, but this entry is such a simple one.


3) start autocad and goto to tools>options and under the files tab click on the
'support file search path'
then click on the 'add' button on the right and then browse to the folder that you created and copied the lisp files into. ok this and the next time you open/start a cad file the lisp files specified in the TOOLS.LSP file will be loaded.


so you've created a folder with all your custom lisp files copied in there. you've told the acad.mnl file to load TOOLS.LSP file (which in turn loads the rest of them) and you've added a search path to find the TOOLS.LSP file along with the other lisp files.


at the moment the TOOLS.LSP is loading only four lisp files the 4, 5, 6 & 7 (note the semi-colon in front of the two lines loading 'q' and 'w'. this is to ignore them for this lesson). if you want to load another lisp file, just copy one of the line entries and replace the previous name with the new name. for example you have a lisp file called spring.lsp. then copy the line

(defun C:7 ()(load "7")(C:7))

and replace 7 with spring.

(defun C:spring ()(load "spring")(C:spring))
Attached Files
File Type: zip lisp files.zip (1.4 KB, 138 views)
Inactive is offline  
Old 04-24-2006, 04:16 AM   #3
Guest
 
Join Date: Apr 2005
Posts: 1,836
OS:


assuming everyone (anyone) has gone through the above posts, this is the next one in the sequence. the first one which quickly changed the views but automatically does a zoom extents. that's what happens when you use the command vpoint. so if you are working in a large scene and you need to quickly save/restore a view, that's in close to an object, then this lisp file will do that. i use 2 lisp files using keystrokes q and w to quickly save/restore the views. i never found the need for more than 2.

so when you press q/w it will check to see if the view has already been saved. if it has already a view saved it will ask you to restore it or overwrite it. if you press 'v' it will overwite it with the current view or any other key will restore the one that is already saved. so the commands q and w will save a view called 'view1' and 'view2' respectively. if you have started a new drawing, or have deleted these manually, when you press q or w it will save the view and tell you so at the command prompt. the next time you press q/w it will ask you to restore or overwrite.



the first 'if' uses the autolisp command 'tblsearch' to check the named views for a save called 'view1'. if this returns empty (nill) then it will carry out the instructions following the first 'progn', otherwise it will continue to the next progn and carry out those instructions. 'command' carries out an autolisp command, as you would type it out on the command line. 'prompt' just prints a line of text and the '\n' starts the text on a new line.

the second 'if' statement asks the user for a response. if the user types any other key than 'v' (= "v" input) then the named view will be restored. if they do type 'v' then it will overwrite the named view.

the lisp file 'w' is very similar to this one, only having 'view2' in place of 'view1' and w following the 'defun C:' statement
Attached Files
File Type: zip views.zip (801 Bytes, 101 views)
Inactive is offline  
Sponsored Links
Advertisement
 
Old 05-05-2006, 04:50 AM   #4
Guest
 
Join Date: Apr 2005
Posts: 1,836
OS:



if, like me, you create all of the models in solids you'll find yourself using the slice command alot. i don't like the autocad long version, so i have a lisp file to slice an object(s) on the xy, yz or zx planes. this lisp file will slice on the zx plane, at 0,0,0 or a point of your choice and keep both sides of the sliced object(s).



object is the variable used for the objects picked in the scene. p1 is the point in which to slice them on. osmode is assigned the running object snap setting. again from the release14, i used to turn off the object snap before running the autocad commands. with some commands i found it doing strange things.
the 3rd line i set a mark in the undo command. i never really found it necessary, because the file does so little in the way of commands. essentially if you type 'undo' at the command line and the back - it will undo back to the last found mark.
(setq object (ssget))
the variable object will be set to whatever the ssget instruction returns with. so ssget lets you pick objects in the autocad scene.

(setq p1 (getpoint "\nPick a point on the cutting plane <0,0,0>: "))
similarly p1 will be assigned a point returned with the instruction getpoint. i have <0,0,0> in the text, so if the user doesn't pick a point it will assume that the objects are to be cut at 0,0,0

(command "-osnap" "off")
here i turn off the running object snaps. i could have used the line
(setvar "osmode" 0)
as well. the latter is the binary way to set the object snaps, not as user friendly. note i turn off the object snaps after you pick a point in the scene. it'd be annoying if you were using object snaps and expected to snap to a point using them.

the if command i've covered above, so the first option will slice the objects at 0,0,0 and the second line will slice the objects on the point you picked. this is the part that saves you typing the options in on the command line yourself.

the last 3 lines are the usual, returning the system variables to the appropriate values. i have also attached 2 other lisp files that will slice on the xy and yz planes. these are virtually the same as above, only xy and yz are used in place of zx.

the next lisp file i will post is to set the running object snaps. a very short one, but i find it handy when you cancel the likes of this file midways and find your settings turned off. i also find it quicker to set some snaps rather that using the autocad dialogue box to set them.
Attached Files
File Type: zip slice.zip (1.2 KB, 119 views)
Inactive is offline  
Old 03-17-2007, 01:20 AM   #5
Guest
 
Join Date: Mar 2007
Posts: 1
OS:



hi,

Thank for this tutorial, I jusy learn and want to use it on my works,

I find these tips ware usefule.

Thanks.
alansnoog is offline  
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Photoshop Tutorials
Photoshop Tutorials For Photoshop 6, 7, Cs, Cs2 :) Basic Tutorials For Photoshop Loading Brushes Tutorial Introduction To Layers Tutorial Photoshop Tool Basics Tutorial Complex Shapes Tutorial The Magnetic Lasso Tutorial
crimmer Design Discussion & FAQs 8 05-11-2007 02:04 AM
Video card crashing AutoCAD?!
I've encountered a problem when opening AutoCAD ever since installing my new video card. I upgraded from a 128MB card to an NVIDIA GeForce 5500 256MB OC, and now anytime I open up ANY version of AutoCAD (2004, 2005, 2006, even Architectural Desktop), it crashes. in AutoCAD Arch. Desktop 2005, it...
archi7908 Graphic Design, Digital Imaging, and Multimedia 6 09-01-2006 02:02 PM
AutoLISP
https://i36.photobucket.com/albums/e40/freddyhard/4LSP.gif here is a highlighted view of a LISP file that quickly changes your view to a southwest isometric. essentially all it is doing is using the command "vpoint" with a value of "-1,-1,1" and then zooming 0.9x., but all you'll type is 4 at the...
Inactive Design Team Room 13 02-13-2006 05:09 AM

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is on
Smilies are on
[IMG] code is on
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Post a Question


» Site Navigation
 > FAQ
  > 10.0.0.2
Powered by vBadvanced CMPS v3.2.3


All times are GMT -7. The time now is 10:21 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
vBulletin Security provided by vBSecurity v2.2.2 (Pro) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.1.0 (Pro) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
Copyright 2001 - 2018, Tech Support Forum

Windows 10 - Windows 7 - Windows XP - Windows Vista - Trojan Removal - Spyware Removal - Virus Removal - Networking - Security - Top Web Hosts