TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: amgirard2003 on November 03, 2003, 05:21:55 PM

Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 03, 2003, 05:21:55 PM
What up everyone?
A newbie here to the world of Lisp and just wanted to check in and let you all know that i am completely lost!!  :?
I've recently been doin a lot of reading and working on a little routine..
I currently don't have the file with me but i'll post it tomorrow from work.
I'm lookin for any help possible..
Would like to keep it as simple as possible as i am a beginner..

Take a look tomorrow for my little routine and any help would be greatly
appreciated..

Thanks,
Andre
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 03, 2003, 05:27:28 PM
Hello Andre,
Welcome to a world of fellow lispers (well, in here at least)

Looking forward have a look at your routine.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: hendie on November 04, 2003, 04:10:31 AM
welcome Andre,
it's good to have a new face around the forum.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 04, 2003, 07:57:27 AM
Here's my little routine...
I'm looking for comments and suggestions on how i can improve my coding..
If you could e-mail me back at amgirard2003@yahoo.com with a revised copy of my file that would be great...

Code: [Select]
;New Command: Newline
;Purpose is to set linetypes and layer upon selection of a new line
;to be drawn.

;Code in English

;Prompt User: "Select Linetype: Three Phase, Double Phase, Single Phase, Secondary, 600/347V, 120/208V
;Variable Answer = User Input

;if Answer = T (Three Phase) then
;Linetype = Three Phase
;Layer = 612
;Lwpolyline

;if Answer = D (Double Phase) then
;Linetype = Double Phase
;Layer = 612
;Lwpolyline

;if Answer = Si (Single Phase) then
;Linetype = Single Phase
;Layer = 612
;Lwpolyline

;if Answer = E (600/347V) then
;Linetype = Hidden
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline

;if Answer = F (120/208V) then
;Linetype = Custome Linetype
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline

;************************************************************
;************************************************************

;Coding

(defun c:nl (/ answer oldblip oldlayer oldplinewidth oldortho)
(initget 1 "Three Double Single seCondary E600 F208")
; Prevents the user from responding to the request by entering only ENTER
(setq answer (getkword "\nSelect Phase: Three/Double/Single/seCondary/E600/F208 <> "))
 oldblip (getvar "blipmode"); set old variable to variable for call back
 oldlayer (getvar "clayer"); set old variable to variable for call back
 oldplinewidth (getvar "plinewid"); set old variable to variable for call back
 oldortho (getvar "osmode"); set old variable to variable oldortho for call back



(cond ((= answer "seCondary") ; Secondary
    (setvar "plinewid" 0.5); set polyline width to 0.5
  (setvar "clayer" "622"); set layer to 622
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
        (princ answer)
      )
     
      ((= answer "Three") ; Three Phase
      (setvar "plinewid" 0); set polyline width to 0
  (setvar "clayer" "612"); set layer to 612
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
(princ answer)
      )

      ((= answer "Double") ; Double Phase
      (setvar "plinewid" 0); set polyline width to 0
  (setvar "clayer" "612"); set layer to 612
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
(princ answer)
      )

      ((= answer "Single") ; Single Phase
      (setvar "plinewid" 0); set polyline width to 0
  (setvar "clayer" "612"); set layer to 612
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
(princ answer)
      )

      ((= answer "E600") ; 600/347V
      (setvar "plinewid" 0); set polyline width to 0
  (setvar "clayer" "622"); set layer to 622
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
(princ answer)
      )

      ((= answer "F208") ; 120/208V
      (setvar "plinewid" 0); set polyline width to 0
  (setvar "clayer" "622"); set layer to 622
  (setvar "osmode" 0); set orthomode to off
  (setvar "blipmode" 0); set blips to off
(princ answer)
      )
)

(princ)


)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 04, 2003, 08:32:52 AM
Quote from: amgirard2003
If you could e-mail me back at ...
No way, you asked for it in public, now you're getting the comments in public, too :D

Before suggesting any changes, here are some questions and comments:

