Jump to content

A little trouble with calculating points in LISP


MarcoW

Recommended Posts

I am trying to make my own lisp, I mean without cut / paste other routines into my own. This

one is an example wich I will "expand" as far as I have ideas.

Function of routine: draw a box with specified side length. Insertion point box must be

offset a certain distance from the actual insertion point. At last it should be rotate-able.

 

This is what I have got so far:

 

 
(defun c:box1 (/ len leng dist pt1 pt2 pt3 pt4 pt5 pt6)
(setq len (getint "\nLength1:  "))
(setq leng (getint "\nLength2:  "))
(setq dist (getdist "\nDistance:  "))
(setq pt1 (getpoint "\nInsertion:  "))
(setq pt2 (polar pt1 (* pi 0.5) dist))
(setq pt3 (polar pt2 (* 2 (* pi 0.5)) (* len 0.5)))
(setq pt4 (polar pt3 (* pi 0.5) leng))
(setq pt5 (polar pt4 0.0 len))
(setq pt6 (polar pt3 0.0 len))
(command "pline" pt3 pt4 pt5 pt6 pt3 "") 
(command "rotate" "l" "" pt1  pause)
(princ)
)

 

My questions / probs:

 

 
(defun c:box1 (/ len leng dist pt1 pt2 pt3 pt4 pt5 pt6)

 

No questions, given variables after the "/" are cleared after my routine ends.

 

 
(setq len (getint "\nLength1:  "))
(setq leng (getint "\nLength2:  "))

 

I had len1 and len2 but then it got stuck, I figured len1 can not be used in combination with the (polar ...) thingy below. Thats why I took the len and leng variable.

 

 
(setq dist (getdist "\nDistance:  "))

 

No probs...

(setq pt1 (getpoint "\nInsertion:  "))

 

No probs...

 

Calculations, with tears in my eyes:

 
(setq pt2 (polar pt1 (* pi 0.5) dist))

 

Polar is meant for an angle, am I correct?

-> (* pi 0.5) is 90 degrees I figured.

So: calculate point 2, it is "polared" to point 1, angle 90 degrees with a distance called "dist".

 
(setq pt3 (polar pt2 (* 2 (* pi 0.5)) (* len 0.5)))
(setq pt4 (polar pt3 (* pi 0.5) leng))
(setq pt5 (polar pt4 0.0 len))
(setq pt6 (polar pt3 0.0 len))

THese above must contain errors / faults for it does not work properly.

 

 
(command "pline" pt3 pt4 pt5 pt6 pt3 "") 
(command "rotate" "l" "" pt1  pause)
(princ)
)

Okay...

In short terms:

Can someone help me understand calculating this?

Do not give me the solution at once, let me struggle.

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    13

  • MarcoW

    10

  • David Bethel

    1

  • alanjt

    1

Top Posters In This Topic

Posted Images

