Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

to creat a lisp

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
shavezkhan
890 Views, 14 Replies

to creat a lisp

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

14 REPLIES 14
Message 2 of 15
dbroad
in reply to: shavezkhan

Do an internet search on "learn autolisp".  Your question is too broad to answer in a post.

Architect, Registered NC, VA, SC, & GA.
Message 4 of 15
BeKirra
in reply to: shavezkhan

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

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
Message 5 of 15
shavezkhan
in reply to: dbroad

ok i will try thanks....sir
Message 6 of 15
shavezkhan
in reply to: paullimapa

thankssssss sir
Message 7 of 15
shavezkhan
in reply to: BeKirra

sir
firstly we have to create a code than it will run for lisp or what
how we will make a lisp by the code how it will run for lisp can you explain by video or send me any video link where i can see
how to crete a code than after code how we make lisp
Message 8 of 15
paullimapa
in reply to: shavezkhan

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


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 9 of 15
shavezkhan
in reply to: BeKirra

thnaks sir
(defun C:zw()
(COMMAND "ZOOM" "W")
(princ)
)
i try to make it as you explain
& make also this lisp but how it will work i mean which command i put there
Message 10 of 15
paullimapa
in reply to: shavezkhan

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


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 11 of 15
Kent1Cooper
in reply to: shavezkhan

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.

Kent Cooper, AIA
Message 12 of 15
dicra
in reply to: shavezkhan

Hi Shavezkhan,

 

When I first started, beside this one of course :), I had a lot of help from these websites:

 

http://www.afralisp.net/

http://www.lee-mac.com/

 

Cheers

Message 13 of 15
shavezkhan
in reply to: paullimapa

sir
one more thing now i want to creat a lisp for offset command
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
Message 14 of 15
Kent1Cooper
in reply to: shavezkhan


@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.

Kent Cooper, AIA
Message 15 of 15
dicra
in reply to: shavezkhan

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost