hii, i want to know how to creat a lisp
just as i have some lisp file & i using those but i want to know how i can create a lisp file.
i have attached one lisp file so suggest me like this how i can create my own
plz suggest me thanks lot in advance
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Do an internet search on "learn autolisp". Your question is too broad to answer in a post.
check out some of these on-line lisp tutorial websites:
http://www.afralisp.net/index.php
http://www.jefferypsanders.com/autolisptut.html
http://www.cadtutor.net/tutorials/autolisp/quick-start.php
Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store
Here is a few very basic tips:
1) to get routine work, you need your own command and you create it with your routine.
2) usually all routines contain more than one function, even a command from AutoCAD, ie (COMMAND "ZOOM" "W") taken from you file.
3) Take care with the use of parentheses in your code. They must be in pairs.
Here is a sample from your file.
(defun C:zw() (COMMAND "ZOOM" "W") (princ) )
defun => define a function.
C: => stands for "command"
zw => your own command.
(COMMAND "ZOOM" "W") => the main function in your code.
(princ) => put this at the very end of your code so it makes a silent exit.
After learning the basic task, you may need to think what to do if your code is terminated accidentally.
In many cases, this will unexpectedly change the preset values of system variables in AutoCAD. You then need to add an error handling function in your code. I wiil not give details here at this time. --- You may do a search in the forum for the error handling function later.
Furthermore, conditional statments are used in codes in most of times. The simplest one is the "if" function.
Again here is a sample from your file:
(DEFUN C:SA() (COMMAND "LAYER" "NEW" "SPR HEAD" "C" "201" "SPR HEAD" "") (COMMAND "LAYER" "NEW" "FF" "C" "241" "FF" "") (COMMAND "LAYER" "NEW" "cable" "C" "131" "cable" "") (COMMAND "LAYER" "NEW" "SPR main" "C" "33" "SPR main" "") (COMMAND "LAYER" "NEW" "SPR branch" "C" "100" "SPR branch" "") (COMMAND "LAYER" "NEW" "hose" "C" "20" "hose" "") (COMMAND "LAYER" "NEW" "drain" "C" "145" "drain" "") (COMMAND "LAYER" "NEW" "text" "C" "81" "text" "") (COMMAND "LAYER" "NEW" "Fa" "C" "241" "Fa" "") (COMMAND "LAYER" "NEW" "arch" "C" "8" "arch" "") (COMMAND "LAYER" "NEW" "Fm200" "C" "20" "Fm200" "") (COMMAND "LAYER" "NEW" "ig55" "C" "20" "ig55" "") (COMMAND "LAYER" "NEW" "co2" "C" "20" "co2" "") )
This code creates a bundle of layers by using the command "SA". The question is what if the layers are already exist in the drawing?
In this case you may add an "if" function:
(DEFUN C:SA() (if (not (tblsearch "layer" "SPR HEAD")) (COMMAND "LAYER" "NEW" "SPR HEAD" "C" "201" "SPR HEAD" "") ) (princ) )
It means that the code will only be executed if the layer "SPR HEAD" is not found in the drawing.
HTH
just search for autolisp tutorials on youtube.. here's a basic one by the famous Lynn Allen:
https://www.youtube.com/watch?v=G_QY_iY6gB0
Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store
So assumming you created & saved a file matching the name of the lisp function calling it zw.lsp with the following code:
(defun C:zw()
(COMMAND "ZOOM" "W")
(princ)
)
Next you can use the APPLOAD command to locate the zw.lsp file you created and click on the Load button.
Now back on the AutoCAD Command prompt, you can now execute the command by typing:
ZW
and AutoCAD will start the Zoom Window command requesting you to select the first corner point.
Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store
Follow Paul Li's instructions about loading and using such a file, but.... I would point out that this particular operation does not require an AutoLISP-defined command. The Window option is the default in the Zoom command, without your needing to ask for it. So you can type just Z [AutoCAD's alias for Zoom] and get the same thing as your ZW command.
I would also point out that, though Paul's instructions suggest otherwise, the .lsp file name does not need to match the command name defined in it. [In the case of custom Hatch patterns, it does, but not with Lisp routines.] You could call the file ZoomWindow.lsp if you want, if that makes it easier to know what it is about when looking at a list of file names. And you can define more than one command in one file, so you could [for example] have one file called Zooms.lsp that can contain similar definitions of all the Zoom shortcuts you might want to use, such as your ZW [if you really want to define that], ZP for Zoom Previous, ZE for Zoom Extents, and so on. Use APPLOAD to load Zooms.lsp, and all the commands defined in it will be available -- there is no need to make several separate files for each command, which would all need to be loaded separately.
Hi Shavezkhan,
When I first started, beside this one of course :), I had a lot of help from these websites:
Cheers
@shavezkhan wrote:
...
i want to make 1 songle line to 100 dia mm pipe
from center line 50 one side & 50 another side so for this one how i have to make a code like zw pls suggest something
Try this out, or my OffsetBothSides.lsp [attached]. Study the way they're written, and look up the functions they use in Help, to learn more about how to make such things.