This will hopefully explain things a little better, without just "giving you the answer".

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:box1  [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] len leng dist pt1 pt2 pt3 pt4 pt5 pt6[b][color=RED])[/color][/b]

 [i][color=#990099]; Define Functions and Localise Variables[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] len  [b][color=RED]([/color][/b][b][color=BLUE]getdist[/color][/b] [b][color=#ff00ff]"\nLength1:  "[/color][/b][b][color=RED])[/color][/b]
       
       leng [b][color=RED]([/color][/b][b][color=BLUE]getdist[/color][/b] [b][color=#ff00ff]"\nLength2:  "[/color][/b][b][color=RED])[/color][/b]

       [i][color=#990099]; I'd be more inclined to use "getdist"[/color][/i]
       [i][color=#990099]; so that the user can pick the distance.[/color][/i]
       
       dist [b][color=RED]([/color][/b][b][color=BLUE]getdist[/color][/b] [b][color=#ff00ff]"\nDistance:  "[/color][/b][b][color=RED])[/color][/b]
       
       pt1  [b][color=RED]([/color][/b][b][color=BLUE]getpoint[/color][/b] [b][color=#ff00ff]"\nInsertion:  "[/color][/b][b][color=RED])[/color][/b]
       
       pt2  [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt1 [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=BLUE]pi[/color][/b] [b][color=#009999]0.5[/color][/b][b][color=RED])[/color][/b] dist[b][color=RED])[/color][/b]
       

[i][color=#990099];;;                     + pt2[/color][/i]
[i][color=#990099];;;                     |[/color][/i]
[i][color=#990099];;;                     |[/color][/i]
[i][color=#990099];;;                     + pt1[/color][/i]

       
       pt3  [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt2 [b][color=BLUE]pi[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] len [b][color=#009999]0.5[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       

[i][color=#990099];;;            +--------+ pt2[/color][/i]
[i][color=#990099];;;           pt3       |[/color][/i]
[i][color=#990099];;;                     |[/color][/i]
[i][color=#990099];;;                     + pt1[/color][/i]
        
       
       pt4  [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt3 [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=BLUE]pi[/color][/b] [b][color=#009999]0.5[/color][/b][b][color=RED])[/color][/b] leng[b][color=RED])[/color][/b]

        
[i][color=#990099];;;           pt4[/color][/i]
[i][color=#990099];;;            +[/color][/i]
[i][color=#990099];;;            |[/color][/i]
[i][color=#990099];;;            |[/color][/i]
[i][color=#990099];;;            +--------+ pt2[/color][/i]
[i][color=#990099];;;           pt3       |[/color][/i]
[i][color=#990099];;;                     |[/color][/i]
[i][color=#990099];;;                     + pt1[/color][/i]
        
       
       pt5  [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt4 [b][color=#009999]0.0[/color][/b] len[b][color=RED])[/color][/b]
       

[i][color=#990099];;;           pt4               pt5[/color][/i]
[i][color=#990099];;;            +-----------------+[/color][/i]
[i][color=#990099];;;            |[/color][/i]
[i][color=#990099];;;            |       pt2[/color][/i]
[i][color=#990099];;;            +--------+--------+[/color][/i]
[i][color=#990099];;;           pt3       |       pt6[/color][/i]
[i][color=#990099];;;                     |[/color][/i]
[i][color=#990099];;;                     + pt1[/color][/i]
       
       
       pt6  [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt3 [b][color=#009999]0.0[/color][/b] len[b][color=RED])[/color][/b]

       [b][color=RED])[/color][/b]  [i][color=#990099]; End Setq[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_.pline"[/color][/b] pt3 pt4 pt5 pt6 pt3 [b][color=#ff00ff]""[/color][/b][b][color=RED])[/color][/b]

 [i][color=#990099]; Remember to use "_." prefix to make it[/color][/i]
 [i][color=#990099]; compatible for all language versions.[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_.rotate"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entlast[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]""[/color][/b] pt1 pause[b][color=RED])[/color][/b]

 [i][color=#990099]; Use "entlast" to detect last entity[/color][/i]
 [i][color=#990099]; added to database (hence created).[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b]

 [i][color=#990099]; Exit Cleanly[/color][/i]
 
 [b][color=RED])[/color][/b] [i][color=#990099]; End box1[/color][/i]

Link to comment
Share on other sites

This will hopefully explain things a little better, without just "giving you the answer".

 

Yes thank you Lee.

 

So the variable "pi" is like 180 degrees, for (* pi 0.5) gives 90 degrees. Using only pi gives the 180 degree angle, using 0.0 stays on 0 degrees. Makes sense.

 

I like the way you put the setq in the routine: this way i can see in an easy way if i have the right amount parenthesises.. -> ().

 

_. prefix tu use always, as a prefix in any command? Is that better?

Like (command "_.ddatte" etc..?

 

Strange thing is: when i open a clean new drawing an i try the command it sometimes draws "not okay". I mean, it looks like there is a variable not calculated right. That cannot be for it works sometimes.

 

See the images, can you place this? The left is gooed, the right image shows the #$%@ up one.

1.jpg

2.jpg

Link to comment
Share on other sites

I thought it might have something to do with the _.pline function so I took a rectangle to do the job.

 

Now it stays "in shap" but the dimension is not correct. ie. I create a box 1500 x 200 dist 100...

I get a box 1423 x 261 dist 100.

 

Aaargh...

Link to comment
Share on other sites

So the variable "pi" is like 180 degrees, for (* pi 0.5) gives 90 degrees. Using only pi gives the 180 degree angle, using 0.0 stays on 0 degrees. Makes sense.

 

"pi" is a recognised symbol in LISP, and the "polar" function take a angle argument in radians, hence fractions of 2*pi.

 

_. prefix tu use always, as a prefix in any command? Is that better?

Like (command "_.ddatte" etc..?

 

It is good coding practice to include this prefix, as it will account for versions in other languages.

 

Strange thing is: when i open a clean new drawing an i try the command it sometimes draws "not okay". I mean, it looks like there is a variable not calculated right. That cannot be for it works sometimes.

 

See the images, can you place this? The left is gooed, the right image shows the #$%@ up one.

 

This will be the OSnaps coming into play when you use the "_.pline" command.

 

You will need to turn them off and back on again to make this routine consistent.

Link to comment
Share on other sites

This will help you in turning off the OSNAPs, but if you want complete "security" in this routine, you will need to add an Error Handler to switch the OSNAPs back on if the user hits Esc.

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:box1  [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] oldos len leng dist pt1 pt2 pt3 pt4 pt5 pt6[b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] oldos [b][color=RED]([/color][/b][b][color=BLUE]getvar[/color][/b] [b][color=#ff00ff]"OSMODE"[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099]; Collect Old OSMODE setting[/color][/i]

 [i][color=#990099]; Define Functions and Localise Variables[/color][/i]

       len  [b][color=RED]([/color][/b][b][color=BLUE]getdist[/color][/b] [b][color=#ff00ff]"\nLength1:  "[/color][/b][b][color=RED])[/color][/b]
       
       leng [b][color=RED]([/color][/b][b][color=BLUE]getdist[/color][/b] [b][color=#ff00ff]"\nLength2:  "[/color][/b][b][color=RED])[/color][/b]

       [i][color=#990099]; I'd be more inclined to use "getdist"[/color][/i]
       [i][color=#990099]; so that the user can pick the distance.[/color][/i]
       
       dist [b][color=RED]([/color][/b][b][color=BLUE]getdist[/color][/b] [b][color=#ff00ff]"\nDistance:  "[/color][/b][b][color=RED])[/color][/b]
       
       pt1  [b][color=RED]([/color][/b][b][color=BLUE]getpoint[/color][/b] [b][color=#ff00ff]"\nInsertion:  "[/color][/b][b][color=RED])[/color][/b]
       
       pt2  [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt1 [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=BLUE]pi[/color][/b] [b][color=#009999]0.5[/color][/b][b][color=RED])[/color][/b] dist[b][color=RED])[/color][/b]
       

[i][color=#990099];;;                     + pt2[/color][/i]
[i][color=#990099];;;                     |[/color][/i]
[i][color=#990099];;;                     |[/color][/i]
[i][color=#990099];;;                     + pt1[/color][/i]

       
       pt3  [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt2 [b][color=BLUE]pi[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] len [b][color=#009999]0.5[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       

[i][color=#990099];;;            +--------+ pt2[/color][/i]
[i][color=#990099];;;           pt3       |[/color][/i]
[i][color=#990099];;;                     |[/color][/i]
[i][color=#990099];;;                     + pt1[/color][/i]
        
       
       pt4  [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt3 [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=BLUE]pi[/color][/b] [b][color=#009999]0.5[/color][/b][b][color=RED])[/color][/b] leng[b][color=RED])[/color][/b]

        
[i][color=#990099];;;           pt4[/color][/i]
[i][color=#990099];;;            +[/color][/i]
[i][color=#990099];;;            |[/color][/i]
[i][color=#990099];;;            |[/color][/i]
[i][color=#990099];;;            +--------+ pt2[/color][/i]
[i][color=#990099];;;           pt3       |[/color][/i]
[i][color=#990099];;;                     |[/color][/i]
[i][color=#990099];;;                     + pt1[/color][/i]
        
       
       pt5  [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt4 [b][color=#009999]0.0[/color][/b] len[b][color=RED])[/color][/b]
       

[i][color=#990099];;;           pt4               pt5[/color][/i]
[i][color=#990099];;;            +-----------------+[/color][/i]
[i][color=#990099];;;            |[/color][/i]
[i][color=#990099];;;            |       pt2[/color][/i]
[i][color=#990099];;;            +--------+--------+[/color][/i]
[i][color=#990099];;;           pt3       |       pt6[/color][/i]
[i][color=#990099];;;                     |[/color][/i]
[i][color=#990099];;;                     + pt1[/color][/i]
       
       
       pt6  [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt3 [b][color=#009999]0.0[/color][/b] len[b][color=RED])[/color][/b]

       [b][color=RED])[/color][/b]  [i][color=#990099]; End Setq[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"OSMODE"[/color][/b] [b][color=#009900]0[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099]; Turn off the OSnaps![/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_.pline"[/color][/b] pt3 pt4 pt5 pt6 pt3 [b][color=#ff00ff]""[/color][/b][b][color=RED])[/color][/b]

 [i][color=#990099]; Remember to use "_." prefix to make it[/color][/i]
 [i][color=#990099]; compatible for all language versions.[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_.rotate"[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entlast[/color][/b][b][color=RED])[/color][/b] [b][color=#ff00ff]""[/color][/b] pt1 pause[b][color=RED])[/color][/b]

 [i][color=#990099]; Use "entlast" to detect last entity[/color][/i]
 [i][color=#990099]; added to database (hence created).[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]setvar[/color][/b] [b][color=#ff00ff]"OSMODE"[/color][/b] oldos[b][color=RED])[/color][/b]  [i][color=#990099]; Turn OSMODE back on[/color][/i]
 
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b]

 [i][color=#990099]; Exit Cleanly[/color][/i]
 
 [b][color=RED])[/color][/b] [i][color=#990099]; End box1[/color][/i]

Link to comment
Share on other sites

Lee,

 

All has to be learned. I read you were only 9 months programming lisp... It surprises me, fast learner! Thank you for your help.

 

My next step will bring up new questions :-) so i will speak to you soon.

Ps.: when's your exam?

Link to comment
Share on other sites

Lee,

 

All has to be learned. I read you were only 9 months programming lisp... It surprises me, fast learner! Thank you for your help.

 

My next step will bring up new questions :-) so i will speak to you soon.

Ps.: when's your exam?

 

Thanks Marco :)

 

My exams start this Friday - I have 7 exams spread over 10 days... :(

Link to comment
Share on other sites

1 thing that I always found interesting in radians:

 

( this from wikipedia )

An angle of 1 radian results in an arc with an equal length to the radius of the circle.

180px-Radian_cropped_color.svg.png

Link to comment
Share on other sites

1 thing that I always found interesting in radians:

 

( this from wikipedia )

 

Excellent point David, which explains nicely why there are 2*pi to a full circle - as the circumference is 2*pi*r. :)

Link to comment
Share on other sites

To be honest, I believe that they should really teach us to think about Radians from a young age.

 

The degree angle measurement is an arbitrary system, and is only really used as 360 has a lot of factors, and so can be used in many situations without the need for decimal calculations. Just like the grad angle measurement, where 100grads is a right angle - an arbitrary notion, introduced for its ease of use*.

 

But, using Radians as a form of measurement makes life so much simpler when it comes to arc-length & segment-area calculations - not to mention that most geometric proofs only hold true for theta in radians.

 

Anyway, thats just my views on it - just going from experience of having to use the radian system entirely when working - and how its so easy just to slip back into thinking in degrees as its so deeply set in our understanding of angles.

 

 

*I might add that these forms of measurement do have their histories, and weren't only introduced for the number of factors in the numbers - but this is just another motivation for using the system.

Link to comment
Share on other sites

:huh: From my point of view: the information above is way too much for me. I just learned how to calculate a few points in a correct way. The thing about radians I cannot avoid for ever so that will come later I guess.

 

A quick question "on topic"... imagine i want to _.pline from pt3 to pt4 etc. When the pline command ends I would like to draw a circle, lets say on pt3 with a diameter dia1.

So first i will prompt for diameter, somewhere in the routine, kinda like this:

 

(setq dia1 (getint "\nDiameter of cicle"))

 

When command pline ends I would like to draw the circle:

 

(command "circle" pt3 "d" dia1)

 

So lets melt it together:

 

(defun c:box1  (/ oldos len leng dist pt1 pt2 pt3 pt4 pt5 pt6)

 (setq oldos (getvar "OSMODE")  ; Collect Old OSMODE setting

 ; Define Functions and Localise Variables

       len  (getdist "\nLength1:  ")
       
       leng (getdist "\nLength2:  ")

       dia1 (getint "\nDiameter of cicle:  ")

       ; I'd be more inclined to use "getdist"
       ; so that the user can pick the distance.
       
       dist (getdist "\nDistance:  ")
       
       pt1  (getpoint "\nInsertion:  ")
       
       pt2  (polar pt1 (* pi 0.5) dist)
       

;;;                     + pt2
;;;                     |
;;;                     |
;;;                     + pt1

       
       pt3  (polar pt2 pi (* len 0.5))
       

;;;            +--------+ pt2
;;;           pt3       |
;;;                     |
;;;                     + pt1
        
       
       pt4  (polar pt3 (* pi 0.5) leng)

        
;;;           pt4
;;;            +
;;;            |
;;;            |
;;;            +--------+ pt2
;;;           pt3       |
;;;                     |
;;;                     + pt1
        
       
       pt5  (polar pt4 0.0 len)
       

;;;           pt4               pt5
;;;            +-----------------+
;;;            |
;;;            |       pt2
;;;            +--------+--------+
;;;           pt3       |       pt6
;;;                     |
;;;                     + pt1
       
       
       pt6  (polar pt3 0.0 len)

       )  ; End Setq

 (setvar "OSMODE" 0)  ; Turn off the OSnaps!
 
 (command "_.pline" pt3 pt4 pt5 pt6 pt3 "")

 ; Remember to use "_." prefix to make it
 ; compatible for all language versions.
 
 (command "_.rotate" (entlast) "" pt1 pause)
 (command "circle" pt3 "d" dia1)

 ; Use "entlast" to detect last entity
 ; added to database (hence created).

 (setvar "OSMODE" oldos)  ; Turn OSMODE back on
 
 (princ)

 ; Exit Cleanly
 
 ) ; End box1

 

And then it won't work, for entlast takes the last entity added to the database (hence created). So the circle is drawn but not rotated with the box.

 

By the way, what does it mean "hence created".?

 

I can go on for ages, I am afraid...: next thing.

When looking at this command, the result is a drawn entity (or must I say a hence created entity). And with "drawn" i mean, it is made out of lines, plines etc.

Is it possible that the result is the same (displayed) but that it is to be a block? For if it were a block it could have attributes. And the attributes could be filled in with the given values.

 

ie. box1: 100x100 dist50 circle 10 and so on, results in the desired box with attributes 100 - 100 - 10 (whatever I want).

 

Or is it ":wacko:" thinking like that?

Link to comment
Share on other sites

Please do read my post before this one, it contains 375 questions :-)

---

"In the meanwhile"

---

I had to modify it so the box is rotated more natural (at least to me it is), the direction is the direction of wich the crosshair is moved. It is nothing difficult for those who get it, to me it was quite sweaty but I managed to do so:

 

(defun c:[color="Red"]box99[/color]  (/ oldos len leng dist pt1 pt2 pt3 pt4 pt5 pt6)

 (setq oldos (getvar "OSMODE")  ; Collect Old OSMODE setting

 ; Define Functions and Localise Variables

       len  (getdist "\nBox length:  ")
       
       leng (getdist "\nBox with:  ")

       ; I'd be more inclined to use "getdist"
       ; so that the user can pick the distance.
       
       dist (getdist "\nDistance between box and insertion point:  ")
       
       pt1  (getpoint "\nInsertion point:  ")
       
       [color="red"]pt2  (polar pt1 0.0 dist)
       

;;;                     +-------+
;;;			pt1	pt2

       
       pt3  (polar pt2 (* pi 0.5) (* len 0.5))
       
;;;
;;;
;;;				pt3
;;;				+
;;;				|
;;;				|
;;;                     +-------+
;;;			pt1	pt2
;;;

        
       
       pt4  (polar pt3 0.0 leng)

        
;;;
;;;
;;;			     pt3    pt4
;;;				+---+
;;;				|
;;;				|
;;;                     +-------+
;;;			pt1	pt2
;;;
        
       
       pt5  (polar pt4 (* pi 1.5) len)
       

;;;
;;;
;;;			     pt3    pt4
;;;				+---+
;;;				|   |
;;;				|   |
;;;                     +-------+   |
;;;			pt1	pt2 |
;;;				    |
;;;				    +
;;;				   pt5
       
      pt6  (polar pt5 pi leng)

;;;
;;;
;;;			     pt3    pt4
;;;				+---+
;;;				|   |
;;;				|   |
;;;                     +-------+   |
;;;			pt1	pt2 |
;;;				    |
;;;				+---+
;;;			      pt6   pt5[/color]


       )  ; End Setq

 (setvar "OSMODE" 0)  ; Turn off the OSnaps!
 [color="red"](setvar "ORTHOMODE" 1)  ; Turn on ORTHO[/color]

 (command "_.pline" pt3 pt4 pt5 pt6 pt3 pt5 "")
 
 
 ; Remember to use "_." prefix to make it
 ; compatible for all language versions.
 
 (command "_.rotate" (entlast) "" pt1 pause)

 ; Use "entlast" to detect last entity
 ; added to database (hence created).

 (setvar "OSMODE" oldos)  ; Turn OSMODE back on

 (princ)

 ; Exit Cleanly
 
 ) ; End box99

 

So this one I like better. Next thing I want to do is that the second time I invoke box99 it must "propose" the length / with / dist as given the first time.

 

I guess it has to do with initget and keyword, read about it but did not play with it. So thats one of my challenges to come. One of many I am afraid.

Link to comment
Share on other sites

:huh: From my point of view: the information above is way too much for me. I just learned how to calculate a few points in a correct way. The thing about radians I cannot avoid for ever so that will come later I guess.

 

Radians isn't too difficult to be honest - its just a different way of thinking about angles. Just think about it in degrees if you like, then divide your degrees by 180 and multiply it by pi. :)

 

So first i will prompt for diameter, somewhere in the routine, kinda like this:

 

(setq dia1 (getint "\nDiameter of cicle"))

 

Would you not want to use "getreal" or are you specifically restricting it to integers?

 

By the way, what does it mean "hence created".?

 

I'm sorry, I should have used simpler language -

 

Hence = Therefore = thus = and so

 

I meant that when an object is created, it is added to the database, and entlast will use the last entity from the database, therefore using the last entity created.

 

 

Is it possible that the result is the same (displayed) but that it is to be a block? For if it were a block it could have attributes. And the attributes could be filled in with the given values.

 

ie. box1: 100x100 dist50 circle 10 and so on, results in the desired box with attributes 100 - 100 - 10 (whatever I want).

 

Or is it ":wacko:" thinking like that?

 

Yes, you could "entmake" your block within the drawing, so that it could have attributes - but this takes a bit more coding.

Link to comment
Share on other sites

This should help you out:

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:box1  [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] *error* vlst ovar ss len leng dist pt1 pt2 pt3 pt4 pt5 pt6[b][color=RED])[/color][/b]

 [i][color=#990099]; Error Handler[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] *error*  [b][color=RED]([/color][/b]msg[b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] ovar
     [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]setvar[/color][/b] vlst ovar[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; If old variables are stored, reset them.[/color][/i]
   [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]member[/color][/b] msg [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"Function cancelled"[/color][/b] [b][color=#ff00ff]"quit / exit abort"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [i][color=#990099]; If the msg isn't one in this list[/color][/i]
     [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] [b][color=#ff00ff]"\n<!> Error: "[/color][/b] msg [b][color=#ff00ff]" <!>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [i][color=#990099]; then print it.[/color][/i]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] vlst [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"CMDECHO"[/color][/b] [b][color=#ff00ff]"OSMODE"[/color][/b] [b][color=#ff00ff]"ORTHOMODE"[/color][/b][b][color=RED])[/color][/b]
       ovar [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]getvar[/color][/b] vlst[b][color=RED])[/color][/b]

       ss [b][color=RED]([/color][/b][b][color=BLUE]ssadd[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099]; Create an Empty Selection Set[/color][/i]

 [i][color=#990099]; Define Functions and Localise Variables[/color][/i]

       len [b][color=RED]([/color][/b][b][color=BLUE]getdist[/color][/b] [b][color=#ff00ff]"\nLength1:  "[/color][/b][b][color=RED])[/color][/b]

       leng [b][color=RED]([/color][/b][b][color=BLUE]getdist[/color][/b] [b][color=#ff00ff]"\nLength2:  "[/color][/b][b][color=RED])[/color][/b]

 [i][color=#990099]; I'd be more inclined to use "getdist"[/color][/i]
 [i][color=#990099]; so that the user can pick the distance.[/color][/i]

       dist [b][color=RED]([/color][/b][b][color=BLUE]getdist[/color][/b] [b][color=#ff00ff]"\nDistance:  "[/color][/b][b][color=RED])[/color][/b]

       dia [b][color=RED]([/color][/b][b][color=BLUE]getreal[/color][/b] [b][color=#ff00ff]"\nDiameter: "[/color][/b][b][color=RED])[/color][/b]

       pt1 [b][color=RED]([/color][/b][b][color=BLUE]getpoint[/color][/b] [b][color=#ff00ff]"\nInsertion:  "[/color][/b][b][color=RED])[/color][/b]

       pt2 [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt1 [b][color=#009900]0[/color][/b] dist[b][color=RED])[/color][/b]
       
[i][color=#990099];;;                    pt1 +-----+[/color][/i]
[i][color=#990099];;;                             pt2[/color][/i]

       pt3 [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt2 [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] [b][color=BLUE]pi[/color][/b] [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] len [b][color=#009999]0.5[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       
[i][color=#990099];;;                             pt3[/color][/i]
[i][color=#990099];;;                              +[/color][/i]
[i][color=#990099];;;                              |[/color][/i]
[i][color=#990099];;;                              |[/color][/i]
[i][color=#990099];;;                    pt1 +-----+[/color][/i]
[i][color=#990099];;;                             pt2[/color][/i]

       pt4 [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt3 [b][color=#009900]0[/color][/b] leng[b][color=RED])[/color][/b]

[i][color=#990099];;;                             pt3   pt4[/color][/i]
[i][color=#990099];;;                              +-----+[/color][/i]
[i][color=#990099];;;                              |[/color][/i]
[i][color=#990099];;;                              |[/color][/i]
[i][color=#990099];;;                    pt1 +-----+[/color][/i]
[i][color=#990099];;;                             pt2[/color][/i]

       pt5 [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt4 [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] [b][color=BLUE]pi[/color][/b] [b][color=#009999]1.5[/color][/b][b][color=RED])[/color][/b] len[b][color=RED])[/color][/b]
       
[i][color=#990099];;;                             pt3   pt4[/color][/i]
[i][color=#990099];;;                              +-----+[/color][/i]
[i][color=#990099];;;                              |     |[/color][/i]
[i][color=#990099];;;                              |     |[/color][/i]
[i][color=#990099];;;                    pt1 +-----+     |[/color][/i]
[i][color=#990099];;;                             pt2    |[/color][/i]
[i][color=#990099];;;                                    |[/color][/i]
[i][color=#990099];;;                                    +[/color][/i]
[i][color=#990099];;;                                   pt5[/color][/i]

       pt6 [b][color=RED]([/color][/b][b][color=BLUE]polar[/color][/b] pt5 [b][color=BLUE]pi[/color][/b] leng[b][color=RED])[/color][/b]

[i][color=#990099];;;                             pt3   pt4[/color][/i]
[i][color=#990099];;;                              +-----+[/color][/i]
[i][color=#990099];;;                              |     |[/color][/i]
[i][color=#990099];;;                              |     |[/color][/i]
[i][color=#990099];;;                    pt1 +-----+     |[/color][/i]
[i][color=#990099];;;                             pt2    |[/color][/i]
[i][color=#990099];;;                                    |[/color][/i]
[i][color=#990099];;;                              +-----+[/color][/i]
[i][color=#990099];;;                             pt6   pt5[/color][/i]

       [b][color=RED])[/color][/b] [i][color=#990099]; End Setq[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]setvar[/color][/b] vlst [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] [b][color=#009900]0[/color][/b] [b][color=#009900]1[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099]; Set the Variables to how we want them[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_.pline"[/color][/b] pt3 pt4 pt5 pt6 [b][color=#ff00ff]"_C"[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099]; Make the Polyline[/color][/i]

 [i][color=#990099]; Remember to use "_." prefix to make it[/color][/i]
 [i][color=#990099]; compatible for all language versions.[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]ssadd[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entlast[/color][/b][b][color=RED])[/color][/b] ss[b][color=RED])[/color][/b]  [i][color=#990099]; Add the polyline to the selection set[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_.circle"[/color][/b] pt3 [b][color=#ff00ff]"_D"[/color][/b] dia[b][color=RED])[/color][/b]  [i][color=#990099]; Create the Circle[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]ssadd[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entlast[/color][/b][b][color=RED])[/color][/b] ss[b][color=RED])[/color][/b]  [i][color=#990099]; Add the Circle to the selection set[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_.rotate"[/color][/b] ss [b][color=#ff00ff]""[/color][/b] pt1 pause[b][color=RED])[/color][/b]

 [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]setvar[/color][/b] vlst ovar[b][color=RED])[/color][/b] [i][color=#990099]; Reset System Variables[/color][/i]

 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b]

 [i][color=#990099]; Exit Cleanly[/color][/i]

 [b][color=RED])[/color][/b] [i][color=#990099]; End box1[/color][/i]

Link to comment
Share on other sites

lee, i just thought you would like to know, when using the command to draw, etc. you can place an osnap override in the routine to eliminate issues with running osnaps. i know you've covered your bases in this routine; i just wanted to make sure you were aware of this. for instance

(command "_.pline" "_non" pt3 "_non" pt4 "_non" pt5 "_non" pt6 "_non" "_C")

while a little verbose, it removes the need to control osnaps.

Link to comment
Share on other sites

@ Lee: I tried to understand. Some I don't, please see below and correct me where i am wrong.

 

 
(defun c:box1  (/ *error* vlst ovar ss len leng dist pt1 pt2 pt3 pt4 pt5 pt6)
[color=red]; all systems go, got the message![/color]

; Error Handler
[color=red]; we would have to spend a chapter on the error handler for I don't get the code.[/color]

(defun *error*  (msg)

[color=red]; defun without the c: is a subfunction, correct?[/color]
[color=red]; How is a subfuntion invoked? Or wil it work autom[/color][color=red]atically whenever the main function is invoked?[/color]

   (if ovar

[color=red]; If the old variables...[/color]

(mapcar 'setvar vlst ovar)); If old variables are stored, reset them.

[color=red]; are stored (mapcar = stored ??) then set the variable vlst to ovar..[/color]
[color=red]; as if ovar & vlst were variables... where is the "setq ovar / setq vlst" ??[/color]

(if (not (member msg '("Function cancelled" "quit / exit abort")))

[color=red]; If the error message isn't one in this list ("member msg") then:[/color]

     (princ (strcat "\n<!> Error: " msg " <!>"))) ; then print it.
   (princ))

[color=red]; Yes prin[b]C[/b] it...[/color]

(setq vlst '("CMDECHO" "OSMODE" "ORTHOMODE")
ovar (mapcar 'getvar vlst)

[color=red]; oops... here they are the vlst and ovar setq's...[/color]
[color=red]; so this is the point where i think "first setq's then refer to them..[/color]
[color=red]; this seems upside down...[/color]
[color=red]; what is the  '  in there?[/color]

       ss (ssadd)  ; Create an Empty Selection Set

[color=red]; so ss is the variable and ssadd is a function to create a SelectionSet?[/color]
[color=red]; an empty one, in wich certain entities can be added[/color]

; Define Functions and Localise Variables
       len (getdist "\nLength1:  ")
       leng (getdist "\nLength2:  ")
 ; I'd be more inclined to use "getdist"
 ; so that the user can pick the distance.

[color=red]; okay, in some cases that might come in handy and since[/color]
[color=red]; the keybord methode works too its maybe better to use getdist.[/color]

       dist (getdist "\nDistance:  ")
       dia (getreal "\nDiameter: ")

[color=red]; the getreal function is in fact better for it can contain decimal values[/color]
[color=red]; i used integer for i was thinking in round numbers (don't know english for that")[/color]
[color=red]; you know what i mean[/color]

       pt1 (getpoint "\nInsertion:  ")
       pt2 (polar pt1 0 dist)

;;;                    pt1 +-----+
;;;                             pt2
       pt3 (polar pt2 (/ pi 2) (* len 0.5))

[color=red]; Lee you altered the line above, I get it for (* pi 0.5) is the [/color]
[color=red]; same as when typing (/ pi 2)[/color]
[color=red]; Just wanted you to know I noticed :-)[/color]

;;;                             pt3
;;;                              +
;;;                              |
;;;                              |
;;;                    pt1 +-----+
;;;                             pt2
       pt4 (polar pt3 0 leng)
;;;                             pt3   pt4
;;;                              +-----+
;;;                              |
;;;                              |
;;;                    pt1 +-----+
;;;                             pt2
       pt5 (polar pt4 (* pi 1.5) len)

;;;                             pt3   pt4
;;;                              +-----+
;;;                              |     |
;;;                              |     |
;;;                    pt1 +-----+     |
;;;                             pt2    |
;;;                                    |
;;;                                    +
;;;                                   pt5
       pt6 (polar pt5 pi leng)
;;;                             pt3   pt4
;;;                              +-----+
;;;                              |     |
;;;                              |     |
;;;                    pt1 +-----+     |
;;;                             pt2    |
;;;                                    |
;;;                              +-----+
;;;                             pt6   pt5
       ) ; End Setq
 (mapcar 'setvar vlst '(0 0 1))  ; Set the Variables to how we want them

[color=red]; Problem: The mapcar thingy is not understood...[/color]
[color=red]; I'd rather google a bit[/color]

 (command "_.pline" pt3 pt4 pt5 pt6 "_C")  ; Make the Polyline
 ; Remember to use "_." prefix to make it
 ; compatible for all language versions.

[color=red]; i put a sticky note on my forehead + mirror besides monitor.[/color]

 (ssadd (entlast) ss)  ; Add the polyline to the selection set

[color=red]; Because (setq ss (ssadd)) has no further parameters it stayed empty at first[/color]
[color=red]; Now (ssad (entlast) ss) means "put last created entity into the set ss".[/color]

 (command "_.circle" pt3 "_D" dia)  ; Create the Circle
 (ssadd (entlast) ss)  ; Add the Circle to the selection set
 (command "_.rotate" ss "" pt1 pause)
 (mapcar 'setvar vlst ovar) ; Reset System Variables

[color=red]; Did I tell you i didn't get that one?[/color]

 (princ)
 ; Exit Cleanly
 ) ; End box1 

 

What needs to be done In my case is that i first try to understand the error handling, that looks to me as muchos importante.

 

Then the mapcar thingy, for I would do it in a rather simple methode, like setvar oldosmode etc.

 

I like the way of doing this, I mean figuring out what is written. Only copying end pasting doesn't provide me with knowledge only questions.

 

Tnx for your reply.

Link to comment
Share on other sites

lee, i just thought you would like to know, when using the command to draw, etc. you can place an osnap override in the routine to eliminate issues with running osnaps. i know you've covered your bases in this routine; i just wanted to make sure you were aware of this. for instance

(command "_.pline" "_non" pt3 "_non" pt4 "_non" pt5 "_non" pt6 "_non" "_C")

while a little verbose, it removes the need to control osnaps.

 

Thanks for pointing this out - yes, I had known about it, but I prefer not to use this method, as it seems like a "work-around", and, when drawing multiple objects using the command call method "(command..." you will always have to remember to add the "_non" every time - leaving room for errors...

Link to comment
Share on other sites

As for your other reply - we could be here all day... :P

 

Not many people understand "mapcar" - and it is such a useful function. I'm not sure I would be the best person to explain it to you, but I shall try my best.

 

Mapcar will apply the provided function to every member in the provided list, and return a list of the results of doing this.

 

Hence:

 

(mapcar 'setvar (list "CMDECHO" "OSMODE") (list 0 0))

 

is the same as

 

(setvar "CMDECHO" 0)
(setvar "OSMODE" 0)

 

Have a read in the Visual LISP Editor (VLIDE) Help files on mapcar to get more of an understanding.

 

As for the apostrophe, it just means that the statements following it are not evaluated, so:

 

(setq lst '(1 2 3))

 

is the same as:

 

(setq lst (list 1 2 3))

 

As for the Error Handler and Sub-Functions.... this is another thing altogether... There is a lot of information on AfraLISP about Error Handling in LISP, and I have also written an FAQ on it (which is not yet available, but should be shortly!).

 

Hope this helps!

 

Lee

Link to comment
Share on other sites

Shure it helps, but for now, let's call it a day.

I have too much to "worry" about... :-)

 

Afralisp I know and I will visit it today. I'll be back here soon, ... how could you ever think I would not be.

 

Tnx for the info so far, I am gonna struggle a bit now.

Link to comment
Share on other sites

Join the conversation

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

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

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

×   Your previous content has been restored.   Clear editor

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


×
×
  • Create New...