Author Topic: PEdit LISP help for a beginner  (Read 10985 times)

0 Members and 1 Guest are viewing this topic.

cparnell

  • Guest
PEdit LISP help for a beginner
« on: November 21, 2003, 06:01:01 PM »
I will take the advice of Daron from my previous post "True Global Attribute Edit" and ask for help to learn LISP from the beginning.
I have been hesitant to learn LISP because I don't have experience with any kind of programming.

Here is my question.
I continuously use the PEdit command and have to constantly type in PE, select my line or PLine, J for join, ALL to complete the process. I would guess that this process could be made into a simple routine to automate this process, by typing in PE for PEdit, select the line or PLine and the routine would take care of the rest.

How do I begin with this routine?

I am familiar with (defun C:CHATTE
chatte is the command line entry.
I am familiar with any thing behind; is not acknowledge in the routine. It is used for notes.

I will follow-up with Darons suggestions and look at the web sites that he suggested.

Thanks for any help.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
PEdit LISP help for a beginner
« Reply #1 on: November 24, 2003, 07:10:41 AM »
Using Lisp, the simple way of doing just what you want, would be to identify the command line flow for the pedit command using join as the option.

This should be a quiick and dirty way to cut some time.
Code: [Select]

(defun C:PJ() ;;define the function
(princ "\nSelect plines to join: ");;prompt the user
(setq a (ssget));;select the plines
(setq b (ssname a 0));;retrieve a base line
(command "_.pedit" b "j" a "" "");;enter the command line options
(princ);;exit quietly
);;we are done
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

cparnell

  • Guest
PEdit LISP help for a beginner
« Reply #2 on: November 24, 2003, 08:01:19 AM »
KEB:

Where can I find definitions to the code terms that are used in this routine?
Such as
defun - DEfine FUNction?
"\nSelect plines to join" - I figured out that this is a prompt on the command line. How does this relate to princ which is before it on the same line?
princ -
(setq a (ssget))- Selection Set get?
(setq b (ssname a 0)- Selection Set NAME?
(command "_.pedit" b "j" a "" "") - I believe I understand that the routine is using the pedit command to continue the routine. What does " b "j" a "" "" mean? I noticed that there are spaces between " letter and ". I would guess that J is for join and A for all. But I have not figured out B.

Thanks for your assistance. I have a long way to go.

I have not followed up with Darons suggestion on visiting web sites to assist me in learning LISP, but I will.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
PEdit LISP help for a beginner
« Reply #3 on: November 24, 2003, 08:12:08 AM »
The best reference to autolisp functions is in your ACAD install folder under Help\acad_dev.chm.

i.e.
C:\Program Files\AutoCAD 2000\Help\acad_dev.chm
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
PEdit LISP help for a beginner
« Reply #4 on: November 24, 2003, 08:28:38 AM »
cparnell, I sugest that you do. He gave you a link to a  great lisper. (Whom, i am very happy to have on this fourm. ) You see, SMadsen teaches me stuff all the time without posting anything more then code; I keep saying that "you" should run each line of code and see what happens, but i dont think you guys take me seriously. You learn so frickin' much when you test, play arround and inspect each expression it would be stupid not to do so.  

...Ahe, sorry this is turning into a bitch session, but the point is still made; Test and inspect each expression. Especially when your new to the language. Dont just take the books word on it.  That's advice that you should take and use when you start learning lisp and even when you get "good" at lisp. Theres always stuff you learn when you 'mess arround' with code.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
PEdit LISP help for a beginner
« Reply #5 on: November 24, 2003, 08:39:11 AM »
Ok, you are on the right track.

You have adequately described the functions, but let me elaborate on their function a bit.

DEFUN is the process of defining the function, it (or DEFUN-Q) must be used to define the name of the function. All command line functions defined in lisp will have the C: preceeding the  function name. This lets the lisp interpreter know to process the program from the command line.

SSGET is the selection set collection command. It allows the user to select autocad entities, there are a variety of options that can be used with this command. Here we simply used it to create a collection of objects that the user selects. We simply stored the selection set in variable A.

SSNAME returns the name of a single object from a selection set. The syntax is (SSNAME SelectionSet ItemNumber) Note that all selection sets are numbered from 0 not 1. So what we are doing here is retrieving the name of the first entity in the selection set that is stored in A, and putting that in variable B.

COMMAND is a lisp call to execute an internal autocad command. You must supply the command line parameters or provide for the user to input them. We are passing the information already gathered. The arguments are as follows:

"_.pedit" = the command
b = the individual pline to be used in the pedit command
"j" = join
a = the selection set
"" = a required enter to close the selection set
"" = a required enter to close the pedit command

The command line is as follows:
Command: pedit
Select polyline:
Enter an option [Close/Join/Width/Edit vertex/Fit/Spline/Decurve/Ltype
gen/Undo]: j
Select objects: Specify opposite corner: 2 found
Select objects:
1 segments added to polyline
Enter an option [Close/Join/Width/Edit vertex/Fit/Spline/Decurve/Ltype
gen/Undo]:

Hopefully this explains it a bit better.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
PEdit LISP help for a beginner
« Reply #6 on: November 24, 2003, 09:33:29 AM »
Also note that when, in this case a or b, strings are not set within quotes, the lisp interpreter see's them as variables and uses the info stored in the variable. So, if either of them were set to nil the command sequence would look like this:
Code: [Select]
(command "_.pedit" nil "j" nil "" "")
Don't test that. That is how the interpreter might see it, not how you would write it. Neither variable should be set to nil and the function would crash.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
PEdit LISP help for a beginner
« Reply #7 on: November 24, 2003, 09:40:20 AM »
Thank you Daron for pointing that out. I obviously forgot that cparnell wanted to learn from the beginning. I should not have assumed anything.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
PEdit LISP help for a beginner
« Reply #8 on: November 24, 2003, 09:41:01 AM »
I hope it doesn't confuse the issue.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
PEdit LISP help for a beginner
« Reply #9 on: November 24, 2003, 09:42:33 AM »
Also note the '_' and the '.'(dot) in the call to pedit as shown as
Code: [Select]
(command "_.pedit"
The '_' adds foreign language support, and the '.'(dot) is used to avoid redefined commands.

Quote
If you develop AutoLISP programs that can be used with a foreign language version of AutoCAD, the standard AutoCAD commands and keywords are automatically translated if you precede each command or keyword with an underscore (_).

(command "_line" pt1 pt2 pt3 "_c")
If you are using the dot prefix (to avoid using redefined commands), you can place the dot and underscore in either order. Both "._line" and "_.line" are valid.
TheSwamp.org  (serving the CAD community since 2003)

cparnell

  • Guest
PEdit LISP help for a beginner
« Reply #10 on: November 24, 2003, 09:48:29 AM »
Thanks to all for your input. I have not had a chance to read all of your input, but will when I get caught up today. I guess I'm on my way to learning LISP. Any other suggestions as to how to learn LISP and where I can get other LISP tutorials would be greatly appreciated.
Thanks again.

daron

  • Guest
PEdit LISP help for a beginner
« Reply #11 on: November 24, 2003, 10:01:05 AM »
The best way I've found to do it is to have a need and ask for help in writing it. That's how I learned it. Also note, from Mark's addition of breaking down the _.pedit, it's a good idea to at least put the "." in always. There are some routines we've used here for a long time and when I loaded ADT4, they wouldn't work quite like they should. They made a layer in this fashion. (command "layer" blah blah blah). The routine worked fine, except the object wasn't on the right layer. In desktop, there is a new layer manager and it uses the command line layer, redefined to load its dialog form and its command structure. So, if I want to force the native layer structure, I have to add the dot.