- You say that the routine is for changing the linetype, yet I don't see where it changes the current linetype?
- Are you sure that you want to force the user to hit escape in order to exit from the routine without doing changes? INITGET 1 is for very rare cases where input is essential for further processing. It's not for irritating the user.
- You forgot to include the initial oldxxx assignments in a SETQ
- Are you sure you want to force OSMODE and BLIPMODE to 0? If that is the case, why are you saving their current values?? It's not necessary, either, to save the current values of CLAYER and PLINEWID if your intention is that the routine will change them.
- Setting OSMODE and BLIPMODE to 0 within all conditions are unnecessary repetitions.
- If setting OSMODE and BLIPMODE to 0 and leaving them that way is NOT intentional, then you need to include code that restore their values.
- What will happen if the layers are not present in the drawing when using CLAYER to set a layer currently active? (if you include CELTYPE to change the current linetype then the same question applies)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 04, 2003, 09:34:59 AM
Also, why are you supplying the answer back to the user when the user knows what he supplied. Also, using the "or" expression for conditions that have the same body results, like single, double and three will help you keep your code short and easier to read. Ex.
Code: [Select]
((or (= answer "Double")
      (= answer "Single")
      (= answer "Three")
 )
(setvar 'clayer 612)
);end condition


That is an example of how to use the "or" expression. Do consider what SMadsen said about existing layers and everything else.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 04, 2003, 09:40:40 AM
*smadsen holds a hand for his mouth and whispers discretely, ahem, don't you mean OR, Daron?*
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 04, 2003, 09:42:41 AM
DOH! I'll go change it. It's early, here. Thank you. I was reading the code that was supplied and thinking to myself that condition 1 and 2 and 3 are all the same, so I put my thoughts down without thinking about what would happen in the code.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 04, 2003, 09:54:02 AM
WO WO WO WO... Hold on horses...
Like i said i'm a NEWBIE.... everything you are tellin me i should do and not do is complete chinese to me... I'm not understanding what you are tellin me.. Remember this is the first time i've ever written any kind of programming code... I know by your experience that you're lookin at this thing and sayin what a joke this is.. I'm lookin for some guidance and to take some small steps.. I don't want to be runnin a mile when i'm not ready for it.

- You say that the routine is for changing the linetype, yet I don't see where it changes the current linetype?

   Well i haven't gotten to that point... i don't know how to use tables to determine if linetypes have been defined or not, and how to create them if there not defined.


- Are you sure that you want to force the user to hit escape in order to exit from the routine without doing changes? INITGET 1 is for very rare cases where input is essential for further processing. It's not for irritating the user.

  I don't understand what you're tellin me with this comment

- You forgot to include the initial oldxxx assignments in a SETQ

  Like the previous comment... don't understand what you're sayin

- Setting OSMODE and BLIPMODE to 0 within all conditions are unnecessary repetitions.

  I understand that i've repeated this part over and over but don't understand code syntax so i don't have to re-itterate the same code over and over


- If setting OSMODE and BLIPMODE to 0 and leaving them that way is NOT intentional, then you need to include code that restore their values.

  I haven't gotten to that part... the routine as you can see is FAR from being done.


- What will happen if the layers are not present in the drawing when using CLAYER to set a layer currently active? (if you include CELTYPE to change the current linetype then the same question applies)

  Again... i know there's error traping that i will have to develop but again don't know how to develop that at this moment..



To finish this off... I don't want anyone to take it in the wrong manner.. Like i said i'm a NEWBIE to the world of programming...
I'm lookin for all the help i can get to help me learn this, As there's no places around where i live that offer courses in LISP..

Thanks for your input.

Andre

P.S- is there any way to add attachments to this forum?




[/b]
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Mark on November 04, 2003, 10:02:16 AM
Quote
P.S- is there any way to add attachments to this forum?

No, but as a member of TheSwamp you are allowed to use the lilly pond to upload/download files if you wish.
http://theswamp.org/lilly.pond/
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 04, 2003, 10:16:04 AM
Quote from: amgirard2003
everything you are tellin me i should do and not do is complete chinese to me... I'm not understanding what you are tellin me.. Remember this is the first time i've ever written any kind of programming code... I know by your experience that you're lookin at this thing and sayin what a joke this is.. I'm lookin for some guidance and to take some small steps.. I don't want to be runnin a mile when i'm not ready for it.
No need to run a mile. Take what you can now, ask questions about it and come back for more (often). I'm sure there will be plenty of comments your next time around.

Quote
- Are you sure that you want to force the user to hit escape in order to exit from the routine without doing changes? INITGET 1 is for very rare cases where input is essential for further processing. It's not for irritating the user.

  I don't understand what you're tellin me with this comment

1 (bit 0)  Prevents the user from responding to the request by entering only ENTER. There's the help file on initget 1. Now the question: What if the user decides he doesn't want to change anything after invoking this command? Can he hit enter to get out of it clean? You are forcing your user to hit escape to get out of it, which is bad practice.

Quote
- Setting OSMODE and BLIPMODE to 0 within all conditions are unnecessary repetitions.

  I understand that i've repeated this part over and over but don't understand code syntax so i don't have to re-itterate the same code over and over

Instead of changing variables inside each condition, you can change them before the conditional statement, unless they are needing to be changed to different values as a result of the condition. Ex. would be osmode. In some cases you might feel that it's better to give the user nothing but nearest or in other conditions you might want end/int.

Quote
Again... i know there's error traping that i will have to develop but again don't know how to develop that at this moment..



To finish this off... I don't want anyone to take it in the wrong manner.. Like i said i'm a NEWBIE to the world of programming...
I'm lookin for all the help i can get to help me learn this, As there's no places around where i live that offer courses in LISP..

Error trapping? You've got a better start than when I got started. Initget is a good error trapping tool as is cond. As far as places to learn, many of us here will help you get through problems as you ask them.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: hendie on November 04, 2003, 10:23:49 AM
Quote from: amgirard2003
... I know by your experience that you're lookin at this thing and sayin what a joke this is.. I'm lookin for some guidance and to take some small steps..

No  we are not treating this as a joke by any means ~ we all started somewhere (and some of us haven't travelled far from that point yet !)

lets take a step back for a moment. Lay aside the code you have written for the time being. Now what would really be helpful is pseudo-code defining what you want to do step by step.
That will let us see what you are trying to do. Then we can take it a step at a time.
pseudo code is something like:
Quote

prompt use for type of line
get current variables
if line type 1 then
    set these variables
    check for layer and linetype
    do this code
    [/list:u]
    or if line type 2 then
      set those variables
      check for layer and linetype
      do this code
      [/list:u]
      or if line type 3 then
        set those other variables
        check for layer and linetype
        do this code
        [/list:u]
        restore variables
        and exit

get the drift ?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 04, 2003, 10:32:02 AM
No offense Hendie, but I thought he did a fairly decent job of pseudo-coding it. Not complete, but what is ever complete in the initial thinking of code? Here's the p-c he originally stated
Quote
;Code in English

;Prompt User: "Select Linetype: Three Phase, Double Phase, Single Phase, Secondary, 600/347V, 120/208V
;Variable Answer = User Input

;if Answer = T (Three Phase) then
;Linetype = Three Phase
;Layer = 612
;Lwpolyline

;if Answer = D (Double Phase) then
;Linetype = Double Phase
;Layer = 612
;Lwpolyline

;if Answer = Si (Single Phase) then
;Linetype = Single Phase
;Layer = 612
;Lwpolyline

;if Answer = E (600/347V) then
;Linetype = Hidden
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline

;if Answer = F (120/208V) then
;Linetype = Custome Linetype
;Linetype Scale = 0.5
;Layer = 622
;Lwpolyline


It could definately use some updating and complete direction for a finish, but it's better than I ever did when I got started. Heh, I still hate writing that stuff. I feel like I can write the code just as fast as I could write the p-c, most of the time.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: hendie on November 04, 2003, 10:38:29 AM
none taken, it's just that (I thought) I'd read he hadn't got to a few things yet so wondered if there was anything that we should be aware of at this time (just in case)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 04, 2003, 11:02:36 AM
I have a sugestion; Why dont you comment your code as well as you can. Read, evaluate, and look up as much as you can. Comment everything you can as we will tell you if your right/wrong/close/ etc. and offer help from there.  We are here to teach you. Test everyline and ask any questions you have. We are not here to pick on you, we are here to give you the oppertunity to create the best code out there.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 04, 2003, 11:10:19 AM
Code: [Select]
(defun nl (/ answer oldblip oldortho)
(initget 0 "Three Double Single seCondary E600 F208")
(setq answer (getkword "\nSelect Phase:Three/Double/Single/seCondary/E600/F208 <> "))
  oldblip (getvar "blipmode)  
  oldortho (getvar "osmode)
  (setvar "osmode" 0)
  (setvar "blipmode" 0)

(cond ((= answer "seCondary") ; Secondary
    (setvar "plinewid" 0.5); set polyline width to 0.5
  (setvar "clayer" "622"); set layer to 622
  (princ answer)
      )


I don't know where i'm goin with this.. but give some time to get this into my head..

Does this look a little better??
I took out the setting of variables within the condition and put it before the condition takes place...


7Edit: I added the code tags to your post.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 04, 2003, 11:18:18 AM
O.k another quick question...

Because i don't understand the syntax too well and still tryin to understand what i read i'm confused to why the routine is not setting the next variables

I figured out how to use the debugging options and place a couple breakpoints...

(cond ((= answer "seCondary") ; Secondary
          (setvar "plinewid" 0.5); set polyline width to 0.5
        (setvar "clayer" "622"); set layer to 622
        (princ answer)
      )

after it finds the first line and reads it it goes to the next but doesn't set "plinewid" to 0.5 and "clayer" to 622...
am i missing somethin in the code?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 04, 2003, 11:18:24 AM
Alright just some formatting issues with that code bit.
I have commented the code where you made some formatting mistakes.
Code: [Select]
(defun nl (/ answer oldblip oldortho)
(initget 0 "Three Double Single seCondary E600 F208")
(setq answer (getkword "\nSelect Phase:Three/Double/Single/seCondary/E600/F208 <> "))
(setq oldblip (getvar "blipmode") ;;<- You forgot the "setq" and the closing dbl quotes.
      oldortho (getvar "osmode")) ;;<- You forgot the closing dbl quotes and to
                                  ;;   close the "setq" statment.
  (setvar "osmode" 0)
  (setvar "blipmode" 0)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 04, 2003, 11:20:31 AM
How much programing experience do you have. (In any language?)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 04, 2003, 11:20:55 AM
Andre,
If it is your intention to leave OSMODE and BLIPMODE set to 0 then yes, you might as well do it in one place instead of repeating it in each condition.
However, if the user regrets to having issued the command and exits the routine, then it will have changed the users environment unexpectedly, which is not so polite.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 04, 2003, 11:29:53 AM
When you talk about programming experience let's just say that i was always that turned my head to the idea of ever learning anything about it..

But after working with a consultant for a few months and saw what he did with the autocad system where i work i was blown away and now has me itchin to learn this...

So no experience at all, except for the books i've picked up the last few months.. " Autocadet's guide to Visual Lisp", "Autolisp in Plain English" and
"Autolisp Treasure Chest"
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 04, 2003, 11:48:42 AM
How far have you gotten in those books? Im asking you because i wanted to know if you truly want to learn or do you just want a couple bits of code?  (and thats cool too; we have a few people like that here. They just want the code and are upfront about it. Thats fine by me.)  If you want to learn, ill toss you a few links to get you started. (And if you want code, ill toss you a few links to get started too :)~ )  But i think we could make this program your "intro" and teach you the right way, right-away. But i suggest starting over so you can understand each and every line in your code.  Up for it?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 04, 2003, 11:53:08 AM
Well then, if I were you I'd go to www.dsxcad.com and download the VisuaLisp developer's bible so you can get to it later.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 04, 2003, 11:55:11 AM
Se7en,

Let's start this buggy up because my whole intent is to learn...
I'm lookin for bits of code to put somethin together... I wanna learn
how to write and what things i should keep in mind when i write code.

"Autolisp in Plain English":- I've read that about 5 times now.. I know what you're thinkin... but it's an old copy dating back to version 9 of autocad.. and i know a lot of things have changed since then..

The other 2 I've read a few chapters and section but havin some trouble understandin...

I've found a few websites and have done a lot of readin..
Afralisp is one i enjoy.. I've downloaded the manual for Autolisp and have been goin through that, the only problem i have with that manual is that it jumps too much...

So i'm up to learnin to answer your question...
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 04, 2003, 12:04:58 PM
w00t! Good, glad to have you abord the lisp train! Alright lets get started.

If your looking for a nice intro the lisp world; our SMadsen has a very nice intro, and is very much so, worth reading. I would at least check it out. Its  on SMadesen's page under the "Primer" section. You can get to it by visiting here: http://www.smadsen.com/ and clicking on the "primer" link on the left.

The next thig i would do is to develop "pseudo code" and tell us  what you want for a program. (remeber we are starting over and giving you a fresh new program.)  

Example Psuedo Code:  (this is actualy one of mine for an idea i was working on.)
Quote
;;; Pseudo code for the circle leader program                         ;
;;;-------------------------------------------------------------------;
;;; - Select an entity.                                               ;
;;; - Test if block.                                                  ;
;;;    - If it is, dive in.                                           ;
;;; - Get second point.                                               ;
;;; - Calculate polar point of circle/arc                             ;
;;; - Get third point (the tail)                                      ;
;;;   ~ I would calc this, but I dont want to assume the              ;
;;;     direction of the tail/text.                                   ;
;;; - Prompt the user for text strings.                               ;
;;;   ~ I could use a simple dialog box for this.                     ;
;;;   ~ I could just start the dtext command after prgn complete.     ;;
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 04, 2003, 12:06:44 PM
To illustrate some points from the previous comments, consider the code below.

As for COND and why it doesn't proceed further than the condition, please look up COND in the help reference or in one of your books. Sometimes it helps to read up on a function in an isolated way just to get a clear picture of its specific behavior.

Code: [Select]
(defun c:nl (/ answer oldblip oldlayer oldplinewidth oldortho)

  ;;sm: Removing the "1" in INITGET allows GETKWORD to return nil, which
  ;;sm: means that the user simply hit enter or space (an empty input)
  (initget "Three Double Single seCondary E600 F208")
  ;;sm: ^Therefore, we have to test if GETKWORD was given an input
  ;;sm: This can be done by wrapping it all into one CONDition:
  (cond ((setq
           answer (getkword "\nSelect Phase: Three/Double/Single/seCondary/E600/F208 <> ")
         )
         ;;sm: OK, user gave an input that we can use.
         ;;sm: Now proceed. Set the environment and check the input.
         ;;sm: If the user hit enter, the code will not have gone
         ;;sm: this far and it will not be able to set his/her
         ;;sm: system variables (it is still inpolite to change
         ;;sm: them but that's another story :)
         (setvar "osmode" 0)
         (setvar "blipmode" 0)

         (cond ((= answer "seCondary") ; Secondary
                (setvar "plinewid" 0.5) ; set polyline width to 0.5
                (setvar "clayer" "622") ; set layer to 622
                (princ answer)
               )
               ;;sm: Using Daron's suggestion of collecting all identical settings:
               ;;sm: (if you have plans of adding other statements to the conditions
               ;;sm: then please keep your existing structure!)
               ((or (= answer "Three") ; Three Phase
                    (= answer "Double") ; Double Phase
                    (= answer "Single") ; Single Phase
                )
                (setvar "plinewid" 0) ; set polyline width to 0
                (setvar "clayer" "612") ; set layer to 612
                (princ answer)
               )
               ;;sm: Again, using Daron's suggestion:
               ((or (= answer "E600") ; 600/347V
                    (= answer "F208") ; 120/208V
                )
                (setvar "plinewid" 0) ; set polyline width to 0
                (setvar "clayer" "622") ; set layer to 622
                (princ answer)
               )
         )
        )
  )
  (princ)
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 04, 2003, 12:18:37 PM
Thanks for all the comments...
I really do appreciate all the help..

se7en,

I will check out the site and do some readin and i will develop
some pseudo code and i will re-post when i am done..
I will try and get back and post it as soon as i get it done.

Thanks again,

Andre

P.S- Lookin forward to clearing the smoke and starting fresh..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 04, 2003, 02:33:37 PM
Under direction of se7en i'm starting over..
I've done some reading and have re-compiled my
routine with some better pseudo code for your understanding


Pseudo Code

-Prompt User: "Select Phase: Three,Double,Single,Secondary,600/347V, 120/208V
-use a keyword for each selection
          - Three = T
          - Double = D
          - Single = S
          - Secondary = C
          - 600/347 = E
          - 120/208V = F

;if user inputs T (Three) then
;Linetype = Three Phase
;Layer = 612
;Color = Bylayer


;if user inputs D (Double ) then
;Linetype = Double Phase
;Layer = 612
;Color = Bylayer

;if user inputs S (Single) then
;Linetype = Single Phase
;Layer = 612
;Color = Bylayer

;if user inputs E (600/347V) then
;Linetype = Hidden
;Linetype Scale = 0.5
;Layer = 622
;Color = Bylayer

;if user inputs F (120/208V) then
;Linetype = Overhead Secondary
;;Layer = 622
;Color = Bylayer

;if user inputs C (Secondary) then
;Linetype = Bylayer
;Layer = 622
;Color = Bylayer
;Plinewidth = 0.5

;after variables are set, the pline command is
launched with all the settings that are required.

;once the user is done drawing a line the routine will reset all variables
to original settings so the routine can start from a fresh start again.

;if user inputs nil (enter) then
; routines exits.


se7en,
I await your response.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 04, 2003, 03:34:17 PM
First I would like you to explaine in your own words what a variable is. Then i would like you to explain what a function is. And how the two tie together.

Nothing fancy, just the basics.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 04, 2003, 06:46:08 PM
In my own words

A variable is where data can be stored ( Numbers, Strings, lists, other variables)

A function is a set of commands you give to the routine to tell it what to do.

A function calls on variables so it can pass through the routine.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 04, 2003, 09:19:45 PM
Correct (sort of. Lets clean those thoughts up a bit. They were good, I just want to make sure you think of it 'this' way.)

A variable is basically a "container" of sorts. A function is a set of processes and  returns a value --A procedure--. When you define a variable you are essentially associating a name that identifies a variable which has a value.

You define a name by using "setq".
-e.g. (setq a 1)

We have just named the value "1" to the name "a".

So theoretically, we can test a value and perform a process --or set of processes-- based on the results.

Taking the information we have just learned, let's create a function that returns a True/False value. We are going to create a procedure that will return either True or False based on the value of a test.  Side note: This procedure will be a procedure you can use over and over again in many programs you create over the years so you should keep track of this procedure. (I have a system that seems to work for me. I keep a file I call my "Utils" file that holds all my finished products and I also keep a "Junk" file for my daily program scratchings. I suggest devising a system of your own and sticking to it.)

I'll start with an easy one so I don't loose you sofar. How about a function to test to see if a layer exists in the drawing?

Start a new drawing and run this line of code in either the command line or the VLIDE and see what it returns.
(tblsearch "layer" "0")

What does it return? How do you think we can make a procedure return either true or false using this function? HINT: Find a function that will return True or False. -e.g. Daron used the "or" function earlier, what task does it preform?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: hendie on November 05, 2003, 03:54:22 AM
I don't want to side track anybody or anything but wouldn't this topic be better served in the Teach Me forum ?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 07:44:05 AM
(tblsearch "layer" "0")
Returns this:
((0 . "LAYER") (2 . "0") (70 . 0) (62 . 7) (6 . "Continuous"))
which in turn means true.. it found a layer that = 0

Using the OR function that Daron had mentioned earlier will check all the variables that are within that function, once it finds a match you then tell the routine where to go from there...

Pseudo Code
(or(tblsearch "layer" "0") ;then go to step 1
    (tblsearch "layer" "1") ;then go to setp 2
    (tblsearch "layer" "2") ;then go to step 3

Is this what you were looking for?
To Hendie's previous message.. if you want to move this to the Teach Me forum i don't have a problem with that..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: hendie on November 05, 2003, 08:01:20 AM
Quote from: amgirard2003
...will check all the variables that are within that function, once it finds a match you then tell the routine where to go from there...

partly correct. ~ it will search within that function for a match
Code: [Select]
(or
   (tblsearch "layer" "0")
   (tblsearch "layer" "1")
   (tblsearch "layer" "2")
)

will return TRUE if any of Layer "0" OR Layer "1" OR layer "2" are found.
i.e. if only layer 0 is present and layer 1 & layer 2 are NOT present it will still return TRUE
and if all 3 layers are present it will return TRUE. it will only return NIL if none of the layers are present
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 08:41:11 AM
Correct. The "or" expression evaluates its arguments and returns True for the first non-nil argument it finds.

If you guys want me to I'll split this thread. But I was only trying to demonstrate Smadsen's and Darons points.

OBTW, My department just got a big job that is kinda fast paced untill the 60% review. (In a couple of days.) So I prolly wont be able to put as much detail into my posts, ok?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 05, 2003, 08:47:09 AM
Quote from: hendie
... i.e. if only layer 0 is present and layer 1 & layer 2 are NOT present it will still return TRUE
Actually, you wouldn't know if layer 1 and/or layer 2 are present if layer 0 is present (so it might not be a perfect test in every case)   :wink:
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 09:07:25 AM
Alright I want you to do some testing here. Let's set up some variables and give each a value.

(setq a 1 b 2 c nil)

As you can see I set the "c" varialble to hold the value of "nil". (In other words; its "empty") This is for testing purposes only.

Now run these processes:
(or a b c)
(or a)
(or b)
(or c)
(and a b c)
(and a)
(and b)
(and c)
(not a b c)
(not a)
(not b)
(not c)

Let me know if you can come up with a procedure of your own to test to see if a layer exists in the drawing.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 09:08:07 AM
Quote from: SMadsen
... Actually, you wouldn't know if layer 1 and/or layer 2 are present if layer 0 is present (so it might not be a perfect test in every case)   :wink:
:lol: I was thinking the same thing.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 10:07:35 AM
(or a b c) = True
(or a) = True
(or b) = True
(or c) = nil (false)
(and a b c) = nil (false)
(and a) = True
(and b) = True
(and c) = nil (false)
(not a b c) = too few arguements ( What does this mean? )
(not a) = nil (false)
(not b) = nil (false)
(not c) = True

That's one check to see if it exists
(if
   (tblsearch "layer" "0") ;then go to step 1
*******************************************************
(if (not
        (tblsearch "layer" "0") ; then go to step 1 and create new layer
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 10:21:09 AM
Quote from: amgirard2003
...
(not a b c) = too few arguements ( What does this mean? ) ...


Oh im sorry.  :oops:  I cut and pasted when i shouldnt have. The "not" expression only excepts one argument and we suplied it three.  (Sorry 'bout that, but i guess it was a good test anyways. --It helps you see that you cant use "not" to test all three values. :lol: )

Your getting the idea. But how about taking a steping back and just creating a function to test if the layer exists.  We'll work on a conditional expression in a second.

Here look this over and make sure you understand it.
Code: [Select]
;;;===================================================================;
;;; Layer-p                                                           ;
;;;-------------------------------------------------------------------;
;;; Determines if a layer exists in drawing.                          ;
;;;                                                                   ;
;;; Arguments: Layer - The name of a layer.(In string format.)        ;
;;;                                                                   ;
;;; Returns: "T" if the layer was found, "nil" if not.                ;
;;;                                                                   ;
;;; Date: 10.5.03                                                     ;
;;;===================================================================;
(defun layer-p (layer)
  (and (tblsearch "LAYER" layer)))
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 05, 2003, 10:22:22 AM
Quote from: hendie
I don't want to side track anybody or anything but wouldn't this topic be better served in the Teach Me forum ?

Nope, and I think you understand why now.

Quote from: Se7en
As you can see I set the "c" varialble to hold the value of "nil". (In other words; its "empty")

It is empty, but something has happened to the value of c. Here's a test to run and tell me what your findings are:
(setq a 1 b 2 c nil)
(setq a (append c a b))
(setq a (append c (list a b))

Why does the first append not work and the second append does? The fact that I make a list of value a and b is the obvious answer. The question I want answered is what makes c so special that it doesn't need to be listed?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: hendie on November 05, 2003, 10:25:35 AM
yup
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 10:36:54 AM
O.k... little confused here..
I started a new drawing..
I've gone into Vlide

I've gone into my drawing and created a layer called "andre"

So in the code you've given me

(defun layer-p (layer)
   (and (tblsearch "layer" layer)))

I've replaced layer with andre

(defun layer-p (andre)
   (and (tblsearch "layer" "andre")))

now how do i test this to see if it comes out true?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 10:39:08 AM
tblsearch
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 10:42:38 AM
(layer-p "andre")

You don't need to change (layer) to (andre) as (layer) is just a name for the required argument (i.e. what layer you're looking for).

Try running this

(layer-p)

and you'll get this from AutoCAD:

Quote
; error: too few arguments
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 05, 2003, 10:48:25 AM
(defun layer-p (layer)
(and (tblsearch "layer" layer)))

What you do with that is:
(layer-p "andre")
That then will find and return the layer "andre".
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 10:59:02 AM
O.K got it now..

Question

(defun layer-p (layer)

In the line above, what is (layer) signifying?

If i'm frustrating you I'm really sorry... just really new to all of this and like i've said i have no programming background what so ever...
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 11:32:53 AM
An "object".

The "layer" represents an argument to the procedure. The "layer-p" procedure needs an object to perform its process on.

Daron, now I'm not entirely sure about this but... (Smadsen, do you know for sure?) When you create a variable name associated with the value of "nil" you are doing two things; One allocating space for a variable and two, destroying it. So as I see it, the variable 'c' is created and destroyed. By telling the interpreter that we are defining a new variable named 'c' we are telling it to allocate memory space for it, but then when we assign it to a value of 'nil' that tells the interpreter to destroy it. So the 'c' variable is nothing more then a flash in the pan.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 11:34:48 AM
When you define a function ('(defun layer-p...') you can add arguments to your function by including the variable name for your argument in the parentheses following the function name. When you write a LISP routine you are going to set variables. Having one of your variables as a required argument essentially requires that the person running the function set the variable for you.

(defun layer-p (layer)

simply says that when a user runs the function layer-p they'll need to supply an argument to go along with it. The argument that they supply will be the value of a variable called, in this instance layer. So, later on in the function, it will do a tblsearch of the layer named with the value of the variable supplied by the user.

In english, the function is doing this 'Check to see that a layer exists in this drawing.'

Naturally, the function needs to know what layer you are referring to so the argument is, in english 'Which layer am I looking for?'

It could have easily been written as

(defun layer-p (required_argument)

Using 'layer' as a variable name is, in my opinion, a bad habit. I try to never name any variable in any of my functions with terminology common to Autocad.


The same can be done for checking a plethora of items like a block:

Code: [Select]
(defun Block-Exists (x)
(and (tblsearch "Block" x))
)



or a text style:

Code: [Select]
(defun TxtStyle-Exists (x)
(and (tblsearch "style" x))
)


or a dimension style:

Code: [Select]
(defun DimStyle-Exists (x)
(and (tblsearch "Dimstyle" x))
)


In those three examples the variable x is the argument provided when running each function. So, in the 'Block' function the second line is doing this, in english:

Check the drawing to see if there is a block named whatever the value of the variable x is in it.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 11:50:21 AM
I understand that better... was a little confused there for a minute

Couldn't you do this as well

(defun layer-p ()
  (tblsearch "layer" "x"))

Not pass a variable and just let tblsearch function look for the layer x

If it finds it then it will result in being "TRUE"
if not then "NIL"

what are your thoughts?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 11:56:55 AM
Absolutely.

Having it as a variable makes the function more versatile, though.

You may be looking for layer 'x' today but tomorrow you may want to search for layer 'z'. And if you intend on writing a function for each separate layer that you want to search for it would be simpler to not make the function in the first place and just run

(tblsearch "layer" "x")

(tblsearch "layer" "y")

(tblsearch "layer" "z")
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 12:03:38 PM
Conditional expressions:

The "if" expression allows us to evaluate a value and preform a process based on the results.

(if [predicate] [consequent] [alternative])

If the Predicate is TRUE then do the consequent, else do the alternative.
Code: [Select]
(if
  (Layer-p "612")                 ; <- Predicate
  (setvar "clayer" "612")         ; <- Consequent
  (command "layer" "m" "612" "")  ; <- Alternative    
 )


The "cond" expression lets us evaluate and preform a set of process if the value evaluates to "True".

(cond [predicate] [consequent] [predicate] [consequent] ...)

If the Predicate is TRUE then do the consequent.
Code: [Select]
(cond
  ((Layer-p "612")                 ; <- Predicate
   (setvar "clayer" "612"))        ; <- Consequent
  ((not (Layer-p "612"))           ; <- Predicate
   (command "layer" "m" "612" "")) ; <- Consequent
 )


Code: [Select]
(cond
  ((Layer-p "612")
   ;; If the layer "612" is present in the drawing
   (setvar "clayer" "612"))
   ;; Then set the curent layer to "612"
  ((not (Layer-p "612"))
   ;; If the layer isnt found
   (command "layer" "m" "612" ""))
   ;; Then create it and set it curent
 );_ end conditional expression


Reason to choose "cond" over "if":
A point was made to me by another lisper a bit ago that the use of the "if" expression is fine and dandy but there are better more flexable solutions out there. The point he made was that; "What happens if you decide to preform some more processes later down the road? You would need to reformat your procedure to accomodate them." That was a good point, and that point alone is worth remebering when you design a program. I've tried to get out of the habit of using the "if" expression.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 12:07:10 PM
So in this case

(defun layer-p (/ x)
  (or (tblsearch "layer" "x")
       (tblsearch "layer" "y")
       (tblsearch "layer" "z")
  )
)

x would be a passed value by user entering something when prompt to do so..

Ex. Asking the user what layer to create?
     The user would enter y

     y is then passed to x
     tblsearch looks for a match to value of x = y
     if y exists which would result in being True
     then user would be prompt with " Layer already exists.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: RCJDavis on November 05, 2003, 12:08:02 PM
You know I don't post much, I mostly lurk and read, but wow this is making so much sense.  You guys are going through this with a fine tooth comb.  It should almost get stickied when done, as a great reference of where to begin.  Thanks to everyone who's working on this I am learning so much!
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 12:12:36 PM
Another reason, posed to me by the person who taught me about 'cond':

What if, in your infinite wisdom, you hadn't considered something that the user might have done? Your lines and lines of possible scenarios within those if/then statements would be useless.

'Cond' lets you cover all of the bases by adding a final predicate of 'T' which, essentially, means 'if none of my other predicates are true, do this instead'.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 12:32:02 PM
Quote from: amgirard2003
So in this case

(defun layer-p (/ x)
  (or (tblsearch "layer" "x")
       (tblsearch "layer" "y")
       (tblsearch "layer" "z")
  )
)

x would be a passed value by user entering something when prompt to do so..

Ex. Asking the user what layer to create?
     The user would enter y

     y is then passed to x
     tblsearch looks for a match to value of x = y
     if y exists which would result in being True
     then user would be prompt with " Layer already exists.


No.

Actually, placing the x after the '/' changes it completely. The function won't be requiring anything from the user.

Required arguments are placed before the '/'.

Check your books and try to find out what the purpose of placing them behind that slash is.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 12:36:07 PM
placing a variable after the / makes it local to that function
placing it in front of the / makes it global.. so therefore other function could refer to the variable..

am i right or wrong on this one?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 12:41:58 PM
Close.

You're correct about the local variables. Placing it behind the slash 'empties' that variable once the function is complete.

Placing a variable before the slash declares it as a required argument.

Making a variable global is as simple as not including it in the list following the slash. A mistake that many novice programmers make.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 05, 2003, 12:42:57 PM
Quote from: Se7en
Daron, now I'm not entirely sure about this but... (Smadsen, do you know for sure?) When you create a variable name associated with the value of "nil" you are doing two things; One allocating space for a variable and two, destroying it. So as I see it, the variable 'c' is created and destroyed. By telling the interpreter that we are defining a new variable named 'c' we are telling it to allocate memory space for it, but then when we assign it to a value of 'nil' that tells the interpreter to destroy it. So the 'c' variable is nothing more then a flash in the pan.


Yes, you allocate memory space for it, but you are also defining it. If you run my three line question on it, the first line sets the variable to nil. The second line (the first append) crashes. The third line runs okay. I stated why I changed a and b to a list, but I'll clarify: They are integer values, or strings, or longs, or whatever, but they are NOT a list. The value of c is nil. What else is it? It works in an append situation without being called as a list, even though there is nothing to append to. So, I ask again, when you define a variable as nil, what is the object (container) of c? What does c become? Not nothing. Not destroyed. Not a flash in the pan.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 12:49:49 PM
Originaly posted by Daron,
Yes, you allocate memory space for it, but you are also defining it. If you run my three line question on it, the first line sets the variable to nil. The second line (the first append) crashes. The third line runs okay. I stated why I changed a and b to a list, but I'll clarify: They are integer values, or strings, or longs, or whatever, but they are NOT a list. The value of c is nil. What else is it? It works in an append situation without being called as a list, even though there is nothing to append to. So, I ask again, when you define a variable as nil, what is the object (container) of c? What does c become? Not nothing. Not destroyed. Not a flash in the pan.
***********************************************************

Wouldn't c always = nil... not empty, not a flash in the pan, not destroyed
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 12:52:00 PM
Code: [Select]
(defun var-test ( / va vb vd vf)
(setq va "A"
      vb "B"
      vc "C"
      vd "D"
      ve "E"
      vf "F")
)




Copy and past that into AutoCAD  and run the function by typing this on the command line

(var-test)

Now, after it's been run type the following on the command line and watch what the results are:

!va

!vb

!vc

!vd

!ve

!vf


on a side note: typing an exclamation point followed by a variable name will tell you what the value of that variable is. This can be helpful when writing LISP
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 12:52:35 PM
nivuahc,

I think i get it... I think as we get into it more that it will click in...
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 12:59:36 PM
I see what happened... the variables after the / va vb vd vf were not assigned a value..
Variables vc ve were assigned a value..

I'm confused as to why that happened..

I was under the impression that when you used the
(setq) to give a value to a variable, the variable would then = that
value

 :?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 05, 2003, 01:02:59 PM
Quote from: amgirard2003
Wouldn't c always = nil... not empty, not a flash in the pan, not destroyed


I'm not asking for the value of c. We supplied that. What is c that it works in append? Here's the help file on append. Maybe I'm a confusing teacher, but this should give up the answer.
Quote
append Function
 



Takes any number of lists and appends them together as one list

(append [list ...])

Arguments

list

A list.



Again, what is the empty object (container) of the variable of C?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 01:06:57 PM
Quote from: amgirard2003
I see what happened... the variables after the / va vb vd vf were not assigned a value..
Variables vc ve were assigned a value..

I'm confused as to why that happened..

I was under the impression that when you used the
(setq) to give a value to a variable, the variable would then = that
value

 :?


Actually, all of those variables were assigned values.

The ones listed after the slash were 'emptied' after the function completed but the ones not included in that list retained their value thereby making them global variables.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 01:14:51 PM
From what i've read is it better to stay away from
global variables because you can make the mistake
and have other functions call on those variables?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 01:19:26 PM
As I see it Daron, 'c' is a name bound to a value of 'nil' nothing more. The space allocated for the Variable is reclaimed by the processor but the value of the name 'c' is left as 'nil'. So we have a "phantom" variable.  ...I think.  
(I mean this is kind of beyond me, theory wise. But, I can’t think of any other explanation.)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 01:26:31 PM
Now this should really bake your noodle:

Code: [Select]
(defun local-test ( / va vb)
  (setq va "A")
  (setq vb "B")
  (princ (strcat "\nThe value of va is " va))
  (princ (strcat "\nThe value of vb is " vb))
  (princ)
)


Before you run that, set the values of va and vb to something else

(setq va "Z" vb "X")

Now test the values of each

!va

!vb

Now before we run our function above, what result do you think you will get?

Try it and let's see

(local-test)



Now we're going to test the values of each of our variables again. Again, before you do, what result do you think you will get?

!va

!vb



Care to take a shot at why that happens the way it does?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 01:38:11 PM
Quote

code:
--------------------------------------------------------------------------------
(defun local-test ( / va vb)
  (setq va "A")
  (setq vb "B")
  (princ (strcat "\nThe value of va is " va))
  (princ (strcat "\nThe value of vb is " vb))
  (princ)
)

Now we're going to test the values of each of our variables again. Again, before you do, what result do you think you will get?

!va

!vb



Care to take a shot at why that happens the way it does?
--------------------------------------------------------------------------------

O.k let me see if i get this one right for a change...

When the routine begins it sets Z to va and X to vb..
It then prints "The value of va is Z"
                  "The value of vb is X"
and then exits..
Why i think this happened is because it printed the values of va and vb to the screen before exiting and clearing the variables..

Correct??
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 01:41:29 PM
Did you try it out?

Because I think you'll be surprised when you do.


Also, I just wanted to mention... I'm loving this.

I remember what I was like when I started all of this and I love to see lightbulbs go off.

And, amgirard2003, don't feel bad if you don't fully grasp all of this right away.

Having no one to teach me, and relying solely on old books and old code to teach myself, I plugged along writing LISP for at least 4 years before I understood the difference between local and global variables.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 01:44:38 PM
nivuahc

You can call me by my first name which is Andre
amgirard is my full name... Andre, Michel, Girard

I know it will take some time to get this all to plug into my head
I'm here to learn and i want to learn all of this...
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 01:55:53 PM
I get what your saying Daron. I see your point now. Your saying that when we assign 'c' to 'nil' we are creating an empty list.

That would make sense; Seeing as (setq c nil) is the same as saying (setq c '())  That's a cool lesson. Theres a lot to think about there.  *huh*
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 01:57:01 PM
From the Autocad command line (emphasis added):

Quote
Command: (defun local-test ( / va vb)
(_>   (setq va "A")
(_>   (setq vb "B")
(_>   (princ (strcat "\nThe value of va is " va))
(_>   (princ (strcat "\nThe value of vb is " vb))
(_>   (princ)
(_> )
LOCAL-TEST

Command: (setq va "Z" vb "X")
"X"

Command: !va
"Z"

Command: !vb
"X"

Command: (local-test)

The value of va is A
The value of vb is B

Command: !va
"Z"

Command: !vb
"X"


When you make a variable local, you make it local to the function that you used it in.

The variables va and vb are global variables that you set at the command line using

(setq va "Z" vb "X")

When you run the function (local-test) you set variables va and vb, local to the function, to A and B respectively. As local variables, they are 'emptied' when the function ends. But the variables that you set globally at the command line retained their value.

Doing this

Code: [Select]
(defun local-test ( / )
  (setq va "A")
  (setq vb "B")
  (princ (strcat "\nThe value of va is " va))
  (princ (strcat "\nThe value of vb is " vb))
  (princ)
)


would change the value of our global variables because they are not local to this function (notice that they are no longer following our slash). So when you test the variable values at the command line after running this function, you'll get a different result.

Quote
Command: !va
"A"

Command: !vb
"B"
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 05, 2003, 01:57:35 PM
When I started I had no book on lisp and still don't. I did have someone teach me things, but only if I'd ask questions. This left a lot in the air for me. I understood how things worked and when, but not why. Since April, under Se7en's tutilage, I've learned many new things. With that book and the tutilage you'll get here you should be able to avoid bad pratices as well as become a good lisp programmer at a rapid pace. It took me forever to understand functions and the power of the list and list iteration tools.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 05, 2003, 02:15:40 PM
Quote from: Se7en
I get what your saying Daron. I see your point now. Your saying that when we assign 'c' to 'nil' we are creating an empty list.

That would make sense; Seeing as (setq c nil) is the same as saying (setq c '())  That's a cool lesson. Theres a lot to think about there.  *huh*

Yup, and what is LISP? LISt Processor. What else uses lists? foreach. Took me forever to understand how to use that one. I used repeat all the time. I'm learning in my vba book that there are three types of loops, determinate, indeterminate and infinate. Don't use infinate.
Types of determinate loops in lisp are repeat and while.
Types of indeterminate loops are foreach and vlax-for.
The difference in ability is the determinate loops run through a sequence a specified number of times. They also don't require lists to process.

indeterminate loops require lists or (vla-objects) to process and loop for as long as there is a list in the list collection. It doesn't matter how many items are in the collection, it just runs them until it's done.

The reason I bring this up is that I didn't understand what it took to get the indeterminate loops to work until Mark helped me understand that I wasn't supplying lists to the function.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 02:16:20 PM
I think i see where you're goin with it... so anything that is set within the function will make that variable local to that variable..

If you have many functions that are dependent on the same variable then make it global so other functions can reference them..

Just to add a note... I had never heard of Autolisp and Visual Lisp till about 6 months ago.. I've been using autocad for 10 yrs now. just shows my ignorance to learning new things when i was younger..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 05, 2003, 02:20:06 PM
Wow, 10 years and you hadn't heard of lisp. I heard of it as soon as I started learning AutoCAD. I also heard a few people voice their displeasure with programming in general. I for one, find it fascinating.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 02:28:56 PM
Yeah i know tell me about it..
Now i totally regret it never hearing about it.. cause i now have the itch to learn programming.

After seeing what the consultant did i was blown away... amazing what he did with reactors and stuff...

And that's why i'm here... i found a forum that's willing to help...
All othe rforums i've gone too have either ignorant people that tell you to figure it out yourself or people that don't answer to your posts.

I'm glad i found this forum... I've learned more in one day than i have in like weeks of reading the books that i have.

Whatever you feel is next to teach or show me please feel free to begin
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 02:47:46 PM
I know what you mean!

For me, when I first started using CAD I was given a task to do. Me and another drafter had to insert two columns of terminal blocks on a drawing, numbered sequentially and continued on the next sheet.

In other words, sheet A might have terminal blocks 1 through 200 on it and sheet B had terminal blocks 201 through 400 on it etc...

Our terminal block was a rectangle with a single attribute in the center. We had to insert one, assign the number, insert the next, assign the number and so on.

Using Autocad R9, it took us 8 hours to do 2 sheets a piece. And that's not including drawing the wiring or labels.

I did that for about 2 days and was ready to pull my hair out.

I just knew there had to be a better way.

I asked everyone I knew and someone told me I oughtta look into LISP.

I bought a book (still have it and it's great) and tore into it. It took me the better of 2 weeks to write a routine that cut the time it took to do one drawing to about 2 minutes. Needless to say my boss at the time was very happy. So happy, he let me take advantage of any of my 'down time' to learn whatever I wanted so long as it pertained to my job.

I posted that routine, slightly modified, to the Show Your Stuff forum and you can check it out here (http://theswamp.org/phpBB2/viewtopic.php?t=82)

And, as you can see, even after doing this for 13 years... I still have a lot to learn.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 02:51:50 PM
Just wanted to post that i work till about 3:30 so if i don't get back to soon after you post your message i'll either check later on in the night or the following day..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 02:55:08 PM
Ive started my job in late '99. Ive been lisping for about three years now.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 03:02:51 PM
So what do you feel is the next thing on the list that i should get a grasp on?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 03:04:42 PM
Are you all caught up? Do you understand the conditional expressions?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 03:14:35 PM
I believe i understand the conditional..
Are there other ones that i should be concerned with?

I know this sounds dumb but i think this will kinda help me out quite a bit..

How about some little test as we go along on the different topics?

Give me a problem and i'll try and figure it out on my own and see how i do.. but keep in mind that i'm still learnin..

what are your thoughts?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Mark on November 05, 2003, 03:24:03 PM
Quote
I'm glad i found this forum... I've learned more in one day than i have in like weeks of reading the books that i have.

I think I speek for all of use here, thank you.

And if you don't mind I might quote you. :D
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 03:25:34 PM
here, here
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 03:34:15 PM
Dont worry about the other conditionals yet. (You'll understand them in time.)

A small test:
Create a function called "PutLayer" that accepts an argument of a layer name and sets the current layer. Use the procedure I supplied and a conditional expression.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 03:48:00 PM
A test you say?

How about this:

First, download this drawing (http://www.nivuahc.is-a-geek.com/downloads/lisp-test.dwg) (right-click, save as)

This drawing has 6 stick-figure characters from Star Wars in it.

Each character has a name and a layer corresponding to their name.

Some of these characters have a weapon. Their weapons are drawn with polylines and are on the same layer as the character themselves.

So if Luke has a weapon it will be drawn with a polyline and the polyline will be on layer 'Luke'.

Your task, should you choose to accept it, is to write a routine that will determine which characters have weapons and which characters do not.

First, figure out, using LISP, what the characters names are.

Then figure out, using LISP, which characters have weapons.

That should be a good place to start.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: M-dub on November 05, 2003, 03:51:58 PM
LMAO!!!  :lol:
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 03:59:59 PM
Hey, no need to be boring, right? :D

By the way, hang on to this drawing because we can use it for other tests in the future. :)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 04:06:07 PM
Sounds like a good idea. Wadd-ya got sofar?!
(I have almost all of the pseudo code "worked out" in my head already.)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 05, 2003, 05:00:19 PM
Quote from: Se7en
Sounds like a good idea. Wadd-ya got sofar?!
(I have almost all of the pseudo code "worked out" in my head already.)



Same here, pseudo code and all, but I'm waiting for our student to show what he comes up with before spilling the beans. :D
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 05, 2003, 05:12:35 PM
Thats a little advanced for him, lets have him just stick to the other one. Maybe you could issue that as a little chalenge to the other coders out there. You might even get a couple cool functions out of the chalenge.  (see if there are any takers and have a little contest.)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 05, 2003, 06:19:01 PM
I think we should get him thinking about manipulating and using lists before throwing him into ActiveX. We've got about five or so different topics. Should we split some up to make everybody's thought a little more easy to read?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 05, 2003, 08:12:57 PM
Sorry guys, my autocad at home is giving me some errors so i can't work on
anything here... something about "HARD ERROR" , "INTERNAL STACK" problem... don't know what that means...

So i'll get to it tomorrow morning and see how i do..

Sorry about that...
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 08:01:47 AM
Mornin All,
Ready for another day..

O.k. here's the Pseudo Code first,

-The user would enter the name of the function followed by the name of the layer.
-Conditions would be :
  1) If the layer currently exists then just make that layer the current layer

  2) If the layer doesn't exists then create that layer and make it current..

- Exit the program

I'll post the code shortly..

Code: [Select]

(defun putlayer (layer)
(tblsearch "layer" "layer")
  (cond ((putlayer "layer")
         (setvar "clayer" "layer")
         (not ((putlayer "layer"))
                (command "layer" "m" "layer" ""))
  )
)


O.k. everytime i run this code i'm getting a Stack Error?

Am i even close?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 06, 2003, 08:57:03 AM
Are you close? No.  Try again.

Use the previous procedure i did as an example. Your procedure should not be any harder, or complicated, then the conditional i supplied.


EDIT: Oh, try to get in the habit of just re-writing instead of debugging these small procedures. (Its small, and should be faster to just re-write it, then to find a bug.)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 09:13:42 AM
O.K

let's try this again...

Code: [Select]

(defun putlayer (x)
  (tblsearch "layer" x))



o.k this works so far...

now the second part is confusing me a little... everytime i do somethin i get
an internal stack error which is getting very annoying cause it keeps booting me out of autocad..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 06, 2003, 09:23:39 AM
Can you give some info on your system, i.e. ACAD version, Windows OS, etc.

Also Se7en, have you taught him about recursive functions yet, or is that just a newbie error? I didn't even know about them and have never made that mistake, but my vba book mentions them and talks about them being useful in very few instances as well as usually done out of error from lacking user knowledge.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 09:25:23 AM
Windows 2000 NT
Autocad Map 5
2.0 GHZ Pentium 4
512 RAM
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 06, 2003, 09:31:24 AM
That's the one giving you errors? Have you ever done a repair from the add/remove programs utility in windows?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 09:36:28 AM
Command: _vlide Hard error occurred ***
internal stack limit reached (simulated)
*** INTERNAL ERROR: VL namespace mismatch
type y to reset:

That's the error i get
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 06, 2003, 09:44:46 AM
Andre, the error comes from the recursion in your code. It's an internal stack overflow that isn't allowed to grow into dangerous proportions (normally). Don't worry about it - it will go away when Se7en points you in the right direction
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 09:47:58 AM
O.K then that's a good thing to know..

Well i'm obviously going in the wrong direction and have no idea where i'm goin

Beyond these 2 lines i don't know how to put it together..
I'm lost... In my head i know what i have to do but i just don't know
how to write it out in syntax.

(defun putlayer (x)
  (tblsearch "layer" x))
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 06, 2003, 09:56:54 AM
Heres the previous procedure that we came up with.
Code: [Select]
;;;===================================================================;
;;; Layer-p                                                           ;
;;;-------------------------------------------------------------------;
;;; Determines if a layer exists in drawing.                          ;
;;;                                                                   ;
;;; Arguments: Layer - The name of a layer.(In string format.)        ;
;;;                                                                   ;
;;; Returns: "T" if the layer was found, "nil" if not.                ;
;;;                                                                   ;
;;; Date: 10.5.03                                                     ;
;;;===================================================================;
(defun layer-p (layer)
  (and (tblsearch "LAYER" layer)))


Here is the "putlayer" pocedure. Go thru this code and understand it all.
Code: [Select]
(defun PutLayer (layer)
  (cond
    ((Layer-p layer)
     (setvar "clayer" layer))
    ((not (Layer-p layer))
     (command "layer" "m" layer ""))
    )
  (princ)
 )
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 09:59:04 AM
Why isn't tblsearch being used this time?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 06, 2003, 10:11:43 AM
Quote from: amgirard2003
Why isn't tblsearch being used this time?
What does the "tblsearch" expression do?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 10:18:53 AM
k i'm totally confused now..

I was under the impression that if you wanted to determine if a layer existed or not, u had to use the tblsearch function, so it could look through the drawing for that layer.
And then after that you would go into your conditionals

Wow... talk about a few yards back instead a few steps forward.

Sorry guys...
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 06, 2003, 10:21:01 AM
Thats exactly what we are doing.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 06, 2003, 10:25:30 AM
Don't be sorry. I think you answered the question. Three alligators for you. So, what do you mean we're not using t(a)bl(e)search. It's embedded in the layer-p function. Aren't you using that. Looks like you use it in the cond argument to determine if the layer exists or not and returns T or NIL. There is one problem with it, though. It's missing a dot. Can you tell me where?
Code: [Select]
(command "layer" "m" layer "")
Written like this the program could crash if it gets to this point. It might work fine in Vanilla Cad, but in vertical platforms, not using a dot or hyphen has different result than Vanilla Cad. So, it's a good idea to use a dot or hyphen. Where's it needed?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 10:31:32 AM
Quote from: Daron
Don't be sorry. I think you answered the question. Three alligators for you. So, what do you mean we're not using t(a)bl(e)search. It's embedded in the layer-p function.


So when should you use the (tblsearch) function??
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 10:34:53 AM
Quote from: Daron
There is one problem with it, though. It's missing a dot. Can you tell me where?
Code: [Select]
(command "layer" "m" layer "")
Where's it needed?


would it be required before the first "layer"

Code: [Select]
(command ".layer" "m" layer "")

am i correct??
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 11:42:58 AM
(defun PutLayer (layer)
  (cond
    ((Layer-p layer)
     (setvar "clayer" layer))
    ((not (Layer-p layer))
     (command "layer" "m" layer ""))
    )
  (princ)
 )

when i run this code on my machine
i get
Command: _vlide Hard error occurred ***
internal stack limit reached (simulated)

do any of you get his as well?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 06, 2003, 11:46:34 AM
How are you running it?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 11:51:19 AM
Write it in vlide
Load it
switch back to autocad
(putlayer "x")

and then i get the error
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 06, 2003, 12:22:50 PM
Delete the previous putLayer function that you wrote and reload afterwards.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 12:26:18 PM
O.k nothin is workin now..

I can run
(defun putlayer (layer)
(command "layer" "m" layer ""))

but as soon as i go to a conditional
i get the error message.

don't know what is goin on here.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 06, 2003, 12:42:15 PM
Whaaaa?! That dosent make any sense. How can that be?  Can you close out of acad and reopen it. (I want to clear all variables and stuff) Im going to put two procedures up in the next post. Load those into the VLIDE and run the last one.

...brb
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 06, 2003, 12:42:27 PM
If you ran all this in one continuous session, then maybe quitting AutoCAD and starting it up again would be a good thing.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 06, 2003, 12:43:22 PM
Oh beaten by Se7en in 1 millisec  :D
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 06, 2003, 12:45:12 PM
Code: [Select]
(defun layer-p (layer)
  (and (tblsearch "LAYER" layer)))
(defun PutLayer (layer)
  (cond
    ((Layer-p layer)
     (setvar "clayer" layer))
    ((not (Layer-p layer))
     (command "layer" "m" layer ""))
    )
  (princ)
 )


(PutLayer "TEST") ;;<-- Run the procedures with this line.

SMadsen, lol.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 01:09:27 PM
I'm curretnly re-installing my autocad and see if this will help
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 06, 2003, 01:14:58 PM
Quote from: amgirard2003
O.k nothin is workin now..

I can run
(defun putlayer (layer)
(command "layer" "m" layer ""))

but as soon as i go to a conditional
i get the error message.

don't know what is goin on here.


You were right about the placement of the dot. Why is it missing still, here? This is what I get when the dot is missing.
Quote
Command: (command "layer" "m" layer "")
layer Unknown command "LAYER".  Press F1 for help.

Command: m Unknown command "M".  Press F1 for help.

Are you getting anything like this? With the dot in place on my machine it works.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 06, 2003, 01:18:16 PM
Quote from: amgirard2003
I'm curretnly re-installing my autocad and see if this will help


WHAT?!  :shock:  No you dont have to do that. I just ment close it down and start it back up again. not un-install it.

lol
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 06, 2003, 01:20:44 PM
Also, as I mentioned earlier, you should be able to do a repair from add/remove programs and that'll take care of most problems while leaving your current settings intact.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 06, 2003, 01:49:36 PM
I think the problem he is having is that he's not loading the Layer-p function first and all of you are assuming he is.

Andre, you are right. The tblsearch function could be used in the routine. If you load the Layer-p function first, then run the PutLayer routine as 7 listed, however, it's not necessary.

The PutLayer routine is depending on the Layer-p routine to be there.

Then again, you could be doing exactly that and I might be wrong :P
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 01:59:24 PM
Alright everyone, after the slate has been cleaned with a complete re-installment i'm back and runnin BEAUTIFULLY..

se7en,

I ran the routine you told me to run and no problems..
I couldn't do that earlier..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 02:14:17 PM
O.k... I'm gonna work on an example on my own similar to what 7 told me to do and i'll see how it goes.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 06, 2003, 02:15:31 PM
Quote from: amgirard2003
Alright everyone, after the slate has been cleaned with a complete re-installment i'm back and runnin BEAUTIFULLY..

se7en,

I ran the routine you told me to run and no problems..
I couldn't do that earlier..

Outstanding. Im glad your back up and running. It is crutial that you understand every aspect of these two procedures to cont. so please ask any quesions you might have, now.


Quote from: nivuahc
...
The PutLayer routine is depending on the Layer-p routine to be there.
...

That is EXACTLY the point. I not just teaching him how best to write this program, Im teaching something else entirely; Im using his program as an aid. (I'm attempting to teach him how to fish.) There is a lesson hidden in that statment. (Daron knows what im getting at here.)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 02:28:45 PM
Quote

That is EXACTLY the point. I not just teaching him how best to write this program, Im teaching something else entirely; Im using his program as an aid. (I'm attempting to teach him how to fish.) There is a lesson hidden in that statment. (Daron knows what im getting at here.)


Hey se7en,
I'd like to learn how to bait the hook before i go fishin... :lol:

Just kiddin... i appreciate all the help... thanks
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 06, 2003, 02:31:48 PM
Quote from: amgirard2003
Hey se7en,
I'd like to learn how to bait the hook before i go fishin...

Didn't you read Smadsen's lisp primer? That is the bait on the hook to go fishin' with.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 02:34:22 PM
Yeah i've read it but i'll have to re-read it...
I'm putting a binder together with notes so somethin
i can reference back to...

Well if that's the bait.. I need to learn how to cast then!!  :lol:
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 06, 2003, 02:44:43 PM
I think you have a great start. You're going to make mistakes and some things are going to be so frustrating that you'll want to quit. All you have to do is work on small pieces of code and test them. How familiar are you with the Vlide? Have you used the inspect button? That is a better way to test code than using !var.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 06, 2003, 03:00:22 PM
I'm very new to vlide..
I've figured out how to use the debugging tool but haven't gotten much further than that..

I know it's early and i've been frustrated once already...and i know it might not get easier from here but i know once i get the hang of things that it will go much smoother... I guess my biggest downfall right now is i get lost when i write the syntax.. I don't know where and what is supposed to go where..

Help on that topic i think will help me out as well..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 06, 2003, 03:11:12 PM
I don't know if my tutorial on it is all that great, but you can read it here (http://www.theswamp.org/super.fusion/Tutorials/Vlide%20Editor%20Tutorial/VLispTutorial.html)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 08:07:01 AM
Good Mornin Everyone,

Well now that i'm up and runnin and havin no problems i'm lookin to take some steps forward..
I've played around with the routine se7en had me test and have looked it over line by line, by doing that i think it finally clicked.

So whatever you feel is next please feel free to guide me in that way.

Thanks for your patience and your help.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 07, 2003, 08:35:42 AM
Warning: This is where you start showing what you have --or have not-- learned. You not only must have a prety good understanding of what i have previously posted, but you need to have a mental "map" of how a procedure works.

Varibles are "contaniers" right? Well, when you create a variable it takes up memory and therefore causes your program to slow down. A good question to ask yourself is: how do I fill my variable --what am I actualy doing to supply a value to my varaible. The answer is in the previous posts. See if you can find the answer before you continue, but dont spend much time on it (you should know already).

There is a flip side to thinking about how variables slow your procedure down. Using up a bit of memory is often better and ultimatly faster then if you were to process a set of expressions each time, instead of using a "container" "filled" with the value.

Your next assignment is to find a way to make the "PutLayer" procedure "better" based on these paragraphs.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 09:04:35 AM
se7en,
With your last post i guess i don't know what i'm learnin,
cause i'm totally lost as to what you're askin me to look for..
I've read these posts 5 times through and still can't see what you're askin me to look for.
This is frustrating....arrr...
 :x
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 07, 2003, 09:07:15 AM
Alright I'll write something up for ya.


EDIT: The answer I was looking for is posted below.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 07, 2003, 09:27:18 AM
A variable is supplied a value by the evaluation of expressions. When you define a variable you are really telling the interpreter to evaluate an expression --Or set of expressions--.

To improve the "PutLayer" function, you could define a variable and use it in place of the existing predicate of the conditional expression. This would cut the running time the conditional expression curently takes by 1/2. ~Do this.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 09:51:12 AM
se7en,
It's either too early and my brain is not workin or i'm completely missin somethin cause i'm stumped to what you are sayin..
I understand when you pass somethin to the interpreter it will always eveluate it.

But as far as improving the "Putlayer" i just don't see it.
I just don't see how to improve it.

The only thing that is goin through my head on how to improve it is
to make this an Autocad command, prompt the user and have that answer = a variable which would be local to that function. The conditionals would refer to that variable.

 :?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 07, 2003, 10:02:32 AM
Quote from: amgirard2003
...
The only thing that is goin through my head on how to improve it is
to make this an Autocad command, prompt the user and have that answer = a variable which would be local to that function. The conditionals would refer to that variable.


That dosent make any sense. Make it a command. Why? Prompt the user. What do you want to get from the user? (The layer name?! I thought we aready knew the layer name. "612")

Look in your PM inbox.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Mark on November 07, 2003, 10:10:21 AM
May I comment on this lesson Se7en?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 10:11:32 AM
O.k... question... where are we goin with this?
cause i'm startin to pull hair out of my head from frustration.

Like i've said... I don't know what i'm doin.. I don't know how to program and write code.. I'm not understanding the logic..

Feel like i've just been sacked for a 50 yard lost after throwin for 100 yards.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 07, 2003, 10:21:02 AM
Quote from: Mark Thomas
May I comment on this lesson Se7en?


Feel free Mark.

Quote from: amgirard2003
O.k... question... where are we goin with this?
cause i'm startin to pull hair out of my head from frustration.

Like i've said... I don't know what i'm doin.. I don't know how to program and write code.. I'm not understanding the logic..

Feel like i've just been sacked for a 50 yard lost after throwin for 100 yards.


I dont get it. You came here with code. You must know something about code. (Who produced the code?) You said that you read SMadsens intro. I assumed that you knew a little about lisp.

What we are doing here is teaching you the basics of logic to improve your coding skills.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 10:32:05 AM
If i said i wrote the code i would be lying.

Someone from a newsgroup had sent me the code.
I replaced words that he had used with mine and that was it
As far as all the "INITGET" i would have never thought of that or would never known where to look for that.

I'm here to learn from the beginning..
I want to scrap my idea for the time being and learn from the start..
I wanna learn Lisp, learn how to put it all together, learn the coding and how to write it properly...

I'm a newbie to programming, please keep that in mind....
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 07, 2003, 10:32:59 AM
ASS U ME

Never assume anything. You might be movin' just a little too fast there se7en.

I understand, believe me. I get excited when I see someone wanting to learn and I usually end up inundating them with too much information too quickly. That can be extremely frustrating to both parties involved.

Party 1 (andre) doesn't get it. Too much information too fast.

Party 2 (the rest of us) doesn't understand how Party 1 can't see what we're talking about.

Both parties end up pulling their hair out.

Patience, young Jedi. :D
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 07, 2003, 10:38:04 AM
Quote from: amgirard2003
If i said i wrote the code i would be lying.

Someone from a newsgroup had sent me the code.
I replaced words that he had used with mine and that was it
As far as all the "INITGET" i would have never thought of that or would never known where to look for that.

I'm here to learn from the beginning..
I want to scrap my idea for the time being and learn from the start..
I wanna learn Lisp, learn how to put it all together, learn the coding and how to write it properly...

I'm a newbie to programming, please keep that in mind....


Ok then if that's the case, im going to have to fill in a few blanks. I dont feel we are moving to fast at all, i just think your missing a few key issues. Once I think of a way to explaine this, everything will click and you will be right up to speed. Im going to pull a Babe Ruth and going to say it will take me three posts (not counting the unserious ones) to get you up to speed.  Give me some time to think this over.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 07, 2003, 10:44:47 AM
Here's what you should do andre.

Answer a couple of questions so we can see how much you understand what we're talking about.

1. What is a function in LISP and how do you identify a function with LISP (i.e. what command defines a function)?

2. What is a variable?

3. What's are the key differences between a local variable and a global variable?

4. How do you declare a variable as local?

5. How do you declare a variable as global?

6. How do you assign a value to a variable?


That, for a start, should give us an idea of where you are with understanding the basics.

We should be able to move on from there.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: M-dub on November 07, 2003, 10:45:22 AM
Ok, Quick Question...
How much time would you gurus say I would need to spend each night to learn Lsip?  I can't spend much time during the day.  I spend too much time on these forums as it is!  I couldn't tell you how many times I've hit Alt-Tab when I hear footsteps!!! :)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Mark on November 07, 2003, 10:48:10 AM
Perhaps you could take Andre's original code modify it and step through it line by line explaining as you go. When finished Andre will have a working program and more knowledge of lisp.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 10:50:16 AM
Quote from: nivuahc
Party 1 (andre) doesn't get it. Too much information too fast.

Party 2 (the rest of us) doesn't understand how Party 1 can't see what we're talking about.

Both parties end up pulling their hair out.

Patience, young Jedi. :D


You hit the nail right on the head.

I want everyone who wants to help to forget the idea i had first posted.
I don't want anything to do with it until i feel more comfortable and able to
do it on my own and understand what i'm doin.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 07, 2003, 10:56:55 AM
Quote from: M-dub
Ok, Quick Question...
How much time would you gurus say I would need to spend each night to learn Lsip?  I can't spend much time during the day.  I spend too much time on these forums as it is!  I couldn't tell you how many times I've hit Alt-Tab when I hear footsteps!!! :)


First, take a look at Ghostzilla, the invisible web browser (http://www.ghostzilla.com/) ;)

Second, the amount of time needed is completely dependant on the person doing the learning. If you follow this thread through, I'm sure you will learn quite a bit about LISP without even trying.

This one thread has the potential to teach quite a bit in a relatively short amount of time if we continue to work as a community to make it grow.

We have a community of newbies, oldbies, experts and gurus. There's no reason why we shouldn't be able to all learn something from this thread, not to mention this entire board.

Anyone who claims to know everything is ignorant of at least one thing. No one knows everything.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 07, 2003, 10:59:45 AM
Quote from: M-dub
Ok, Quick Question...
How much time would you gurus say I would need to spend each night to learn Lsip?  I can't spend much time during the day.  I spend too much time on these forums as it is!  I couldn't tell you how many times I've hit Alt-Tab when I hear footsteps!!! :)


That depends on you. How much time do you have each night. I always heard 1 hour. Of course, if I tried it for an hour, I'd forget what I learned when it came to the next night. As well, when I tried to work for an hour, three had passed. That was when I was in Andre's position. Yesterday, I spent an hour at w3schools.com, read through the lessons on SQL, took the quiz at the end and only missed two questions out of 20. I spent another half hour reading up on VBScript and PHP. I'm finding many similarities between many languages. SQL is the only one I find that doesn't have as many similarities as the others. SQL seems simple.

Chuck jumped in ahead of me.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 11:07:18 AM
Quote from: nivuahc
Here's what you should do andre.

Answer a couple of questions so we can see how much you understand what we're talking about.

1. What is a function in LISP and how do you identify a function with LISP (i.e. what command defines a function)?

Function: a set of commands
To define a command you use the DEFUN function
To identify i don't understand what you mean?

Quote from: nivuahc

2. What is a variable?


A storage area for data you set to it
Quote from: nivuahc

3. What's are the key differences between a local variable and a global variable?


Global Variables: They don't lose their value when the program exits, and other functions can refer to them.

Local Variables: They lose their value when the program exits, and they are only local to that function, no other function can refer to them.

Quote from: nivuahc

4. How do you declare a variable as local?


you assign the variable after a "/"
Quote from: nivuahc

5. How do you declare a variable as global?


You assign the variable before a "/"
Quote from: nivuahc

6. How do you assign a value to a variable?

Use the (setq) function
(setq a 5)

Quote from: nivuahc

That, for a start, should give us an idea of where you are with understanding the basics.

We should be able to move on from there.


Edited to make post clearer.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 07, 2003, 11:10:51 AM
Se7en, you asked a question back on page 4. Yup, didn't forget it but wouldn't want to disrupt this thread with some crazy ramblings either, so I put it in a separate thread.

Carry on tutoring ... :)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 07, 2003, 11:12:59 AM
Quote
5. How do you declare a variable as global?

You assign the variable before a "/"


No.

Everything else you got right, more or less.

The only action required to declare a variable as global is no action at all.

Putting the variable in front of the '/' will declare it as a local variable as well. But, more importantly, it will declare that variable as a 'required argument'. What, exactly, is a required argument?




EDIT: So, just to clarify, any variable listed in the set of parentheses following the function definition are considered local variables. Any variables not listed in that set of parentheses are considered global variables.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 11:17:19 AM
Quote from: nivuahc
Quote
5. How do you declare a variable as global?

You assign the variable before a "/"


No.

Everything else you got right, more or less.

The only action required to declare a variable as global is no action at all.

Putting the variable in front of the '/' will declare it as a local variable as well. But, more importantly, it will declare that variable as a 'required argument'. What, exactly, is a required argument?


o.k hmmmm..

(defun putlayer (layer / a b c )

Wouldn't layer be global?

Required argument: like it says required.. you have to pass somethin so the routine will run..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 07, 2003, 11:19:39 AM
No, it'd be local.

And it'd be a required argument.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 11:23:43 AM
o.k.. see i was confused with () i was under the impression that everything
had to be within the parentheses.. all variables had to be within them..

(setq a 5) i thought a would have be within the parentheses and was under the impression that if you put it before the / then it was global.

I was completely backwards on that first topic

And another thing... never heard of "required argument"
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 07, 2003, 11:30:08 AM
Ahhh... the Force is strong with this one... but you are not a Jedi yet!. :D

So to test what you've learned so far try this:

Code: [Select]
(defun lisp-test (va / vb vc)
  (setq vb "B")
  (setq vc "C")
)


Copy/paste that code and then run the function

(lisp-test A)

Now, being able to test the value of a variable at the command line, type the following and see what you get

!va

!vb

!vc
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 07, 2003, 11:30:30 AM
Quote from: nivuahc
The only action required to declare a variable as global is no action at all.
Heh, at least it's a comfort that the tutor got it wrong, too. I've never seen a global variable appear from no action at all. *ahem* .. a global variable appears when a symbol is assigned a value without explicit actions taken to declare it as local. "Oh what a smarta$$" (I know .. just couldn't resist)  :wink:
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 07, 2003, 11:32:28 AM
:lol:
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 11:44:26 AM
Quote from: nivuahc
Ahhh... the Force is strong with this one... but you are not a Jedi yet!. :D

So to test what you've learned so far try this:

Code: [Select]
(defun lisp-test (va / vb vc)
  (setq vb "B")
  (setq vc "C")
)


Copy/paste that code and then run the function

(lisp-test A)

Now, being able to test the value of a variable at the command line, type the following and see what you get

!va

!vb

!vc


Let me try and see what this is sayin
Code: [Select]
(defun lisp-test (va / vb vc); variables "vb" "vc" are local, "va" is a required argument.
  (setq vb "B"); you're setting "B" to "vb", which is a global variable.
  (setq vc "C"); you're setting "C" to "vc", which is a global variable.
)


So when you start the function "lisp-test" you must pass it an argument for it to work.
Therefore (Lisp-Test A)

!va will evaluate to nil because nothin is being passed to it.

!vb will evaluate to nil because nothin is being passed to it.

!vc will evaluate to nil because nothin is being passed to it.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 07, 2003, 11:59:55 AM
Quote from: amgirard2003


Let me try and see what this is sayin
Code: [Select]
(defun lisp-test (va / vb vc); variables "vb" "vc" are local, "va" is a required argument.
  (setq vb "B"); you're setting "B" to "vb", which is a global variable.
  (setq vc "C"); you're setting "C" to "vc", which is a global variable.
)



In the second line of that code I'm setting the value of "B" to variable vb which is a local variable (notice it's listing in the set of parentheses following the defun).

In the third line of that code I'm setting the value of "C" to variable vc which is a local variable (notice it's listing in the set of parentheses following the defun).

Any variable listed whithin those parentheses are declared as local variables.

If my code had a fourth line that said

Code: [Select]
(setq vd "D")

then variable vd would be a global variable because it's not listed in the parenthese following the defun.

Therefore, after running this function, the return value of va, vb, and vc will all be nil because they are all local variables.

The return value of vd, were it included as listed above, would be "D".

Understand?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 12:06:12 PM
Sorry about that

I mis-read line 2 and 3... brain fart!  :lol:
I forgot about the variables being listed in the parentheses.

I understand this part now... the smoke has thinned out quite a bit on this topic.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 07, 2003, 12:22:35 PM
Okay then.

Write a routine called 'My-Lisp'.

In your routine, declare the following variables:

var-a (global)

var-b (local)

var-c (local - required argument)

var-d (local)

Assign values to your variables as such:

var-a "I'm a Global Variable"

var-b "I'm a Local Variable"

var-c "C"

var-d "I'm a Local Variable"


Then demonstrate how you'd run that routine.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 12:40:49 PM
(defun mytest ( c / b d )
   (setq a "I'm a global variable")
   (setq b "I'm a local variable")
   (setq c "C")
   (setq d "I'm also a local variable")
)

O.k question for ya...

After i run this when i type in

"!a" i get nil but when i type in just "a" "I'm a local variable"

I thought to check the value of a variable you used the ! followed by the
variable
!a
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Mark on November 07, 2003, 12:45:26 PM
>I thought to check the value of a variable you used the ! followed by the variable

Not when using the vlide.

Let me clarify.
(setq a 1)
vlide
a = 1
ACAD command line
!a = 1
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 12:48:09 PM
oh o.k... that make more sense now..
Thanks Mark
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 01:21:04 PM
nivuahc,

give me another problem to solve..
make it clear but a little more difficult..

This is helping out a lot!

 :)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 07, 2003, 01:42:12 PM
Try figuring out the difference between IF and COND. Also, explain what PROGN does and why you don't need to use it in COND and why you use it in IF.

When you've explained and understand that, let's say we work on looping structures? Or is that reserved for a little further down the lesson line?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 01:46:16 PM
I'm open to anything..
The only thing i ask is for thing to not start jumping all over the place..
I downloaded the Autolisp tutorial from Afralisp.com and the biggest problem i have with that tutorial is that it jumps to much.. before you can grasp what you read you're into somethin totally different

So i'll leave it to you as a group to decide where you would like to take this ship.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 07, 2003, 02:34:20 PM
Quote from: Daron
Try figuring out the difference between IF and COND. Also, explain what PROGN does and why you don't need to use it in COND and why you use it in IF.

When you've explained and understand that, let's say we work on looping structures? Or is that reserved for a little further down the lesson line?


IF- If is used to check one expression at a time..If the expression is TRUE then PROGN comes into to play. Use PROGN to tell it what to do if the expression returns true.

COND- is used to check multiple expression at one time. It checks all expressions until it finds one that returns TRUE. If it finds one that is true it goes to the next line to do what is programmed to do.

How's that?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 07, 2003, 03:13:12 PM
Cond is good. You'll get more comfortable with it as you use it.
If is good, but Progn is not.

You don't need to use Progn with cond, why? Because cond will process everything it's told to do if the condition is true.
You don't need to use Progn with IF either, why? Because If only processes the first item if the Logical Test evaluates to true. If the LT evaluate to false, it processes the next element in the expression. Syntax:
If...Then...Else
Ex.
Code: [Select]
(if (= a b) ;If true...
    (do something here);...Then do this if true
    (do something here);...Else, do this if false
)


The Progn function will lump elements in an expression as one.
Ex.
Code: [Select]
(if (= a b) ;If
    (progn
        (do something here) ;Then if true do this
        (do something else here) ;if true do this too
        (continue....) ;continue until progn closes
    ) ;end of progn
    (do something here) ; Else do this if false
)

You can use progn for either the true or false statement. Does this help you understand what the PROGN function does?

BTW, the beauty of these boards is that you can take what you want and work it to your understanding and come back for more later. So, if we get off track, let us know. We can always come back to it later. Why don't you let us know also, if you understand what I was getting at earlier with the (setq c nil) thing.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 07, 2003, 03:55:31 PM
Daron, I think it might be best if we stick with the very basics for now.

IF, PROGN and COND seem basic to you and I because we use them so often and, well, they are pretty basic.

Try thinking of this from a newbie point of view, though.

I can think of a ton of other basics that really ought to be covered before we get into IF, PROGN, and COND.

That teaching someone to fish thing... if you teach a person to fish and they don't get any results at first they may get discouraged. The best motivator for someone who is starting out, be it fishing or writing code, is results.

So why don't we help andre get some basic results at this point so that, when the time comes, he'll be more comfortable doing his own fishing. :)

For instance, there are a couple of basic commands in LISP that display information.

princ is one of the most common and is used by a lot of people for debugging a LISP routine.

Code: [Select]
(princ "What are you doing, Dave?")

would print "What are you doing, Dave?" to the Autocad command line.

Try it out.

This should be what you get in return:

Quote
Command: (princ "What are you doing, Dave?")
What are you doing, Dave?"What are you doing, Dave?"

Command:


Well that looks confusing or at least difficult to read, doesn't it?

Another command that writes information to the command line is print.

Code: [Select]
(print "What are you doing, Dave?")

Would return

Quote
Command: (print "What are you doing, Dave?")
"What are you doing, Dave?" "What are you doing, Dave?"

Command:


Well at least that's a little easier to read, no?

prin1 is also a command that will display information on the command line

Code: [Select]
(prin1 "What are you doing, Dave?")

Would return

Quote
Command: (prin1 "What are you doing, Dave?")
"What are you doing, Dave?" "What are you doing, Dave?"

Command:


That looks identical as print and, according to the AutoLISP reference guide each of these commands 'Prints an expression to the command line, or writes an expression to an open file'. More on writing to an open file later. For now, let's focus on the command line.

So, if they all do the same thing, what's the difference?

This is what the AutoLISP Reference says about princ:

Quote
(princ [expr [file-desc]])

This function is the same as prin1, except control characters in expr are printed without expansion. In general, prin1 is designed to print expressions in a way that is compatible with load, while princ prints them in a way that is readable by functions such as read-line.


This is what the AutoLISP Reference says about print:

Quote
(print [expr [file-desc]])

This function is the same as prin1, except it prints a newline character before expr, and prints a space following expr.


I'll continue as soon as I get a sec... very busy at the mo'
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 07, 2003, 04:37:12 PM
Sorry. What I threw out was the first thing I ever learned. He has a good understanding of what I threw out. I don't think he's going away. I've never used prin1 or print. Princ works just fine and there are only three situations where I've found it useful. A) Before a ssget, where I want to be explicit. B) If I want to show info on the command line and C) as a quiet out.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 07, 2003, 05:12:45 PM
No need to apologize Daron. I'm guilty of doing the same thing.

And, as far as princ goes, I agree with you.

I'm just trying to cover some bases, that's all.

The way I see it, andre is just starting out and he has no programming experience at all. The basic things like what kind of values, exactly, can you assign to a variable, haven't even been touched on. Commands like getpoint haven't even been broached. In order to grasp what he'll be capable of doing with LISP in AutoCAD I thought it best to demonstrate those types of things first. Lay a little groundwork, if you will. I'm confident that, once some of these pieces start falling into place, andre will be unstoppable.

He has the willingnes to learn and the determination to understand it all.

In my experience, at least, that's pretty rare.

Most people can't be bothered to actually learn anything but, so far, andre has been different.

The fishing analogy: A long-time fisherman finds a young, inexperienced, willing pupil. They go out in a boat and the Old Man tells the apprentice "Reach in that tackle box and give me a buzz bait". Well, maybe the apprentice can guess what a buzz bait is, maybe he can't. He reaches in the tackle box and grabs a spinner bait and hands it to the Old Man. The Old Man looks at it and says "No, the buzz bait... the buzz bait. By chance, the apprentice grabs a buzz bait and hands it to the Old Man. The Old Man tells the apprentice "Go ahead and setup a Carolina Jig on the rod over their and start fishing this side of the boat". Our apprentice scratches his head and, well, now he's wondering if this is the right guy to teach him about fishing.

Learning anything takes patience. Teaching takes tons more. Sometimes the whole process takes baby-steps at first.

I don't mean to hijack this thread. I know that there are a good number of you who know way more than I do. It's just that, at one time, I was andre. I want to see him learn to fish. I want us to teach him. I want him to keep that drive and determination.

He'll get it, I'm sure of it.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 07, 2003, 05:58:31 PM
Quote
In my experience, at least, that's pretty rare.

Mine too. You're right about needing to learn getpoint and all that stuff. I just threw out the first thing that came to mind.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 10, 2003, 08:06:38 AM
Quote from: nivuahc
The way I see it, andre is just starting out and he has no programming experience at all. The basic things like what kind of values, exactly, can you assign to a variable, haven't even been touched on. Commands like getpoint haven't even been broached. In order to grasp what he'll be capable of doing with LISP in AutoCAD I thought it best to demonstrate those types of things first. Lay a little groundwork, if you will. I'm confident that, once some of these pieces start falling into place, andre will be unstoppable.


I appreciate the patience you guys are showing in teaching me the basic..
I know too many people would have given up by now and would have ditched my post and wouldn't reply anymore..

I've read Smadsen "PRIMER" over the weekend, 5 times actually and i've started a binder with notes i've written down from this thread...

Like Nivuahc says, keep it basic for right now until i can get my feet planted and then i'll be ready to branch into different areas..

I'll be waiting for you posts..

Thanks again
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 10, 2003, 09:11:56 AM
Andre, I hope those small texts were of use to you. Since you have covered some basic terms and are eager to learn more, I have posted lesson 2 from a more indepth course material.

If you want you can get it from http://www.smadsen.com/files/lesson2.htm. It ends with some questions and exercises so that the reader can test if the concepts are understood. If you like, you could try to solve the exercises and post your solutions here, so we could have a wee debate.
Especially exercise 2.5 would be good for this purpose.

Of course, you are welcome to post your answers to both questions and exercises.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 10, 2003, 09:14:35 AM
By the way, it's also available as a Word doc at http://www.smadsen.com/files/lesson2.doc
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: collegeCAD on November 10, 2003, 09:43:49 AM
Hey, welcome! I'm no longer the resident bewnie! woo-hoo! don't worry about being lost, i am all the time... just ask anybody here hehe. these guys know their stuff and will be able to help you w/ no problems at all. good luck!
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 10, 2003, 10:31:57 AM
Smadsen,

Thanks for the link... I'll go through Lesson 2 and i'll let know you all know how i do and post any questions that i will probably have.
I've learned quite a bit since i've joined this forum.

I'll post as soon as i'm done..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 10, 2003, 11:28:33 AM
Smadsen,

I printed out Lesson 2 and goin through it as we speak.
I've run into a snag though...
Page 6 you go through an example with (Defun Calculate) and (defun formula),
Here's the example:

Code: [Select]

(defun calculate (a b c y / add1 add2 add3)
  (setq add1 (* a y))
  (setq add2 (* (expt b 2.0) y))
  (setq add3 (/ (* c 4) 0.5))
  (+ add1 add2 add3)
)



(defun c:formula (/ a b c y temp)
  (setq a (getreal "\Value of a: "))
  (setq b (getreal "\Value of b: "))
  (setq c (getreal "\Value of c: "))
  (setq y (getreal "\Value of y: "))
  (setq temp (calculate a b c d y))
  (princ "\nX = ")
  (princ temp)
  (princ)
)


This example is not working for me...

Question is where is says (setq temp (calculate a b c d y))
how can c:formula call on calculate to do the calculation, where in (defun calcualte) nowhere does it say (+ a b c d y).
Am i making any sense?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Mark on November 10, 2003, 11:51:30 AM
Code: [Select]
(setq temp (calculate a b c d y))
Appears to be a typo, try it like this;
Code: [Select]
(setq temp (calculate a b c y))


*note to SMadsen. we missed that one!*
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 10, 2003, 11:56:10 AM
Yes, you're making alot of sense, thank you.
Thought I had corrected that loong time ago .. hmmm, guess not  :oops:  
The functions should of course read:

Code: [Select]
(defun calculate (a b c y / add1 add2 add3)
  (setq add1 (* a y))
  (setq add2 (* (expt b 2.0) y))
  (setq add3 (/ (* c 4) 0.5))
  (+ add1 add2 add3)
)

(defun c:formula (/ a b c y temp)
  (setq a (getreal "\Value of a: "))
  (setq b (getreal "\Value of b: "))
  (setq c (getreal "\Value of c: "))
  (setq y (getreal "\Value of y: "))
  (setq temp (calculate a b c y))
  (princ "\nX = ")
  (princ temp)
  (princ)
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 10, 2003, 12:01:55 PM
Andre, you're a rascal for putting that PRINC in the CALCULATE function! I admit to typing an extra variable but I did not have sex with that PRINC .. I mean, I did not write it.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Anonymous on November 10, 2003, 02:38:07 PM
Answer to Lesson 2 from Smadsen;

1. What is difference between local and global variables?

Local Variables: They are local to that function, other functions can't refer to them, they lose their value when the program exits.

Global variables: Other functions can refer to them, they don't lose their value when the program exits.

2. Under normal circumstances, which are the two cases that can cause a global variable to loose its value?

First case is when the environment in which it was created in is terminated.
Can't find the second case.

3. Which built-in functions is used for building userdefined functions?

DEFUN is used to build a userdefined function

4. What are the 3 arguments that need to be present in a userdefined function?

1. The name of the function that is being defined
2. List of arguments
3. List of local variables

5. What kind of data type does a userdefined function return?

the value of the last expression within the DEFUN that becomes the return calue of the userdefined function.

6. Which function is used for loading AutoLISP code that is contained within external files?

LOAD is the function to load Autolisp files

7. What is the special symbol that causes commands issued by the command function to await input from the user?

The PAUSE symbol will cause the function to pause and await input from the user.

8. When can a userdefined function be called as an ordinary command at the command line in AutoCAD?

You must enter c: in front of the function name. ex: (defun c:test ())

9. At which location or locations within a userdefined function are arguments to the function used?

Arguments are located before the "/" ex: (defun test ( a b c / d e))
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 10, 2003, 02:39:07 PM
Those were my answers... didn't realize i was logged out.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 10, 2003, 05:39:58 PM
Cool, amgirard. Well done. Are you sure you are a beginner at this??

1. Correct answer

2. Correct answer. The second case is merely when a global variable is assigned another value, whereby it looses its current value, but your answer is what this question is all about: to think about it.

3. Correct answer

4. Almost correct. The list of arguments/local variables that follows the function name is one argument (it's merely a list, although treated specially). The third required argument is at least one expression.

5. Correct answer. The kind of data type depends only on the last evaluated value.

6. Correct answer.

7. Correct answer.

8. Correct answer.

9. This is a trick question that is solely designed to think of the use of arguments while writing down an answer. I've often experienced ppl who, even though they are fully capable of understanding what arguments to the multiplication function are, are having trouble with understanding arguments to a DEFUN.
Arguments can be used throughout the function. There is no specific location. It's true that arguments are declared at the location you mention but the question is about their use.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 11, 2003, 08:41:58 AM
; Lesson 2 from Smadsen
; Exercises
; 2.1
(defun c:add ()
  (prompt "This will add 2 numbers together")
  (setq a (getreal "\nEnter a Number: "))
  (setq b (getreal "\nEnter another Number: "))
  (setq answer (+ a b))
  (princ answer)
  (princ)
)

; 2.2


(defun c:add ()
  (prompt "This will add 2 numbers together")
  (setq a (getreal "\nEnter a Number: "))
  (setq b (getreal "\nEnter another Number: "))
  (setq answer (sum a b))
  (princ "\nanswer = ")
  (princ answer)
  (princ)
)

(defun sum (a b)
  (+ a b)
)

; 2.3

(defun c:points   (/ a b c d)
  (setq a (getpoint "\nPick First Point: "))
  (setq b (getpoint "\nPick Second Point: "))
  (setq c (getpoint "\nPick Third Point: "))
  (setq d (getpoint "\nPick Fourth Point: "))
  (command "pline" a b c d "c")
  (princ)
)

; 2.4

(defun c:points   (/ a b c d)
  (setq a (getpoint "\nPick First Point: "))
  (setq b (getpoint "\nPick Second Point: "))
  (setq c (getpoint "\nPick Third Point: "))
  (setq d (getpoint "\nPick Fourth Point: "))
  (command "pline" a "a" "r" pause pause b c d "cl")
  (princ)
)

These are my answers for Smadsen exercises..

I was stumped on exercise 2.5

Would like to see your comments..
These were all done by myself..no other help but my own reading..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 11, 2003, 09:07:12 AM
I think you're doing well. Let me show you some ways to not have to have setq placed in so much.
Code: [Select]
(defun c:add ()
(prompt "This will add 2 numbers together")
(setq a (getreal "\nEnter a Number: ")
      b (getreal "\nEnter another Number: ")
      answer (sum a b)
)
(princ "\nanswer = ")
(princ answer)
(princ)
)


This will work with command also, but not with too many other functions. It is of course a personal preference and not required, but to me it is cleaner code. On a side note, pause is a good way to quickly input information, but I wouldn't write it in too many instances. It could become a crutch and it doesn't give the user any idea of what (s)he is supposed to do.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 11, 2003, 09:43:21 AM
Very well done, amgirard! The comments I will make are mostly cosmetic at this stage, so don't worry about it too much. Your functions are working excellently and fullfill the criteria, except for the solution to 2.4 that only works in certain cases.

2.1
- The function creates global variables, which are not needed. It's merely an exercise and all that - heck, most solutions posted in forums like this to serious problems don't declare local variables or include error handling because they simply serve to exchange methods instead of fullblown ready-to-use routines - but it's a nice thing to get used to think in locals and globals.
- The variable answer is not needed if you nest the calculation within the call to PRINC: (princ (+ a b)). It does make the code more readable to produce an intermediate result, though, but a comment could make it equally readable.

2.2
Same comments as above. Regardless of making the code more readable, the variable answer could be replaced by:
...
(princ "\nAnswer = ")
(princ (sum a b))
...

2.3
- Excellent use of local variables! :)
- Most of the section about system variables in the text is about the issue of switching system variables on and off when they can interfere with the use of the COMMAND function. Here the task is to draw a pline automatically, so it might interfere with current object snaps. While retrieving points, the user should be allowed to use whatever object snaps he/she wants, but when drawing occurs it could cause unexpected results because COMMAND will use the current osnaps and might displace the points accordingly.
After getting the points, it should do something similar to this:

...
;; save OSMODE and set it to 0 to avoid unexpected object snap
(setq osm (getvar "OSMODE"))
(setvar "OSMODE" 0)
(command "PLINE" pt1 pt2 pt3 pt4 "Close")
(setvar "OSMODE" osm)  ; restore OSMODE to previous value
...


2.4
I understand that you would want to provide the user with control of the arcs used to draw the polyline. However, two things occur with your solution:
1. If CMDECHO is set to 0, it will not display the prompt that allows the user to specify a radius. He/she would scratch his/her head and hit Escape when not knowing what to do. In order to inform the user, switch off CMDECHO (store the current value) and create a prompt (e.g. with PRINC) before calling the PLINE command. Afterwards, remember to restore CMDECHO. There would still be a problem with the issue below, though.
2. If any of the points are further apart from each other than two times the specified radius, the command will fail. Well, it will not fail completely, but it will create an unexpected result and print a nasty *Invalid* message to the screen. For it to work is a bit more complicated because you would have to retrieve the radius in advance and test it against the distances between the successive points. If this test fails you would then have to decide whether to ask for a new radius, use a calculated radius or give up on the user. Far from mission impossible, but a bit more complicated.
Given only the points, I would merely draw the polyline without control of the arc's appearances:
(command "PLINE" pt1 "Arc" pt2 pt3 pt4 "Close")


You can review the proposed solutions to all exercises, except 2.5 (for which only some clues are given), here (http://www.smadsen.com/files/appendix2.htm)

Good job!
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 11, 2003, 09:45:46 AM
2.5   Create a new command that asks for a center point, a radius, a starting angle and an ending angle. It shall then proceed to draw an arc with center at the specified center point and a radius and an angle as specified. The radius needs to be specified as a distance dragged on the screen so that a rubberband is drawn between the center point and the cursor, or as a number typed at the command line.

   In this exercise we will make use of the function POLAR that hasn't been mentioned yet. Besides utilizing what has already been described, the purpose of this exercise is also to look up a function in the online help references without prior knowledge of the function - and to make it work!

   Save the code to a .lsp file and load it into AutoCAD.

   First, try to issue the ARC command in AutoCAD in order to get familiar with the sequence. Make notes of the exact sequence as the ARC command advances into drawing a complete arc in AutoCAD.

   Note: No suggestions are given for this exercise. The command can be written in different ways but in order to take full advantage of AutoLISP, a couple of more advanced techniques that also utilizes SETVAR/GETVAR can be applied. See the appendix for some useful tips.
   You are encouraged to forward your solution to be evaluated!

This is exercise 2.5 from Smadsen, and i'm stumped on it..
Could someone give me a hand and understanding what i have to do?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 11, 2003, 09:55:00 AM
Quote from: amgirard2003
Could someone give me a hand and understanding what i have to do?

Umm, nope :)
Did you check out the clues in the link (http://www.smadsen.com/files/appendix2.htm) above?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 11, 2003, 09:58:45 AM
Where can i find a good listing of the System Variables that i should keep in mind when i write anything and when should i start to learn about all of these? Is it to early for that yet?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 11, 2003, 09:59:39 AM
Hey, andre and everyone else, I just wanted to pop in and let you know that I have not deserted you. I had to bring the wife to the hospital yesterday as Junior seems intent on entering this world a couple of weeks earlier than previously scheduled. I have had about 8 hours of sleep over the past three days and I am trying, desperately, to catch up on the goings on during my absence at work.

While my time here may be sporadic over the next couple of days I do hope you realize that it is by no fault of your own. From what I have been able to read thusfar in this thread it would seem that you are doing quite well andre and, as silly as it might seem, I'm very proud of you.

Try your best not to get frustrated. They don't call it 'Lost In Stupid Parentheses' simply because it sounds cute. ;)

Rest assured you are in quite capable hands. I, myself, am but a learner. These guys, as they have proven time and time again, are more than capable instructors.

I'll try to catch up here as time permits it.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 11, 2003, 10:06:05 AM
So, all you're doing is re-creating the arc command, right? Clue one is pretty much the key. Polar requires three arguments: point, angle and distance. The exercise asks you to calculate the start point for the arc, based on center point, starting angle and radius. So, let's see how polar would look.
(polar cenpt (angle cenpt pt2) (distance cenpt pt2))
cenpt would be the first point picked and the center of the arc.
(angle cenpt pt2) would be the first point picked and the second point picked to give the desired angle.
(distance cenpt pt2) would be the distance between the cenpt and pt2, which should be the radius of the arc.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 11, 2003, 10:09:13 AM
Quote from: amgirard2003
Where can i find a good listing of the System Variables that i should keep in mind when i write anything and when should i start to learn about all of these? Is it to early for that yet?


If you have express tools, there is a function called system variable editor, under the menu express->tools that will show you most, if not all of the variables.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 11, 2003, 10:30:12 AM
Quote from: Daron
Is that under Autocad 2004, I'm running AutoCAD Map5 and it doesn't have that under the express tools.

It should. Try typing SYSVDLG on the command line and see what happens.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 11, 2003, 10:40:28 AM
In the online help there is a system variable reference (alongside the command reference). I always use that to look up a system variable.

I once wrote a searchable reference in AutoLISP. It can still be dl'ed here (http://intervision.hjem.wanadoo.dk/sysvardlg.htm). It still needs to be updated to include certain variables in 2004 (it does list some undocumented variables, though)  :)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Anonymous on November 11, 2003, 02:53:46 PM
Alright i've been tryin to do Exercise 2.5 all afternoon
and i'm lost... Polar has completely confused me and
now i'm all lost. I don't know where to start or what to do..
I know i have to try and figure things out for myself and
to read but currently i'm reading chinese right now so it's
not making any sense to me. :?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 11, 2003, 02:57:16 PM
that's my post above...once again i wasn't logged in for some reason.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 11, 2003, 03:01:42 PM
Quote from: amgirard2003
Quote from: Daron
Is that under Autocad 2004, I'm running AutoCAD Map5 and it doesn't have that under the express tools.

It should. Try typing SYSVDLG on the command line and see what happens.


That's confusing me. Did I hit edit instead of quote? Bad moderator. Anyway, that should be what you need to do.

As far as for the polar confusion, it took me some time to fully understand it when learned it, too. Tell us what you understand about polar. My example above should give you some hints. I could add more if you like. Print in your words the arguments of the polar function though.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 11, 2003, 03:12:01 PM
Quote from: Daron
As far as for the polar confusion, it took me some time to fully understand it when learned it, too. Tell us what you understand about polar. My example above should give you some hints. I could add more if you like. Print in your words the arguments of the polar function though.


It's the whole 2.5 Exercise... I'm confused to what it's tryin to say.. i know it sounds dumb but i don't understand..
It's saying at the beginning to ask for input on "Center Point", Start Angle" "End Angle" "Radius".
But at the end of the description.. it's saying to allow for input of radius to be like a rubberband or allow for key input.

That's where i'm confused.. Why ask for input at the beginning if you're gonna allow once again later?

Am i making sense?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 11, 2003, 03:20:07 PM
Take the exercise one step at a time. Start by setting up a function for the polar idea to work. The rest can be worked out and tweaked later. Does my example above make any sense to you?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 11, 2003, 03:26:10 PM
What does polar actually do?
i understand what the code syntax is saying but not understanding exactly what the polar function actually does..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 11, 2003, 03:49:03 PM
It allows you to select a start point, an angle and a distance. From this you can do many things. Mostly draw items on an angular position, instead of x-x and y-y, like a rectangle. More like a diamond, if you select two points at 45 degrees. Imagine you want to draw a square by selecting two points.
Code: [Select]
(defun c:square (/ pt1 pt2 pt3 pt4)
     (setq pt1 (getpoint "\nSelect a point: ")
  pt2 (getpoint pt1
"\Select the distance and angle of the square: "
      )
  pt3 (polar pt2
     (+ (angle pt1 pt2) (/ pi 2))
     (distance pt1 pt2)
      )
  pt4 (polar pt1
     (+ (angle pt1 pt2) (/ pi 2))
     (distance pt1 pt2)
      )
     )
     (command ".pline" pt1 pt2 pt3 pt4 "c")
     (princ)
)

Digest that a little bit and see if you can understand the polar function.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Anonymous on November 12, 2003, 11:09:19 AM
So is Polar used to locate points with out drawing lines to first find them?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 12, 2003, 11:11:11 AM
This website keeps resetting me to guest after i log in..
Weird i tell ya..
as you can tell the previous post is from me of course
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 12, 2003, 11:27:52 AM
Quote from: Anonymous
So is Polar used to locate points with out drawing lines to first find them?

Sort of. You can think of polar as a way to define points based on a selected point, radially. As you see in my example, pt1 is the main point. It can be set up where only one point is selected and an angle and distance is supplied by the user and all other points are placed programmatically, based on those three inputs. In my example, I manipulated the angle argument to locate a point 90 degrees from the specified point at the distance stated to get point 3 and 4. You can manipulate the distance argument too, to span the distance at intervals. I have a routine that places text at the mid point of a line by using polar and all I have to do is select a line object. You can do this with arcs too, but it's a little more complex.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 12, 2003, 11:27:54 AM
Check your cookie settings to see if they are too strict to log you on each time.

Andre, I bet you know POLAR all too well - although only in AutoCAD. There are two major ways to type in a point in plain AutoCAD. One is simply writing the coordinates and the other is the polar notation:

Command: LINE
Specify first point: 10,10,0
Specify next point or [Undo]: @10<45.0

This will draw a line from 10,10,0 to approx. 17.07,17.07,0 - i.e. a line from 10,10,0 with the length of 10.0 and at an angle of 45.0 degrees. That is what POLAR in AutoLISP does (except for drawing a line!)

Sure, POLAR wants an angle first and then the length (unlike the sequence shown above) but it simply finds a point that lies at a given angle and a given distance from a given point.

(polar (list 10.0 10.0 0.0) (/ pi 4.0) 10.0) gives the same point as above, (17.0711 17.0711 0.0).
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 12, 2003, 11:34:04 AM
Code: [Select]

(defun c:square (/ pt1 pt2 pt3 pt4)
     (setq pt1 (getpoint "\nSelect a point: ")
      pt2 (getpoint pt1
          "\Select the distance and angle of the square: "
          )
      pt3 (polar pt2
            (+ (angle pt1 pt2) (/ pi 2))
            (distance pt1 pt2)
          )
      pt4 (polar pt1
            (+ (angle pt1 pt2) (/ pi 2))
            (distance pt1 pt2)
          )
     )
     (command ".pline" pt1 pt2 pt3 pt4 "c")
     (princ)
)


Let me see if i'm understanding what you're saying..

(defun c:square (/ pt1 pt2 pt3 pt4)


You're defining all the varaibles as local because you want them to clear themselves when the routine finishes.

(setq pt1 (getpoint "\nSelect a point: ")
      pt2 (getpoint pt1
          "\Select the distance and angle of the square: "
          )


You're asking the user to pick a point which is then saved to PT1,
You're then asking the user to pick a distance and angle which is then saved to PT2

pt3 (polar pt2
            (+ (angle pt1 pt2) (/ pi 2))
            (distance pt1 pt2)
          )
      pt4 (polar pt1
            (+ (angle pt1 pt2) (/ pi 2))
            (distance pt1 pt2)
          )


I'm a little confused here... don't understand what you're sayin here..
Could someone please clarify this for me please

Thanks,
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 12, 2003, 11:46:57 AM
I'm tryin to do Exercise 2.5 and i can't get anywhere
Is there anything easier for me to try because i don't know where to begin with this one...
I think i need somethin easier to understand fully how to use polar..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: hendie on November 12, 2003, 11:52:42 AM
Quote from: amgirard2003

(setq pt1 (getpoint "\nSelect a point: ")
      pt2 (getpoint pt1
          "\Select the distance and angle of the square: "
          )


You're asking the user to pick a point which is then saved to PT1,
You're then asking the user to pick a distance and angle which is then saved to PT2

a small clue ~ look at the sequence of things !

you're correct about the first part (pt1) but then...
you are then asked to pick another point ~ giving PT1 as an argument simply allows Acad to "rubberband" between the points being picked. So, you have picked Point 1 and then picked point 2.... look at the sequence of the code what does it do after picking point 2 ?

(I hope I've helped  :oops: )
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 12, 2003, 12:05:33 PM
No one who took the course has actually been able to solve the exercise at this stage - but it doesn't really matter. The objective is not to solve it perfectly, but to start thinking about ways to aquire the tools in order to solve a problem. There've been great attempts to solve it, though.

Did the polar notation in AutoCAD tell you something about POLAR?

Andre, do you want a proposed solution to 2.5?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 12, 2003, 12:22:28 PM
Code: [Select]
pt3 (polar pt2
(+ (angle pt1 pt2) (/ pi 2))
(distance pt1 pt2)
)

(polar pt2... is the base point for pt3.
(angle pt1 pt2) is just the angle between pt1 and pt2.
(+ (angle pt1 pt2) (/ pi 2)) is taking the angle of pt1 and pt2 and turning it 90 degrees counterclockwise relative to pt1 and pt2.
(distance pt1 pt2) is telling pt3 the distance it will be from pt2.

Does this make sense?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 12, 2003, 12:27:24 PM
Quote from: SMadsen

Did the polar notation in AutoCAD tell you something about POLAR?

Andre, do you want a proposed solution to 2.5?



I think i understand what Polar means... It's getting into my head just slower than what i want it to..

I don't want any answers to 2.5 but i would like to do other examples that will help me solve Exercise 2.5.
Make any sense?

I was bangin my head tryin to figure out how to "rubberband"
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 12, 2003, 12:32:06 PM
Quote from: Daron
Code: [Select]
pt3 (polar pt2
(+ (angle pt1 pt2) (/ pi 2))
(distance pt1 pt2)
)

(polar pt2... is the base point for pt3.
(angle pt1 pt2) is just the angle between pt1 and pt2.
(+ (angle pt1 pt2) (/ pi 2)) is taking the angle of pt1 and pt2 and turning it 90 degrees counterclockwise relative to pt1 and pt2.
(distance pt1 pt2) is telling pt3 the distance it will be from pt2.

Does this make sense?


Ummm...In english yeah...( not in code )

(+ (angle pt1 pt2) (/ pi 2)) is confusing me, how does this make any reference to rotating to 90 degree?? i just don't see it..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 12, 2003, 12:34:39 PM
Quote
I was bangin my head tryin to figure out how to "rubberband"

Do you understand how, now. What about a rectangular rubberband? As far as understanding polar, think of it as slow roasting. Eventually, the flavor gets in and sticks and the turkey tastes much better this way.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 12, 2003, 12:35:55 PM
Rectangular "rubberband" you would be referencing 3 points correct?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 12, 2003, 01:12:15 PM
Quote from: amgirard2003
Rectangular "rubberband" you would be referencing 3 points correct?

Instead of (setq pt1 (getpoint "\nblah blah:") pt2 (getpoint pt1 "\nSame"))
See what this does for you:
Code: [Select]
(setq pt1 (getpoint "\nPick a point: ") pt2 (getcorner pt1 "\nGet opposite corner: "))
I wouldn't use it for a polar function, I just wanted to open your mind to more ideas.
Code: [Select]
(+ (angle pt1 pt2) (/ pi 2))
Break it down. What's (angle pt1 pt2) doing? Read the help file on angle. To help you with seeing what's happening, take the + symbol and change it to - (minus) in both points. Then run the command. What happens now? I feel this is a good way to help you understand how the code works. Let us know what you find.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 12, 2003, 01:31:05 PM
Quote from: Daron
Quote from: amgirard2003
Rectangular "rubberband" you would be referencing 3 points correct?

Instead of (setq pt1 (getpoint "\nblah blah:") pt2 (getpoint pt1 "\nSame"))
See what this does for you:
Code: [Select]
(setq pt1 (getpoint "\nPick a point: ") pt2 (getcorner pt1 "\nGet opposite corner: "))
I wouldn't use it for a polar function, I just wanted to open your mind to more ideas.


Maybe i should try and go through all the functions and learn them..
Every post is posting another function i haven't heard about before..

code:
--------------------------------------------------------------------------------
(+ (angle pt1 pt2) (/ pi 2))
--------------------------------------------------------------------------------



Break it down. What's (angle pt1 pt2) doing? Read the help file on angle. To help you with seeing what's happening, take the + symbol and change it to - (minus) in both points. Then run the command. What happens now? I feel this is a good way to help you understand how the code works. Let us know what you find.

What is (/ pi 2) doin? what are you tryin to say in English?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 12, 2003, 01:36:09 PM
Are you familiar with angles expressed in radians instead of degrees?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 12, 2003, 01:45:23 PM
Quote
Maybe i should try and go through all the functions and learn them..
Sorry, there I go again, adding too much to the mind warp called lisp. You'll learn them as you ask questions and start using them. That help file will be useful, but not as useful as asking someone how to use the function. Anyway (/ pi 2)? Simply, that will give you an angle, 90 degrees from zero (east) in autocad in radians. (+ uang (/ pi 2)) is adding the user angle to 90 degrees to make the polar angle 90 degrees to the user angle. Does that help? Experiment with dividing pi by different numbers and subtracting instead of adding and multiplying instead of dividing.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 12, 2003, 02:13:25 PM
By the way, Andre. You won't need ANGLE or any arithmetic to solve 2.5. The answer is right before your eyes if you run the ARC command.

The routine shall draw an arc based on 1. center point of arc, 2. radius, 3. start angle and 4. end angle. The only way this differs from the normal ARC command is that radius and angle are given separately. Consider this sequence:

Command: ARC
Specify start point of arc or
: CE
Specify center point of arc: pick center point
Specify start point of arc: pick start point = radius and angle in one!
Specify end point of arc or [Angle/chord Length]:

At the last prompt you can specifically specify Angle in order to input an angle or simply pick a point where the angle from the center point to this point will be the end angle.

Here are some more tips - well, actually pseudocode for the entire thing:
Get center point with GETPOINT
Get radius with GETDIST
Get start angle with GETANGLE
Calculate start point with POLAR (hint: center point, start angle and radius are all specified by now)
Start the ARC command, use the data above and let it allow the user to pick the end point
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 12, 2003, 02:46:54 PM
Quote from: Daron
Quote
Maybe i should try and go through all the functions and learn them..
Sorry, there I go again, adding too much to the mind warp called lisp.You'll learn them as you ask questions and start using them.


I think before we go any further and i think this will help me out..
Would it be possible to create a list of the functions i should learn about..
It's easy to say you'll learn them as you go along..
But just like Smadsen just said

Quote
Get center point with GETPOINT
Get radius with GETDIST
Get start angle with GETANGLE


It's easy to say that when you know the functions... right now i know
GETPOINT, GETREAL, PROMPT, SETQ, COMMAND, DEFUN...
I think i should concentrate on learning some of the functions.

Correct me if i'm wrong in thinking about doing this?In the quote from Smadsen (GETDIST) (GETANGLE), i would have never ever thought of those..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 12, 2003, 03:21:29 PM
Well, then that's where you start. Study the getxxx functions, starting with those and get this exercise working. You don't have to know every function to know how to program. I mean, entsel, nentsel, nentselp and ssget all select objects. Do you need to use all of them? For different things yes, but you don't have to use all of them now. I've never used nentselp, because I haven't found a need yet. For a long time I didn't understand the difference between entsel and nentsel. On the surface they seemed like the same thing to me. When I realized the difference, I took to thinking to incorporate nentsel more often, being aware that entsel could keep the user out of a block selection, if I didn't want them in it. In short, learn what we try to teach you here. You'll eventually stumble across the others and either figure them out or ask questions about them.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 13, 2003, 08:32:00 AM
I did some homework last night..

(GET) functions:- Getting User Input

***********************************************

(getreal):- Enter a real number from keyboard.
              - Secures a real number.

(setq a (getreal "Enter a number"))

A real number is assigned to "a" through the keyboard
Avoid using distances and angles with this command

***********************************************

(getdist):- Enter a real number from keyboard or point to distance
             - Secures a real number.

ex: (setq a (getdist "Enter Height" ))
      (setq pnt1 (getdist "Pick a Point" ))
      (setq a (getdist pnt1 "Pick a Point" ))

The last example references the first point "pnt1" and allows the point
"a" to be rubberbanded to "pnt1".

***********************************************

(getstring):- Enter String (text) from keyboard.
                - Command asks you to supply a string of text.

ex: (setq a (getstring "Enter Text" ))

You may supply optional "Flags" which are numbers after the function.
If a "flag" is present (which is a number) then spaces are allowed. No "flag"
then no spaces are allowed.

***********************************************

(getcorner):- Pick the other corner.
                 - Works just like (getpoint), except it assumes one point
                   has already been chosen.

ex: (setq a (getcorner pnt1 "Pick another point" ))

Once again "pnt1" referenced so this allows for a rubberband to be displayed.

***********************************************

(getpoint):- Pick a point
               - is an input request to pick a point.
               - Nothing further will happen until a point is picked.

ex: (setq a (getpoint "Pick a point" ))

The result is "pnt1" is a list of 3 values.
X, Y, Z, coordinates of "pnt1"

***********************************************

(getorient)(getangle):- Find Angle
                               - Allow you to find and angle by pointing to
                                 two points.

ex: (setq a (getangle "Select Angle" ))

This can either be used for point selection or keyboard input.

ex: (setq a (getangle "Select Angle" pnt1 ))

Once again another example of rubberbanding a function with a previous declared variables.

**************************************************

(getkword):- Key Word
                - Used with (initget) function (flags)

ex: (initget 1 "I E")
      (setq a (getkword " (I)ntersection or (E)ndpoint" ))

1 = F;ag which is set for "null input not allowed" which means "Enter" by itself
"I E" = Are the key initials for reference

**************************************************

(getint):- Enter an Integer from keyboard
           
ex: (setq a (getint "Enter a Number" ))

Note: If decimals are required use (getreal) function (getint) does not return decimals.

ex: 15.0 = 15

**************************************************


These are notes that i made from last night..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 13, 2003, 08:50:24 AM
Quote
- Used with (initget) function (flags)

Very good. Now, read up on initget. It's useful for more than getKword. Also, the getstring function can use T for the flag in lieu of a number.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 13, 2003, 11:34:39 AM
I'm just gonna post and let all the people that are helpin me out that i'm gonna go through some functions and post some more notes for you to review..
I will be reading these over to fully understand them and i will post further questions as the arise.

If you have any questions for me to answer as tests that would be great as well.

Thanks
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 13, 2003, 01:58:50 PM
I'm getting a little further with Exercise 2.5 but getting stuck again.

Does this make any sense so far?

(defun c:arctest ()
  (setq pnt1 (getpoint "\nSelect Center Point: "))
  (setq ang (getangle pnt1 "\nSelect Angle of arc: "))
  (setq rad (getdist "\nEnter Radius of arc: "))
  (setq pnt2 (polar pnt1 (angle pnt1 ang) (distance pnt1 ang)))
)

I'm slowly working on it, but always running into a stumbling block..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 13, 2003, 02:24:21 PM
For starters, what type of input do angle and distance require and what are you passing to it?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 13, 2003, 02:40:28 PM
Angle & Distance:- Is inputed as radians but needs to be converted to Degrees.

So i'll have to create a function to convert radians to degrees and add this to the polar function... correct??
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 13, 2003, 02:45:53 PM
Just out of curiousity:

I've just read through that tutorial (which is pretty stinkin' nice BTW) and I'm a little confused about what excercise 2.5 hopes to accomplish.

I know that different people have different methodology and different terminology when it comes to using Autocad so I thought that maybe it was losing something for me in translation.

The obsessive compulsive/ADHD part of me reads what's being requested and wonders "Why? That just makes the ARC command more complicated than it needs to be." so I was hoping to get a little enlightenment.

Understand that I am in no way knocking the tutorial. I think it's awesome. It's just that I'm confused about what's being requested of the pupil in excercise 2.5 and what that excercise attempts to teach.  :?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 13, 2003, 03:18:31 PM
Quote from: amgirard2003
Angle & Distance:- Is inputed as radians but needs to be converted to Degrees.

So i'll have to create a function to convert radians to degrees and add this to the polar function... correct??


I hope I didn't ask what the Angle & Distance functions return to the user. I want you to tell what is needed for them to work?
Multiple choice:
a) integers
b) reals
c) point coordinates
d) strings

Ex. (angle a b)
You need to tell angle and distance two things. What are they? The return value will be a radian as a real or a distance as a real.

Don't worry about a dtr or rtd function yet. I rarely use those. There are ways around them.

==========================
NivuahC, I haven't studied the tutorial. I've only read the requirements of 2.5. The first point is polar and that's the hardest for a beginner to use IMO. I'm just trying to help him understand it so he can continue. I see it this way: The user picks a point (center) and a second point (first angle and radius) and defines the arc angle. Pause might be placed where the arc angle is, thus shouldn't be used in a setq, but left for the time the user needs to input this.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 13, 2003, 04:29:52 PM
nivuach, the intention of the first 2-3 lessons in this course is to get the "student" acquainted with AutoLISP by using the user interface of AutoCAD.

In lesson 1 it starts out at the command line with simple expressions that merely returns a value, then returns a value to a command and then returns a value to a command through input via some GETxxx functions. Step by step, AutoLISP is "taking over" the command to show that much of the UI in AutoCAD can be accessed and controlled by AutoLISP.

It's my experience that - for beginners - it works quite well to learn AutoLISP by opening a door to it from AutoCAD, instead of opening a door to AutoCAD from AutoLISP.

Anyway, I see now that I might have to revise that particular exercise! It should let the "student" play with some GETxxx functions (some of which are covered in lesson 1 that Andre didn't get) and create data to be used with an AutoCAD command - only with a twist so that it's not totally identical to the command itself.

Besides, it should help get the "students" used to work with some info-hunting on their own. This course is over in 10 weeks and it only covers so many issues and functions. I don't like the idea of leaving someone without a clue of how to hunt for information. They should at least be able to look up a function and understand what it does when the support from me stops.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 13, 2003, 04:51:38 PM
Andre, forget about angle, forget about radians and degrees, - you don't need it to solve the exercise. It doesn't matter if angles are expressed in degrees, radians or parsecs. GETANGLE will pass the correct data and we don't even want to know what it is.
You could actually write the POLAR statement like this:

Code: [Select]

(setq startpoint
  (polar
    (setq pnt1 (getpoint "\nSelect center Point: "))
    (getangle "\nSelect start angle of arc: ")
    (getdist "\nEnter radius of arc: ")
  )
)


Notice that center point will have to be saved in a variable because the ARC command will use it, but the radius and the angle is only used to calculate a start point. We don't want to know what the radius or the angle is, only what the calculated start point is.

Once you have a center point and a start point, then you can feed it to the ARC command and let the command take over so that the user can finish the arc (with the help of PAUSE, for example).
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 13, 2003, 05:16:28 PM
Quote from: SMadsen

You could actually write the POLAR statement like this:

Code: [Select]

(setq startpoint
  (polar
    (setq pnt1 (getpoint "\nSelect center Point: "))
    (getangle "\nSelect start angle of arc: ")
    (getdist "\nEnter radius of arc: ")
  )
)



I wasn't even close  :oops:
Now that blows me away...  :?

Would have never thought of doing it that way..

I was under the impression that when you used the polar function that you had to have the variables declared and set before using it in the function like this:


(defun c:arctest ()
(setq pnt1 (getpoint "\nSelect Center Point: "))
(setq ang (getangle pnt1 "\nSelect Angle of arc: "))
(setq rad (getdist "\nEnter Radius of arc: "))
(setq pnt2 (polar pnt1 (angle pnt1 ang) (distance pnt1 ang)))
)

I was never aware that you could invoke the function and set variables on the fly within the function..

Is there anything else i should know about putting syntax together like the example above?[/code]
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 13, 2003, 06:07:48 PM
Andre, what I just showed is a very bad way to do it. When you get a bit more experienced you will want to verify values before use. Nesting functions that may produce invalid data is not good (if the user hits Enter to any of the GETxxx functions above they will return nil, which will crash POLAR).  I merely showed it as an example to underline that we don't really care about what the radius or angle is. Those are the users choices and all we need to do is to calculate a start point for the user.

If you are determined to solve 2.5 then try out the ARC command in AutoCAD, see in what direction is goes when you specify center point first ("CEnter") and then see how your own center point and start point - aquired via GETPOINT and POLAR - could fit in.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 13, 2003, 07:04:05 PM
I'm gonna give the strongest hints I can on this exercise and it may even turn out to be a solution, so whether you want to read it or not is up to you. I recommend reading it, though!


You already know that you need a center point, and you have also shown that you know how to get it:

(setq pnt1 (getpoint "\nSelect Center Point: "))

Great, we are assuming that the user picked a point so now you have a point saved in the variable pnt1. We don't want to know what a point is at this point (no pun intended) - it's just a point that AutoLISP knows how to handle.

The exercise states: "Create a new command that asks for a center point, a radius, a starting angle and an ending angle.", so next step is to get a radius from the user. You know now that it can be done with GETDIST - a function that either accepts a number that is typed directly at the command line or it accepts that the user picks two points on screen from which it calculates the distance automatically. Whatever way it gets the distance, it returns it as a number.

However, if the user decides to pick a distance on the screen, we don't want him to actually pick two points. Why? Because we already know the center point and it would be very natural that the user wants to see the center point when he specifies the radius. So, looking up GETDIST in the help reference, we notice that it can take two arguments - both optional:

(getdist [pt] [msg])

The msg argument, you already know what is - it's the prompt written to the screen. The other argument, pt, is a point that serves as a starting point for the distance being dragged on screen. So, try to insert the center point, pnt1, and see what happens. Try this sequence at the command line in AutoCAD:

Command: (setq pnt1 (getpoint "\nSelect Center Point: "))
Select Center Point: [pick a point]
(9.58282 4.83715 0.0)

Command: (setq rad (getdist pnt1 "\nEnter Radius of arc: "))
Enter Radius of arc: [notice the anchor point, the rubber band and go pick a point]
7.02746

Did you notice that GETDIST anchors the first point at the center point that you just specified? Also, it drew a rubber band between the anchor point and your crosshair cursor? This is exactly what e.g. the LINE command uses to draw a line segment; after giving it the first point and the second point, you don't need to specify a first point again if you stay in the command and decides to draw one more line segment.

Now we have code to get the center point and the radius. The latter even with a nice interface that holds on to the center point and draws a rubberband from it:

(setq pnt1 (getpoint "\nSelect Center Point: "))
(setq rad (getdist pnt1 "\nEnter Radius of arc: "))

Next we want a starting angle. GETANGLE works exactly like GETDIST: it either accepts a number typed at the command line or it accepts two points picked on screen. The only difference between GETDIST and GETANGLE is that GETANGLE returns the angle between the points (alternatively the angle typed at the command line) instead of the distance. GETANGLE can also anchor the first point by giving it a point as an argument. The syntax is no different than GETDIST:

(getangle [pt] [msg])

So, we will again make the assumption that the user would want to drag the angle from the center point - that would be a natural way to specify the angle for an arc. We simply supply the center point again and, of course, your nice prompt:

(setq ang (getangle pnt1 "\nSelect Angle of arc: "))

Oh wait, you had already supplied the point in your code?! Good job! :)

Now we have a center point, a radius and an angle from the center point to the start point. However, we do not know where the start point is. When the user dragged the radius, it didn't need to be the start point of the arc that he specified. Nor is it for certain that he specified the start point when dragging the angle.
If either really was the intended start point, then we have no way of intercepting the point a which he clicked because we used GETDIST and GETANGLE and they do not return a point. But we don't care. Why? Because we have data enough to calculate it!

POLAR takes a point, an angle and a distance. When you have those data, it is geometrically possible to calculate a unique point, and that is what POLAR does. It calculates the point that lies at x angle and in y units from the point. So giving POLAR our center point, our angle and our distance, it spits out the start point of the arc:

(setq pnt2 (polar pnt1 ang rad))

All we have to do now is to start the ARC command through AutoLISP, invoke the right choices in the command and feed it the data. This is where you should run ARC in AutoCAD to make sure that you get the sequence right.

Let's try it and let us use the exclamation mark to call out those variables that we setq'ed previously. First we would want to specify the center point, so in ARC we call the subcommand "CE" to make it accept the center point.
Then we give it the center point and notice that it will want a start point. Oh my, we do have start point! Cool. Give it the start point and then .. umm, then what? Then nothing. Let the user finish the command by letting him specify an end point.

Command: arc
Specify start point of arc or
: CE
Specify center point of arc: !pnt1
(9.58282 4.83715 0.0)
Specify start point of arc: !pnt2
(14.592 9.76599 0.0)
Specify end point of arc or [Angle/chord Length]: [pick an end point on screen]

And there you have a nice arc drawn with the specifications that we asked of the user. Only thing that remains is to write this with the help of the COMMAND function in AutoLISP. Oh, and to arrange all the expressions that we wrote into a DEFUN.

Will you do that, Andre?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 13, 2003, 09:09:08 PM
You bet...
Good morning all...
Well after Smadsen explanation made things a lot more sense to me..

Here's is what i came up with after reading his previous post.

Code: [Select]

(defun c:arctest (/ pnt1 rad ang pnt2 cmd)
  (setq pnt1 (getpoint "\nSelect Center Point: "))
  (setq rad (getdist pnt1 "\nEnter Radius of arc: "))
  (setq ang (getangle pnt1 "\nSelect Angle: "))
  (setq pnt2 (polar pnt1 ang rad))
  (setq cmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (command "arc" "c" pnt1 pnt2 pause)
  (setvar "cmdecho" cmd)
  (princ)
)


I was getting stuck on the ( Start and Ending of Angle ), i know it sounds dumb but that part was confusing me like crazy.

And another thing.. I'm very happy that Smadsen made somethin look very interesting to me.. The last part of his post, running through the "ARC" command with the variables as opposed to just doin the command without them.. It made a lot more sense when i saw it that way..

Thanks,
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 14, 2003, 10:29:00 AM
Any other exercises for me to work on would be great?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 14, 2003, 10:51:44 AM
Very well done!! Glad you finally did it, Andre.

I know angles can be hard to get a grip on at this stage, but do you see now that the finished code doesn't really care about the angles? Well, as an argument to POLAR, yes, but it doesn't use angles for anything else than that. They could be measured in Newton or in nautical miles for all we care. All the code cares about is to set up communication with the user and prepare data in order to feed a frequently used AutoCAD command.

Anyway, excellent solution. Everything is in right order and local variable declarations are remembered. Even saving and restoring CMDECHO is there. Good job.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 14, 2003, 10:57:55 AM
Well, you could write a function that makes a rectangle from two diagonally picked points. That exercise is a classic. It would keep you in the current line of thinking and still let you explore something new, like lists!

The description would be:
Ask the user for a lower left corner and an upper right corner of a rectangle. Write code that calculates the two missing corners and draws a closed polyline using all four corners to form the rectangle.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 14, 2003, 11:03:16 AM
Thanks Smadsen,

I'll go over Lists in my book and see how it works and i'll post any questions or comments after i'm done..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 14, 2003, 11:52:21 AM
Smadsen here's what i got..

Code: [Select]

(defun c:REC (/ pnt1 pnt2 pnt3 pnt4 cmd)
  (prompt "\nThis will create a Rectangular Pline ")
  (setq pnt1 (getpoint "\nSelect Starting Point: "))
  (setq pnt2 (getcorner pnt1 "\nSelect Opposite Corner: "))
  (setq pnt3 (list (car pnt2) (cadr pnt1)))
  (setq pnt4 (list (car pnt1) (cadr pnt2)))
  (setq cmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (command "pline" pnt1 pnt4 pnt2 pnt3 "c")
  (setvar "cmdecho" cmd)
  (princ)
)


What do you think?
Pretty impressive i must say... i surprised myself by actually doin this.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 14, 2003, 12:06:40 PM
That's good. Can you make a rectangle at any angle using two points for width and a third point or user input for length?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 14, 2003, 12:30:09 PM
Quote from: amgirard2003
What do you think?
Pretty impressive i must say... i surprised myself by actually doin this.

Pretty darn impressive! Ok, be honest, where did you get that code? :D
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 14, 2003, 01:11:23 PM
Quote from: Daron
That's good. Can you make a rectangle at any angle using two points for width and a third point or user input for length?


O.k Need help with this one..getting lost...
Can't figure out how to do this one..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 14, 2003, 01:12:41 PM
Quote from: SMadsen
Quote from: amgirard2003
What do you think?
Pretty impressive i must say... i surprised myself by actually doin this.

Pretty darn impressive! Ok, be honest, where did you get that code? :D


Out of my brain baby!!!  :lol:
I read about lists last night so it was still fresh in my head..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 14, 2003, 01:31:04 PM
O.k I started with the following

Code: [Select]
(defun c:rec ()
 (Prompt "\Pline Rectangle" )
 (setq len (getdist "\nEnter Length: "))
 (setq wid (getdist "\nEnter Width: "))
 (setq pnt1 (getpoint "\nEnter Starting Point: "))
 (setq ang (getangle pnt1 "\nEnter Angle: "))

 

That's how far i got so far..
don't know where and how to use the width and length  variables..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 14, 2003, 04:24:23 PM
Let's see if I can spell out what to do.
-user selects ponit for start of rectangle - pnt1
-user needs length of rectangle.
   method one - user could type the length
   method two - user could use second from pnt1 as length
-user needs width or height of rectangle.
   same as above
-program needs to calculate the angle between pnt1 and pnt2 to get the angle from pnt1 and pnt2 to pnt4 and pnt3, respectively.
Does that help?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 17, 2003, 08:37:32 AM
Mornin, How's everyone after a fine weekend..

I'm working on the following:

Quote
Can you make a rectangle at any angle using two points for width and a third point or user input for length?


Code: [Select]
(defun c:REC (/ pnt1 pnt2 pnt3 pnt4 cmd)
  (prompt "\nThis will create a Rectangular Pline ")
  (setq pnt1 (getpoint "\nSelect Starting Point: "))
  (setq wid (getdist pnt1 "\nEnter Width: ")) (terpri)
  (setq len (getdist pnt1 "\Enter Length: ")) (terpri)
  (setq ang (getangle pnt1 "\nSelect Angle: "))
  (setq pnt2 (polar pnt1 ang len)
  (setq pnt3 (polar pnt2 (+(angle pnt1 pnt2) (/ pi 2)) wid))
  (setq pnt4 (polar pnt3 (+(angle pnt1 pnt2) (/ pi 2)) wid))
  (setq cmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (command "pline" (pnt1 pnt2 pnt3 pnt4 "c"))
  (setvar "cmdecho" cmd)
  (princ)
)


This is what i've come up with but it's not working..
Entering of the Length and Width is confusing me.. i can't figure out how to apply this to the polar function..

Thanks for your help
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 17, 2003, 08:56:27 AM
Andre, you are almost there.

If you calculate pnt3 as the point that is raised 90 degrees from pnt2 then why don't you calculate pnt4 in the same manner, except raise it 90 degrees from pnt1?

Code: [Select]

(defun c:REC (/ ); pnt1 pnt2 pnt3 pnt4 cmd)
  (prompt "\nThis will create a Rectangular Pline ")
  (setq pnt1 (getpoint "\nSelect Starting Point: "))
  (setq wid (getdist pnt1 "\nEnter Width: "))
  (setq len (getdist pnt1 "\nEnter Length: "))
  (setq ang (getangle pnt1 "\nSelect Angle: "))
  (setq pnt2 (polar pnt1 ang len))
  (setq pnt3 (polar pnt2 (+ (angle pnt1 pnt2) (/ pi 2)) wid))

  ;;(setq pnt4 (polar pnt3 (+ (angle pnt1 pnt2) (/ pi 2)) wid))
  ;; ^ No good. It will just put pnt4 in the same direction
  ;; as pnt2-pnt3 at a distance of 2 times wid from pnt2

  (setq pnt4 (polar pnt1 (+ (angle pnt1 pnt2) (/ pi 2)) wid))
  ;; ^ This will create the same line as pnt2-pnt3, only it will
  ;; place it in pnt1

  (setq cmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)

  ;;(command "pline" (pnt1 pnt2 pnt3 pnt4 "c"))
  ;; ^ What is this? Shame on you :-)

  (command "pline" pnt1 pnt2 pnt3 pnt4 "c")
  (setvar "cmdecho" cmd)
  (princ)
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 17, 2003, 09:20:53 AM
Thanks Smadsen,

You're a great help...

Code: [Select]
(command "pline" (pnt1 pnt2 pnt3 pnt4 "c"))
   ^ What is this? Shame on you :-)


OOPS.. didn't even see that... i would have found that sooner or later

WOW... well i must say it's been 2 weeks and look where i'm at..
(applauds self on back)... Never thought i would ever get to this point, and to understand what i'm actually doing.. Reading those books made it a lot more diffcult then what it really is.. I know theres still a whole lot more for me to learn but i think i'm off to a great start..

Thanks for all of your help..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 17, 2003, 09:41:37 AM
Well now, here's what I did to learn lisp. I had something that I needed to do, like insert a block through a dialog, explode the inserted block and turn it into a group based on the block name, request an orientation (mirroring the group), and running a number of sqare footage calcs etc.

Why am I telling you this? To tell you to take something you do commonly that you'd like to find a better (easier or quicker) way of doing and start writing a routine for it. Write pseudo-code. Use the pseudo-code to make user-defined functions. Test them and ask questions about possible ways of attacking you problem.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 17, 2003, 01:34:42 PM
O.k
I'm gonna work on the original idea that i came into this forum with

Pseudo Code:

Prompt user with the following choices:

1) Three Phase
2) Double Phase
3) Single Phase
4) 600
5) 208


Once the choice has been made variables would be set according to what
choice they made:

1) Layer
2) Linetype
3) Pline Width
etc.

As well set system variables as well

1) Blipmode
2) cmdecho
3) osmode
etc.

Now let's see how i do at this... there's a few things i'm a little sketchy on but we'll see how it goes.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: nivuahc on November 18, 2003, 09:04:31 AM
Quote from: amgirard2003
Prompt user with the following choices:

....



In what context?

Drawing the objects or changing the object once it's already drawn?

Think about how you can make your program more efficient/easier for the end user.

In my experience, it's best to ask before creation because most users won't change something the way you intend them to once it's already drawn. It's like they have to do the work twice and they can't be bothered.

Now, in the case of drawings that already exist and need to be converted, consider how you might make the changes without any user intervention.

What's the basic setup of what you're trying to do and how is it being done now, if at all?

I assume it's electrical drawings... Are we talking about schematics? Are we talking about one-line diagrams? Are we talking about electrical site plans or what?

I'm more curious than anything. :)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 18, 2003, 10:25:14 AM
Nivuach,

The routine that i'm designing is for my own personal use,
I work with 3 other people but they will not be using routines that i will be devloping in the future ( Union Issues if you get my drift ).

The routine i want to create is when i enter the command,
It will prompt me what kind of line i would like to draw. i will then select
the type and the pline command will then be executed.
The problem right now it i flip from line to line so i'm always changing the current layer to another and so on, so it gets very annoying..
Just want to make it easier to flip from line to line without having to do all the other stuff..

We do some schematics and i am looking at developing some kind of routine that would involve slides and blocks and some other stuff as well.

But right now we are looking at developing a Base Map for a GIS application throughout the city where i live.
It's a huge project, we're using digital ortho photo for locationg pole locations and also doing field checks and doing measurements.

All in all it's a huge project..

Hope that clears it up a little
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 18, 2003, 10:30:29 AM
Se7en was working on a routine where you select a line and it gathers the info from that line to begin a new line. You might PM him and see if he'll show you unless he gets in here sometime. Is he still job hunting? I hope it's not for too long.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 08:57:13 AM
Got a question for you all..

Code: [Select]

(cond ((= ans "T")
(setvar "clayer" "612")
)
(setvar "ltype" "Three")
)


The question i have is how do i set the linetype to become "Three"
It's setting the current layer to "612"
I just want to get it to work first and then worry about the what if's after.


A little lost here..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 19, 2003, 09:09:29 AM
Would it work if you put the "ltype" setvar one level up into the cond? Where you have it now, it's acting as a test condition.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 09:23:38 AM
I'm using this routine with a setup that a consultant has setup for us..

Code: [Select]

(cond((= ans "T")
         (setvar "clayer" "612")
         (setvar "ltype" Three))
)


When i do this i get an error saying:

error: AutoCAD variable setting rejected: "ltype" "Three"

I don't know what to do..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 19, 2003, 09:26:38 AM
Quote from: amgirard2003
...how do i set the linetype to become "Three"...

Easy, you just call (setvar "CELTYPE" "Three")

Hey, that's what you asked :)  but I don't think it's what you meant.
First, there is no sysvar called "ltype". Second, I don't think you mean to use the string "T" as the symbol T? Third - as Daron mentioned - you probably want it to set CLAYER to "612" and CELTYPE to "Three" if ans is T? If that's the case then rearrange the expression to include (setvar "CELTYPE" "Three") within the first test:

Code: [Select]
(cond ((= ans T)
       (setvar "clayer" "1")
       (setvar "celtype" "Three")
      )
)


If it's a case of if-then-else, i.e. if ans is T then set layer, otherwise set linetype, then use it within its own condition. It's normal (not necessary, but normal) to make the last condition in COND return T by simply using T as a condition:

Code: [Select]
(cond ((= ans T)
       (setvar "clayer" "1")
      )
      (T (setvar "celtype" "Three"))
)


Or .. you could simply use an IF:
(if ans (setvar "clayer" "1")(setvar "celtype" "Three"))

That's probably not what you're after but take a look at it, anyway. It says, IF ans THEN set layer ELSE set linetype.
IF ans? Yes, COND and IF only looks to see if the condition evaluates to nil or another value than nil. It doesn't care about the actual return value if it returns anything else than nil. If it returns another value than nil (whatever the value) then it passes the test.
This means that your COND can simply look like this:

Code: [Select]
(cond (ans
       (setvar "clayer" "1")
       (setvar "celtype" "Three")
      )
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 19, 2003, 09:30:38 AM
I'm assuming your linetype Three exists. So, if it does, enclose it in quotes "Three". You also might want to change "ltype" to "celtype". "Ltype" is the command name for linetype. Not the same as the variable, "celtype". Those are the only problems I see.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 19, 2003, 09:31:36 AM
Hahaha! Now it's my turn to fall asleep at the wheel. Four minutes ahead of me.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 19, 2003, 09:33:18 AM
Heh, gotcha
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 09:40:24 AM
Thanks guys.
I wasn't sure if "ltype" was the correct variable..


Quote

Second, I don't think you mean to use the string "T" as the symbol T


I'm having the user input with keyword,
so my question is if you ask the user to input anything wouldn't you have
to use "String" as the symbol?

Code: [Select]

(defun c:nl ()
  (prompt "Run with Phil's routine only")
  (terpri)
  (initget 0 "T D S C E F")
  (setq ans
           (getkword "\nSelect Line: (T)hree/(D)ouble/(S)ingle/se(C)ondary/(E)600/(F)208: <> ")
  )

(cond((= ans "T")
(setvar "clayer" "612")
(setvar "celtype" "Three"))
)
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 19, 2003, 09:50:40 AM
Hey SMadsen, isn't terpri an obsolete function. I mean it still works, but does anybody really use it? Is it useful in Andre's routine?

Andre', that looks good, but remember, things that are the same in all conditions can be altered outside the condition statement. Also, you might consider creating a function to be called within the cond so you don't have to type the same variables over and over again. Example:
Code: [Select]
(defun chvars (clay lintype)
(setvar 'clayer clay)
(setvar 'celtype lintype)
(princ)
)

Write that outside the condition and/or outside the main function and call it like:
Code: [Select]
(cond ((= ans "T")
         (chvars "612" "Three" etc.)
        )
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Kerry on November 19, 2003, 09:51:00 AM
amgirard2003,
Just so that you know about this option :--

Note the [ ... ] in the prompt here.
If you now long press the right mouse button during the prompt .. then you will see the dialog box ..

and .. the < > are usually only used to enclose a default value.
 
and .. terpri was remove ' cause the "\n ... " makes it superfluous

Code: [Select]

(defun c:nl ( / ans)
  (prompt "Run with Phil's routine only")
  (initget 0 "T D S C E F")
  (setq ans
         (getkword
           "\nSelect Line: [(T)hree/(D)ouble/(S)ingle/se(C)ondary/(E)600/(F)208]: "
         )
  )
  (cond ((= ans "T")
         (setvar "clayer" "612")
         (setvar "celtype" "Three")
        )
  )
  (princ)
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 10:05:07 AM
(terpri)
I was referencing one of the books i have... it's quite old so i didn't know
it was old and wasn't in use anymore...
I'll remeber to use "\n"..

Daron,

I want to take one step at a time... I want to write it out so i can work with it and then improve the writting of the code afterwards..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 19, 2003, 10:05:50 AM
Ok, I thought wrong. Seeing your code, the string makes sense.

Time to learn some standard GUI techniques when asking for keywords. Notice how AutoCAD always offers keywords as entire words with one or a few uppercase letters in them? It's possible to choose a keyword by typing the uppercase letter(s) only, part of the keyword or the entire word.

In your code, it's only possible to make a valid choice by typing the uppercase letter. Not that it's wrong but it doesn't comply to the standards.
Of course, there is a problem with choosing "E600" and "F208" but take a look at the code below for a possible solution.

Also, notice that AutoCAD almost always put choices into square brackets and separate them with slashes? This has a distinct purpose. Try running the modified code below and, while executing GETKWORD, try to right-click:

Code: [Select]
(defun c:nl ()
  (prompt "Run with Phil's routine only")
  (terpri)
  (initget 0 "Three Double Single seCondary E E600 F F208")
  (setq ans
         (getkword "\nSelect Line [Three/Double/Single/seCondary/E600/F208] <>: ")
  )
  (cond ((= ans "T")
         (setvar "clayer" "612")
         (setvar "celtype" "Three")
        )
  )
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 10:12:03 AM
when i right click it it just says : nil
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 19, 2003, 10:14:52 AM
Wow, 3 posts came in while typing - talk about falling asleep! Nah, had a phone call and didn't refresh

Daron, I think TERPRI is still used for print-to-screen purposes. I use it when outputting other data than strings where (princ "\n")'s hurts the eye
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 19, 2003, 10:17:26 AM
Quote from: amgirard2003
when i right click it it just says : nil

Ok, try this sequence at the command line and right click where it says so (watch out for word wrap):

Command: (initget 0 "Three Double Single seCondary E E600 F F208")
nil
Command: (getkword "\nSelect Line [Three/Double/Single/seCondary/E600/F208] <>: ")
Select Line [Three/Double/Single/seCondary/E600/F208] <>: [right-click here!]
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 10:22:43 AM
I still get nil..
I think it might be because i might have changed the function of my mouse
What does right click on your mouse do?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 19, 2003, 10:25:09 AM
It brings up a popup that says:
Enter
Cancel
Three
Double
Single
seCondary
E600
F208
Pan
Zoom
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 19, 2003, 10:27:22 AM
Thanks Daron :)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 10:31:29 AM
nope not working over here..
It must be an Autocad 2004 improvement..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 19, 2003, 10:38:26 AM
Not that either. It has been implemented since 2000. After hitting enter after inputing (getkword ...) the command line should read:
Select Line [Three/Double...<>:. Are you right clicking at this point? Check this, under options->User Preferences, select Right-click Customization. Is command Mode set to "Shortcut Menu: enabled when command options are present"? If not, that is your problem.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 10:58:12 AM
I changed that setting and still nothing is working..
no shortcut menu...
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 19, 2003, 11:00:11 AM
What about the Default Mode in the same dialog? Is it set to Shourtcut Menu? In fact, put everything to Shortcut Menu.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 11:06:42 AM
nope not that either..
didn't work..
 :evil:
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 19, 2003, 11:19:54 AM
What do you get?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 11:25:12 AM
it seems to be acting like the "enter" key...
i get nil after i click the right button
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 19, 2003, 11:32:52 AM
Hmmm .. dunno what setting is stealing away the popup menu if not the ones Daron mentioned.
Anyway, in normal setup's this is why you see all those commands having a list of choices formatted like [option1/option2/...]

Even a command like OFFSET that only has one option, Through, offers it in square brackets so that the user can choose it in a right-click popup.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 19, 2003, 12:33:00 PM
Back on track: Have you gotten your function working yet?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 12:52:33 PM
Yeah let's get back on track here..
Well working on it slowly here..

Got a question..
I have a lintype that is not loaded.

1) how do i write the code to load a linetype?
2) what is the variable to change the scale of a particular line?
i don't want to do it globally
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 19, 2003, 01:01:23 PM
Have a looksy here (http://www.theswamp.org/phpBB2/viewtopic.php?p=323#323). You might read/skim the entire topic.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 01:20:33 PM
That's one hell of an example... it's flown over my head but i figured out how to load the linetype i was lookin for
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 19, 2003, 01:23:29 PM
Good. What's next? Post your writings and I/we'll show you how to make a reusable function of it, like I was talking earlier.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 19, 2003, 02:04:13 PM
o.k here's what i got...
Please take it easy on me i know you guys can rip it up pretty good..

(defun c:nl ()
(prompt "Run with Phil's routine only")
(initget 0 "T D S C E F")
  (setq ans
    (getkword "\nSelect Line [Three/Double/Single/seCondary/(E)600/(F)208]: <> ")
  )


(cond ((= ans "T")   
   (setvar "clayer" "612")
   (setvar "celtype" "Three"))
)

(cond((= ans "D")                
 (setvar "clayer" "612")
 (setvar "celtype" "Double"))
)

(cond ((= ans "S")
  (setvar "clayer" "612")
  (setvar "celtype" "Single"))
   
)

(cond ((= ans "C")
  (setvar "clayer" "622")
  (setvar "celtype" "Bylayer")
  (setvar "plinewid" 0.5))
)

(cond ((= ans "E")
  (setvar "clayer" "622")
  (setvar "celtype" "Hidden")
  (setvar "ltscale" 0.5))
)

(cond ((= ans "F")
  (setvar "clayer" "622")
  (command "linetype" "l" "*" "conversion.lin" ""))
  )
(princ)
)

How do i make it so when i start the pline command ( not to that point yet )
the polylines are lwpolylines?

How do i set ltscale of a particular line? i don't want to do it globally
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Kerry on November 20, 2003, 03:34:06 AM
Quote from: amgirard2003
it seems to be acting like the "enter" key...
i get nil after i click the right button


What is the value of your SHORTCUTMENU System Variable ??

 .. Try 11 .. check the Help file for info.

Do not 'click" the right mouse button .. try a long PRESS { hold it down & count to 1.2 }

Regards

.. now we switch back to your scheduled programme ..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Kerry on November 20, 2003, 03:46:04 AM
Regarding the COND  function :-
It may help to think of it as ;

do either
this
or this
or this ...

.. and your revised code will look something like this :-
Code: [Select]

(defun c:nl (/ ans)
  (prompt "Run with Phil's routine only")
  (initget 0 "Three Double Single seCondary E E600 F F208")
  (setq ans
         (getkword
           "\nSelect Line [Three/Double/Single/seCondary/E600/F208] : "
         )
  )
  (cond ((= ans "T")
         (setvar "clayer" "612")
         (setvar "celtype" "Three")
        )
        ((= ans "D")
         (setvar "clayer" "612")
         (setvar "celtype" "Double")
        )
        ((= ans "S")
         (setvar "clayer" "612")
         (setvar "celtype" "Single")
        )
        ((= ans "C")
         (setvar "clayer" "622")
         (setvar "celtype" "Bylayer")
         (setvar "plinewid" 0.5)
        )
        ((= ans "E")
         (setvar "clayer" "622")
         (setvar "celtype" "Hidden")
         (setvar "ltscale" 0.5)
        )
        ((= ans "F")
         (setvar "clayer" "622")
         (command "linetype" "l" "*" "conversion.lin" "")
        )
  )
  (princ)
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 20, 2003, 09:55:20 AM
And to take what Kerry gave you, I'll show you what I meant by creating a reusable function. The function at the bottom is what is doing the work. The portion at the beginning of the main routine is there to use the current variables values for the required arguments in the reusable function. Thus, the use of (cdr (nth num n)) in place of setting a variable (setvar).
Code: [Select]
(defun c:nl (/ ans var n)

  (setq var '("clayer" "celtype" "ltscale" "plinewid")
n   nil
  )
  (foreach item var
    (setq n (append n (list (cons item (getvar item)))))
  )

  (prompt "Run with Phil's routine only")
  (initget 0 "Three Double Single seCondary E E600 F F208")
  (setq ans
(getkword
  "\nSelect Line [Three/Double/Single/seCondary/E600/F208] : "
)
  )
  (cond ((= ans "T")
(chvars "612" "Three" (cdr (nth 2 n)) (cdr (nth 3 n)))
)
((= ans "D")
(chvars "612" "Double" (cdr (nth 2 n)) (cdr (nth 3 n)))
)
((= ans "S")
(chvars "612" "Single" (cdr (nth 3 n)))
)
((= ans "C")
(chvars "622" "Bylayer" (cdr (nth 2 n)) 0.5)
)
((= ans "E")
(chvars "622" "Hidden" 0.5 (cdr (nth 3 n)))
)
((= ans "F")
(chvars "622"
(cdr (nth 1 n))
(cdr (nth 2 n))
(cdr (nth 3 n))
)
(command "linetype" "l" "*" "conversion.lin" "")
)
  )
  (princ n)
  (princ)
)

(defun chvars (clay lintype lscale plwid)
  (setvar 'clayer clay)
  (setvar 'celtype lintype)
  (setvar 'ltscale lscale)
  (setvar 'plinewid plwid)
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 20, 2003, 10:37:44 AM
Daron can u fully explain what you just did cause that flew by me the speed of light...i'm not getting anything of what you just wrote.

1) How does it know what linetype to set if you didn't assign it the way i did in my example.
2) and the same for plinewidth and linetype scale

 :?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 20, 2003, 11:37:40 AM
Code: [Select]
(chvars "612" "Three" (cdr (nth 2 n)) (cdr (nth 3 n)))
This example will be the same for all. First, the routine sees the name chvars, it looks for a function called chvars. When it finds it, it looks in the argument list to see if there are any required arguments:
(defun chvars (required arg's here / local variables)
(...)
)
What you are doing with the example at the top is telling chvars to set each argument to what comes after the chvars call at the top. Since there are currently four required arguments, you need to call chvars with four values. Calling each value is like doing this in each successive call:
Code: [Select]
(defun chvars ()
(setq clay (setvar 'clayer "612")
        lintype (setvar 'celtype "Three")
        lscale   (setvar 'ltscale (getvar 'ltscale))
        plwid    (setvar 'plinewid (getvar 'plinewid))
)
(setvar 'clayer clay)
(setvar ''celtype lintype)
(setvar 'ltscale lscale)
(setvar 'plinewid plwid)
)

With reusable functions, you wouldn't have to type all that each time. This portion may not be the best place for reusable functions, because you aren't changing all values in each condition, but I was hoping to give you an understanding of modular programming (reusable code). I know we discussed this in the past and I think it was over your head then. I know it can be. The first time I saw a function with arguments, I didn't understand how that was possible. Really, until you write one, it won't make sense.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 20, 2003, 01:30:56 PM
Daron, Thanks for your reply and you're right.. It's flown over my head..

I'm keeping it simple and if it takes me to write variables over and over
then that's what i will have to do for right now.

I've fixed my code to what Kerry ahd mentioned i do with the (cond) conditional..

here's what i got so far... I know it's repetitive but it's somethin i see and understand what i'm lookin at, after i get it working i will look at improving the code and the look of it as well...


Code: [Select]
(defun c:nl (/ ans )
  (prompt "Run with Phil's routine only"); tell the user to use it with Phil's routine
  (initget 0 "T D S C E F"); Capital letters of all the Linetypes
  (setq ans
(getkword "\nSelect Line [Three/Double/Single/seCondary/(E)600/(F)208]: <> ")
  )
  (setq clay (getvar "clayer"))
  (setq cltype (getvar "celtype"))
  (setq pwidth (getvar "plinewid"))
 
  (cond ((= ans "T") ; Answer to equal Three Phase
(setvar "clayer" "612") ; Set variable "Current Layer" to 612
(setvar "celtype" "Three")) ; Set variable "Current Linetype" to Three
 
  ((= ans "D") ; Answer to equal Double Phase
(setvar "clayer" "612") ; Set variable "Curren Layer" to 612
(setvar "celtype" "Double")) ; Set varaible "Current Linetype" to Double

  ((= ans "S") ; Answer to equal Single Phase
(setvar "clayer" "612") ; Set variable "Current Layer" to 612
(setvar "celtype" "Single"))   ; Set variable "Current Linetype" to Single

  ((= ans "C") ; Answer to equal 120/240V
(setvar "clayer" "622") ; Set variable "Current Layer" to 622
(setvar "celtype" "Bylayer")   ; Set variable "Current Linetype" to Bylayer
(setvar "plinewid" 0.5))   ; Set Polyline Width to 0.5

((= ans "E") ; Answer to equal 600/347V
(setvar "clayer" "622")
(setvar "celtype" "Hidden")
(setvar "ltscale" 0.5))

((= ans "F") ; Answer to equal 120/208V
(setvar "clayer" "622")
(command "linetype" "l" "*" "conversion.lin" "")
(setvar "celtype" ))
  )

(princ)
(command "pline")
  (princ)
(setvar "clayer" clay)
(setvar "celtype" cltype)
(setvar "plinewid" pwidth)
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 20, 2003, 02:17:47 PM
Andre, did you test the routine? If so, then you might notice that the pline it allows you to draw is not put on the layer and drawn with the linetype that you want. Why?

Look at the last 4-5 lines. It calls the PLINE command alright, but it is not allowed to finish before setting 3 system variables. In other words: it resets the environment before drawing any plines.

If you can solve this problem then you have written yourself a nice little routine.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 20, 2003, 02:46:01 PM
I know how difficult that can be, so here's an old set of functions that should help. They should be simple enough.
Code: [Select]
(defun setpick ()
     (if (= (getvar "ltscale") 1)
 (setvar "ltscale" 48)
     )
     (command ".layer" "m" "an_notes" "c" "4" "" "")
     (setq lt (getvar "ltscale"))
     (setvar "OSMODE" 512)
     (setq a (getpoint "\nStart point of arrow: "))
     (setvar "OSMODE" 0)
     (setq b (getpoint a "\nDirection of arrow: "))
)

(defun ldrawing ()
     (setq waro (* laro 0.6))
     (setq aaro (angle a b))
     (command
 "PLINE"
 a
 "w"
 "0"
 waro
 (polar a aaro laro)
 "w"
 "0"
 "0"
 b
     ) ;_ COMMAND
     (setq c b)
     (while (setq c (getpoint c "\nNext point: "))
 (command c)
     ) ;_ WHILE
     (command "")
)
The part of the code in reference to Stig's suggestion is the end of the last function starting with (setq c b)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 21, 2003, 04:10:03 AM
Just wanted to add another, more generally purposed variant of this technique:

Code: [Select]
(command "PLINE")
(while (> (getvar "CMDACTIVE") 0)
  (command pause)
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 21, 2003, 07:50:06 AM
Quote from: SMadsen
Andre, did you test the routine? If so, then you might notice that the pline it allows you to draw is not put on the layer and drawn with the linetype that you want. Why?

Look at the last 4-5 lines. It calls the PLINE command alright, but it is not allowed to finish before setting 3 system variables. In other words: it resets the environment before drawing any plines.

If you can solve this problem then you have written yourself a nice little routine.


I've tested the routine and it's crashing at some points but i know what is doing that but i want to take care of that after i get this first issue out of the way.

I've looked at the last 4-5 lines like you said and can't see what you're tellin me.. I don't know what you're tryin to say.

Quote

Just wanted to add another, more generally purposed variant of this technique:


code:
--------------------------------------------------------------------------------
(command "PLINE")
(while (> (getvar "CMDACTIVE") 0)
  (command pause)
)
--------------------------------------------------------------------------------




Can you explain what you just wrote here... i have no clue
 :?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 21, 2003, 08:44:16 AM
Quote from: amgirard2003
Can you explain what you just wrote here... i have no clue :?

Not without having you do some tests. It's way easier to illustrate if you run the functions below and read the accompanying comments.

First start a fresh drawing. Create a new layer called "612" and set it to color red. Set layer "0" currently active and leave its color as the default 7 (white or black). Now load this test routine and run it. Draw one or two lines with it.

Code: [Select]
(defun C:TEST ()
  (setvar "CLAYER" "612")
  (command "LINE")
  (setvar "CLAYER" "0")
)


This little routine sets the layer "612" active, issues a LINE command and resets the layer to "0". The intension is naturally to put all new lines on layer "612" .. but it doesn't. Your lines will be put on layer "0".

Whenever AutoLISP issues an AutoCAD command with the COMMAND function, it does not stop up and wait for AutoCAD to do its stuff. This means that before you even get to click at the start point, AutoLISP will have speeded ahead and already executed any subsequent code. Thus, AutoLISP sets the layer to "0" before AutoCAD gets a chance to ask you to draw a line.

So, how do you politely ask AutoLISP to stop and wait while the user finishes a command? You already know one way: to use the symbol PAUSE.
But PAUSE will only hold AutoLISP back while specifying a single parameter in a command. Try this slightly modified version of the routine above:

Code: [Select]
(defun C:TEST ()
  (setvar "CLAYER" "612")
  (command "LINE" pause pause)
  (setvar "CLAYER" "0")
)


Cool. Now we at least get to draw a single line on the layer that we wanted. But if we stay in the command and want to draw more lines, AutoLISP will jump the speeder after the last PAUSE symbol and set the layer to "0".

We could put more PAUSE's in there but who are we to tell the user how many lines s/he is allowed to draw? So we'll have to find a way to stop AutoLISP entirely while there is a command active in AutoCAD.
This is what the system variable CMDACTIVE is for. It's simply a flag that tells if a command is active. If there are no commands currently running, this system variable will be 0 and all we have to do is check for that instance. By running a loop while a command is active we can detect when AutoCAD has finished doing its stuff. While a command is active, we simply issue the PAUSE symbol that allows the user to communicate with the command:

Code: [Select]
(defun C:TEST ()
  (setvar "CLAYER" "612")
  (command "LINE")
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )
  (setvar "CLAYER" "0")
)


Voíla, no more speeding tickets for AutoLISP. It sits neatly in its loop and supplies PAUSE's to the command until the user has finished. Then it sets the layer to "0".
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: Anonymous on November 21, 2003, 11:02:43 AM
Could someone go over the proper way to "SET" and "GET" system variables?
I'm doing something wrong cause the routine keep crashing on me and and and error of (System variables rejected "ltscale" "0")
I don't know what i'm doin wrong that is making my routine crap out

Code: [Select]
(defun c:nl (/ ans clay cltype pwidth)
  (prompt "Run with Phil's routine only")
; tell the user to use it with Phil's routine
  (initget 0 "Three Double Single seCondary E F") ; Capital letters of all the Linetypes
  (setq ans
(getkword
  "\nSelect Line [Three/Double/Single/seCondary/E(600)/F(208)]: <> "
)
  )

  (setq cmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq clay (getvar "clayer"))
  (setvar "clayer" "0")
  (setq ltype (getvar "celtype"))
  (setvar "celtype" "bylayer")
  (setq scal (getvar "ltscale"))
  (setvar "ltscale" 0)
  (setq pwidth (getvar "plinewid"))
  (setvar "plinewid" 0)


I wanna keep it simple for right now, so please try and keep that in mind
Thanks
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 21, 2003, 11:09:29 AM
There is no way to make system variables rattle on the settings that they accept. Before changing a system variable programmatically, it is expected of the programmer to know the allowed settings beforehand. If in doubt, always look up the system variable in the help reference before attempting to SETVAR it.

It makes no sense to set LTSCALE to 0. From the help file:

Quote
Type: Real
Saved in: Drawing
Initial value: 1.0000

Sets the global linetype scale factor. The linetype scale factor cannot equal zero.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 21, 2003, 11:09:44 AM
ltscale can't receive the value of zero. Anything else will work.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 21, 2003, 11:10:56 AM
Beaten by a mere second.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 21, 2003, 11:19:16 AM
Thanks Guys,
I just found that out... I was checking the variables and found what i had to set it too for it to work..

Well it seems to be working great but there are some good old bugs i'm gonna have to get rid of.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 24, 2003, 09:30:22 AM
Hey Guys,

O.k. here's the bugs i have to work out so be on the lookout for questions to come.

1) If the layer does not exist, then create it.

First question and i know we've been through this but wanna refresh,
Do i use the tblsearch function for this?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 24, 2003, 09:34:37 AM
That's one way.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 24, 2003, 09:36:49 AM
Think of TBLSEARCH and TBLNEXT as look-up functions. You can query the so-called symbol tables with them in order to get some common info on an entry, but you can't modify existing entries nor create new entries.

If a layer doesn't exist, I'd recommend that you use the LAYER command to create it - for now at least.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 24, 2003, 09:39:21 AM
Oh, just saw Daron's reply and have to rethink. Yes, TBLSEARCH is an excellent approach to test if a layer exists.

For example, to create a layer if it doesn't exist:

(if (not (tblsearch "LAYER" "612"))
  (command "LAYER" "Make" "612" "")
)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 24, 2003, 09:40:25 AM
Even if a layer does exist, using command layer to create it will not be a problem. All it will do is set the layer current and if you told it to be red instead of whatever color it already was, it would become red. So, you wouldn't need an if function either.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 24, 2003, 09:56:09 AM
(cond((= ans "Three")
   (setvar "clayer" "612")
   (not (tblsearch "Layer" "612"))
   (command "layer" "make" "612" "")
   (setvar "celtype" "Three")
)

Does that make any sense?
i was confused with how to apply it to the "COND" function.
If it's not right, How do i apply it to the "COND" function?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 24, 2003, 10:04:41 AM
If you are using "make", you don't need to search for it. It will be set whether it exists or not. You might want to consider doing this "_.layer" after command. Look here (http://www.theswamp.org/phpBB2/viewtopic.php?p=3630#3630) for the reasons why.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 24, 2003, 10:11:13 AM
Andre, as Daron pointed out, you don't really need to check if a layer exists because of how the "Make" option of the LAYER command works.
Thanks Daron ... for clearing up the smoke after my brain fart.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 24, 2003, 10:30:24 AM
How do i properly code it all with "COND"?
I'm confused on this part
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 24, 2003, 10:30:54 AM
I disagree. It may not be needed, but its good pratice in further applications (When he starts coding harder applications) to develp good programing habits. Why "make" a layer when its not needed.  (I undersand, that it could make the code harder to maintain, but its more of a "theory" thing then a "not necessary" thing. ) It will make his error trapping understanding a whole lot easier if he understands the concept of "do what is needed and not what is necessary."

Test the end users enviroment all you can, it will make your code that much more versatile later down the road.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 24, 2003, 10:50:04 AM
Andre, you already coded it using COND here (http://theswamp.org/phpBB2/viewtopic.php?p=3334#3334).

If you need more tests within each condition, you simply add it to the chunk of code that follows the condition.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 24, 2003, 10:58:25 AM
O.k i must not have made myself clear in my previous post, but what i'm confused with is this..

(cond ((= ans "Three")
    (setvar "clayer" "612")
    (not (tblsearch "layer" "612"))
    (command ".layer" "make" "612")
    (setvar "celtype" "Three"))
)

This does not work why?
What am i doing wrong in the code? I'm confused on how to write it out so if the layer doesn't not exist then create the layer.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 24, 2003, 11:00:26 AM
Where is it crashing? (Did you run each line to see what autocad returns?)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 24, 2003, 11:04:11 AM
it's crashing because layer "612" doesn't exist.
I want it to create the layer if it doesn't exist
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: JohnK on November 24, 2003, 11:06:48 AM
Ok, good. Comment each line of that code you posted and tell us what each line does. (In english)
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 24, 2003, 11:09:19 AM
Always remember to exit the COMMAND function as you would in AutoCAD - usually with an empty response.

(command ".layer" "make" "612") should be
(command ".layer" "make" "612" "")
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 24, 2003, 11:18:38 AM
(cond ((= ans "Three") Line 1
(setvar "clayer" "612")  Line 2
(not (tblsearch "layer" "612")) Line 3
(command ".layer" "make" "612") Line 4
(setvar "celtype" "Three")) Line 5
)

Line 1:- If ans equals "three" then do the following
Line 2:- Set layer to "612"
Line 3:- Check and see if layer "612" exist
line 4:- If it doesn't exist then create it
line 5:- Set lintype to "Three"


I think i might have answered my own question but i'll post it for your comments.

I should have line 3 & 4 before line 2 ??
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 24, 2003, 11:40:18 AM
Quote from: amgirard2003
Line 3:- Check and see if layer "612" exist

It certainly does - but that's all it does. It stands alone as a test condition and is therefore not used for anything. To do something with it, use it as a condition for an IF expression:

Code: [Select]
(cond ((= ans "Three")
      (if (not (tblsearch "layer" "612"))
        (command ".layer" "make" "612" "")
        (setvar "clayer" "612")
      )
      (setvar "celtype" "Three"))
)


This code says:
- if ans is equal to "Three" then do this:
- - if layer 612 does not exist then
- - - make layer 612 (create and set active)
- - otherwise
- - - set layer 612 active
- - set current ltype to "Three"

As Daron pointed out, there's no need to test if the layer exists before using "Make", but this is what you'd do if following Se7en's advice. I think in this case where the end result is setting the layer active, that I would follow Daron's advice. Se7en does have a point about the readability and logic of the code, though.

The real effort should be to see if the linetype exists. Because linetypes are dependent on external files and there are no easy way to simply create it (like a layer), there is a very real chance that it will crash if it doesn't exist.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 24, 2003, 11:45:01 AM
Quote from: SMadsen
To do something with it, use it as a condition for an IF expression:


Code: [Select]
(cond ((= ans "Three")
      (if (not (tblsearch "layer" "612"))
        (command ".layer" "make" "612" "")
        (setvar "clayer" "612")
      )
      (setvar "celtype" "Three"))
)


I've been testing it without the "IF"?
Is it alright to do that as well or should i use it like you showed above?

And another note.. I have the linetype loading but after it's loaded, it's crashing and asking me if i want to reload the layer.

I fixed this problem as well
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: SMadsen on November 24, 2003, 11:56:16 AM
No, it's not alright to use the condition as you did. What would be the purpose of it? Try to see the code in a a sequential manner. This is what you wrote:

Quote from: amgirard2003
Line 1:- If ans equals "three" then do the following
Line 2:- Set layer to "612"
Line 3:- Check and see if layer "612" exist
line 4:- If it doesn't exist then create it
line 5:- Set lintype to "Three"


Line 1 is alright, of course. But look at the next line: Set layer to "612". What would be the purpose first to set the layer active and then see if the layer exists?

The interpreter evaluates the code exactly as you write it. It will try to set a layer active when it sees (setvar "CLAYER" "612"), but if the layer doesn't exists it will crash right there.
So the proper sequence is to test if the layer exists and first then set it active if it was found.

Of course, line 4 is wrong all together. There is no IF in it, so the description would be:
line 4:- Create it
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 24, 2003, 12:56:15 PM
Alright guys here's what i got and it seems to be working pretty good. :D

Code: [Select]
(defun c:nl (/ ans cmd clay ltype scal pwidth)
  (prompt "Run with Phil's routine only")
; tell the user to use it with Phil's routine
  (initget 0 "Three Double Single seCondary E F") ; Capital letters of all the Linetypes
  (setq ans
(getkword
  "\nSelect Line [Three/Double/Single/seCondary/E(600)/F(208)]: <> "
)
  )

  (setq cmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq clay (getvar "clayer"))
  (setvar "clayer" "0")
  (setq ltype (getvar "celtype"))
  (setvar "celtype" "bylayer")
  (setq scal (getvar "ltscale"))
  (setvar "ltscale" 1.0)
  (setq pwidth (getvar "plinewid"))
  (setvar "plinewid" 0)
 
  (cond ((= ans "Three")
(if (not (tblsearch "layer" "612"))
  (command ".layer" "m" "612" "c" "6" "" "")
  (setvar "clayer" "612")
)  
(if (not (tblsearch "ltype" "Three"))
  (command ".linetype" "l" "*" "andre (newline).lin" "")
  (setvar "celtype" "Three")    
)  
)

((= ans "Double")
(if (not (tblsearch "layer" "612"))
  (command ".layer" "m" "612" "c" "6" "" "")
  (setvar "clayer" "612")
)
(if (not (tblsearch "ltype" "Double"))
  (command ".linetype" "l" "*" "andre (newline).lin" "")
  (setvar "celtype" "Double")
)
)

((= ans "Single")
(if (not (tblsearch "layer" "612"))
  (command ".layer" "m" "612" "c" "6" "" "")
  (setvar "clayer" "612")
)
(if (not (tblsearch "ltype" "Single"))
  (command ".linetype" "l" "*" "andre (newline).lin" "")
  (setvar "celtype" "Single")  
)
)

((= ans "seCondary")
(if (not (tblsearch "layer" "622"))
  (command ".layer" "m" "622" "c" "2" "" "")
  (setvar "clayer" "622")
)
(setvar "celtype" "Bylayer")
(setvar "plinewid" 0.5)
)

((= ans "E")
         (if (not (tblsearch "layer" "622"))
  (command ".layer" "m" "622" "c" "2" "" "")
  (setvar "clayer" "622")
)
(if (not (tblsearch "ltype" "Hidden"))
  (command ".linetype" "l" "*" "andre (newline).lin" "")
  (setvar "celtype" "Hidden")
)
(setvar "ltscale" 0.5)
)

((= ans "F")
(if (not (tblsearch "layer" "622"))
  (command ".layer" "m" "622" "c" "2" "" "")
  (setvar "clayer" "622")
)
(if (not (tblsearch "ltype" "OH_SECONDARY"))
 (command ".linetype" "l" "*" "andre (newline).lin" "")
 (setvar "celtype" "OH_SECONDARY")
)
)
  )
  (command "pline")
  (while (> (getvar "cmdactive") 0)
    (command pause)
  )
  (setvar "cmdecho" cmd)
  (setvar "clayer" clay)
  (setvar "celtype" ltype)
  (setvar "ltscale" scal)
  (setvar "plinewid" pwidth)
)



The only problem i have is after i load my routine and draw my first line
it draws the line on the correct layer and the correct color but it draws the line on the "BYLAYER". When i draw a second line it draws it correctly.
Any ideas? :?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: daron on November 24, 2003, 03:07:42 PM
As far as readability goes:
Code: [Select]
(setq cmd  (getvar "cmdecho")
      clay (getvar "clayer")
      ltype (getvar "celtype")
      scal (getvar "ltscale")
      pwidth (getvar "plinewid")
)
(setvar "cmdecho" 0)
(setvar "clayer" "0")
(setvar "celtype" "bylayer")
(setvar "ltscale" 1.0)
(setvar "plinewid" 0)

That, either with the setq's in place or as I have written, would make it more readable. It won't affect how the function runs though.

I still don't think you need to set the layer if it exists or create it if it doesn't. Let's say someone turned the layer color to 3 and your standards say it should be 6. If you just did (command ".layer" "m" "612" "c" "6" "" ""), you could forgo the if statement, the tablesearch and the setvar. Plus, you'd be able to enforce the color standard you seem to be implying. So really, you're just adding more code and making it less readable.

Quote
it draws the line on the correct layer and the correct color but it draws the line on the "BYLAYER".
What are you saying here? Do you want the object color to be different than the layer color? If not, it should be bylayer, if so, you need to set the color property to what you want it to be, but unless you're changing the color of a block, you normally wouldn't do that.
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 24, 2003, 03:20:17 PM
o.k here's the problem that is happening..

I start the routine, and i choose which line i want to draw.
I select T (three) as the line i want to draw.. ( T has a value of "612" as the layer name, "Magenta" as the color of the line and "Three" as the linetype.

When i draw my first line it draws the line on "612" (correct) , "magenta" (correct) and linetype is "Bylayer" (incorrect).
I erase that line and draw a new one and it draws it with all 3 variables correctly..
Does that make any sense or did i confuse you anymore?
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 24, 2003, 03:25:20 PM
And one other thing..

You guys have all been a great help... Don't know if i would have gotten this far on my own..
I've learned quite a bit and like se7en said in another post

Quote
You learn so frickin' much when you test, play arround and inspect each expression it would be stupid not to do so.


I've learned a lot by doing what he said to do..

Thanks for all your help, really appreciate it
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on November 24, 2003, 03:27:04 PM
Daron,

Once again i think i answered my own question to my problem..
I'll post and let you know..
Title: Newbie to world of (Lost in Stupid Parentheses) errr..(List)
Post by: amgirard2003 on December 03, 2003, 10:32:51 AM
Howdy!!!

Well first off things with the routine are working great..
No such problems have arisen..

Sorry i haven't checked in awhile, work has been pretty crazy around here.

Well i'm thinkin about doin another routine, just haven't figured out what i wanna do just yet... but will keep you posted.

Thanks for all your help, you've all been excellent teachers.

Dre