Jump to content

Recommended Posts

Posted (edited)

Hi, there, im very new working with Autolisp, in the past i copy and paste code and use the lisp. Thanks to all the people who write this lisp.

Now im learning how to code with lisp, i m reading books, developers guide and this forum. I need to understand how some commands works for use it in the lisp code. I cant find a description of how command works. For example (command "xref" "r"). But i know this command have more options, i need the description of the other options and how can i use it.

 

(defun c:CircC () (command "._circle" "0,0" "3,3")

(command "._thickness" 1)

(command "._circle" PAUSE PAUSE) (princ) )

 i want to know how circle command works "0,0" is the origin point "3,3" is for ??

 

 

Screenshot_3.png

Edited by ASQ
  • ASQ changed the title to where can i find the "commands" and how it works in lisp
Posted

COMMAND in AutoLISP executes an AutoCAD command. It's just like typing the text that follows at your command prompt. Every space between the arguments is like pressing Space or Enter.

 

A good way to write your COMMAND argument is to enter it at your command prompt. If it works there, it will work in AutoLISP.

  • Like 1
Posted

There are a lot of ways to work it out.

 

If it is a standard AutoCAD command then the help and AutoDESK help will tell you what it all does.

 

Some commands can be used from the command line - and they are ideal for LISP. Some commands can only be used via a dialogue box, which can be useful but you can't automate that part. Some commands can be run both ways, command line and dialogue box - command line is good for automation. typically if a command can be run both ways you can get it to run via the command line with a '-' prefix. For example -plot will step through plotting via the command line.

 

To use a command like that you want (command "-yourcommandhere-" -andthing else that is needed here). Yourcommandhere is the command name and any '-' prefx necessary to make it work via the command line.

 

Anything after that is what is needed to make the command work, and you can work out what is needed by running the command in CAD and noting down everything you type, including 'enter'. Type that into the LISP as you go - you;ll pick it up quick enough. One tip that might be useful is if you need a user input you can use pause instead of some information

 

To make things worse there are other ways to do everything, possibly quicker than 'command', but you'll get to that soon enough. I think most of us started as you are doing and copying from the command line to a LISP.

 

In your example, I'll type in 'circle' in the command line and it returns

'specify centre point for circle or [3P 2P TTR (tan tan radius) ]'

I'll pick a point, or enter a point 0,0 - now this is text so when I make up the LISP later I'll remember to put it in " "

'Specify radius of circle or diameter'

So now I can enter a point as before, or a value, or even pick a point

and that is the command complete

 

So make that into a line for a LISP:

(command to start to tell the LISP what is about to happen

"0,0" - my centre point

pause - I decided I wanted the user to pick a point on the radius. In your example the "3,3" is a point, a point on the circumference to select the radius

 

(command "circle" "0,0" pause)

 

Might be that you have a centre point already selected, you can replace anything in the command with a variable.

Try these 2 lines:

 

(setq pt (getpoint "Select circle centre point") ; pt is a variable (; on code means comment afterwards)
(princ pt) ; princ means display in the command line
(command "circle" pt 5) ; make a circle centred on pt with a radius of 5

 

  • Like 1
Posted
3 hours ago, CyberAngel said:

COMMAND in AutoLISP executes an AutoCAD command. It's just like typing the text that follows at your command prompt. Every space between the arguments is like pressing Space or Enter.

 

A good way to write your COMMAND argument is to enter it at your command prompt. If it works there, it will work in AutoLISP.

Thanks for the advice, yes actually i copy some part of the code to the command line and test it, if it works, i can continue, if dont,  i look for the error. 

Posted
2 hours ago, Steven P said:

There are a lot of ways to work it out.

 

If it is a standard AutoCAD command then the help and AutoDESK help will tell you what it all does.

 

Some commands can be used from the command line - and they are ideal for LISP. Some commands can only be used via a dialogue box, which can be useful but you can't automate that part. Some commands can be run both ways, command line and dialogue box - command line is good for automation. typically if a command can be run both ways you can get it to run via the command line with a '-' prefix. For example -plot will step through plotting via the command line.

 

To use a command like that you want (command "-yourcommandhere-" -andthing else that is needed here). Yourcommandhere is the command name and any '-' prefx necessary to make it work via the command line.

 

Anything after that is what is needed to make the command work, and you can work out what is needed by running the command in CAD and noting down everything you type, including 'enter'. Type that into the LISP as you go - you;ll pick it up quick enough. One tip that might be useful is if you need a user input you can use pause instead of some information

 

To make things worse there are other ways to do everything, possibly quicker than 'command', but you'll get to that soon enough. I think most of us started as you are doing and copying from the command line to a LISP.

 

In your example, I'll type in 'circle' in the command line and it returns

'specify centre point for circle or [3P 2P TTR (tan tan radius) ]'

I'll pick a point, or enter a point 0,0 - now this is text so when I make up the LISP later I'll remember to put it in " "

'Specify radius of circle or diameter'

So now I can enter a point as before, or a value, or even pick a point

and that is the command complete

 

So make that into a line for a LISP:

(command to start to tell the LISP what is about to happen

"0,0" - my centre point

pause - I decided I wanted the user to pick a point on the radius. In your example the "3,3" is a point, a point on the circumference to select the radius

 

(command "circle" "0,0" pause)

 

Might be that you have a centre point already selected, you can replace anything in the command with a variable.

Try these 2 lines:

 

(setq pt (getpoint "Select circle centre point") ; pt is a variable (; on code means comment afterwards)
(princ pt) ; princ means display in the command line
(command "circle" pt 5) ; make a circle centred on pt with a radius of 5

 

Thanks for answer, yes im reading this book, and starting for the basic, setq, if, princ, alert, getpoint.  I ll try pause for inputs, and set values to a variables. 

 

This is a simple code that works for me, i dont want to type xr then select the missed reference then click on found path at and choose the file, you know. Always trying to avoid boring and repetitive task  😅

(defun c:refcpb ()
(command "xref" "p" "20230630 MAG ARCH BASE PB ASQ r0" "MAG ARCH BASE PB ASQ r0")
(princ)
)

 

Screenshot_14.png

Posted

Kindle has some excellent books also, very cheap, look for Reinaldo N Togores. Another good reference is Afralisp has tutorials.

Posted

Some commands you can set FILEDIA and/or CMDDIA to 0 to suppress the dialog box if there is no "-" alternative.

 

You may be interested in looking into AutoCAD Scripts and the Action Recorder if you haven't already.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...