×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

LISP ROUTINE
3

LISP ROUTINE

LISP ROUTINE

(OP)
I am a beginner in LISP. I wrote a short lisp routine which does not produce results consistently. The routine is supposed to draw a line in any quadrant and place text at the mid point of the line. I tried to simplify the routine as a biginner. Could you please test my routine (listed below) and tell me whats wrong with it? I didn't use any AutoCAD System variables, could you please refer me to some documentation (other than AutoCAD Guides) that may help me to understand which system variables to use & when to use them in LISP.

;| Eddies' Routine. This program draws a line between 2 points, then insert text
on top of the line.
ROUTINE
|;

(Defun c:st ()
  (setq pt1 (getpoint "First Point:"))
  (setq pt2 (getpoint "Second Point:"))
  (setq ang1 (angle pt1 pt2))
  (setq pt3 (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2)))
  (if (<= ang1 1.570796327) (setq ang2 (+ ang1 1.570796327))
    (if (<= ang1 3.14159) (setq ang2 (- ang1 1.570796327))
      (if (<= ang1 4.71238898) (setq ang2 (- ang1 1.570796327))
    (if (<= ang1 6.283185307) (setq ang2 (+ ang1 1.570796327)) (setq ang2 0)))))
  (if (<= ang1 1.570796327) (setq ang3 ang1)
    (if (<= ang1 3.14159) (setq ang3 (+ 3.14159 ang1))
      (if (<= ang1 4.71238898) (setq ang3 (- ang1 3.14159))
    (if (<= ang1 6.283185307) (setq ang3 ang1) (setq ang2 ang1)))))     
  (setq pt4 (polar pt3 ang2 200))
  (setq ang2 (* 57.29577951 ang2))
  (setq ang3 (* 57.29577951 ang3))
  (command ".line" pt1 pt2 "")
  (command ".text" pt4 250 Ang3 "Eddie"))

RE: LISP ROUTINE

3
I see one way your routine could have errors-in the "text" command. AutoCAD prompts for text height if your style height is set to 0, but does not prompt if it is a set height.

You should not "hard enter" pi or its ratios; instead use the lisp constant "pi". And to simplify your routine, instead of 2 sets of nested "if" statements for setting ang2 and ang3, you can do it in one set, and the use of "cond" is easier to follow and faster. Cond evalutes each expression until a "true" is encountered and skips the rest.

Applicable system variables to this routine-hmmm, maybe "textsize" for last used text height?
A suggestion on your text placement - may want to center justify your text.

Following routine does the same as yours and incorporates the items I mentioned.

Enjoy your lisping!
Carl

---------------------------------------------------

(Defun c:stt ()
  (setq hpi (/ pi 2) 15pi (* 1.5 pi) 2pi (* 2 pi))
  (setq pt1 (getpoint "\nFirst Point:"))
  (setq pt2 (getpoint pt1 "\nSecond Point:"))
  (setq ang1 (angle pt1 pt2))
  (setq pt3 (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2)))
  (cond
     ((<= ang1 hpi) (setq ang2 (+ ang1 hpi) ang3 ang1))
     ((<= ang1 pi) (setq ang2 (- ang1 hpi) ang3 (- ang1 pi)))
     ((<= ang1 15pi) (setq ang2 (- ang1 hpi) ang3 (- ang1 pi)))
     ((<= ang1 2pi) (setq ang2 (+ ang1 hpi) ang3 ang1))
  );cond
  (setq pt4 (polar pt3 ang2 200));;txt start point
  (setq ang2 (/ (* 180 ang2) pi))
  (setq ang3 (/ (* 180 ang3) pi))
  (command ".line" pt1 pt2 "")
  (command ".text" pt4 250 Ang3 "Eddie")
  (princ);clean exit
)

RE: LISP ROUTINE

(OP)
I tried your routine several times and observed the following: (DO YOU KNOW WHATS CAUSING THAT)

The value for pt3 is inconsistent ("NITTY GRIT" though very close to the answer) as shown by sample of log watch results below;

LOG Watch
...............
ANG1 = 1.5708
ANG2 = 180.0
ANG3 = 90.0
PT1 = (0.0 0.0 0.0)
PT2 = (0.0 6000.0 0.0)
PT3 = (1.83691e-013 3000.0 0.0) (I EXPECT X = 0.0)
PT4 = (-200.0 3000.0 0.0)
...............
...............
LOG Watch
...............
ANG1 = 0.0
ANG2 = 90.0
ANG3 = 0.0
PT1 = (0.0 0.0 0.0)
PT2 = (7000.0 0.0 0.0)
PT3 = (3500.0 0.0 0.0)
PT4 = (3500.0 200.0 0.0)
...............
...............
LOG Watch
...............
ANG1 = 3.92699
ANG2 = 135.0
ANG3 = 45.0
PT1 = (0.0 0.0 0.0)
PT2 = (-4000.0 -4000.0 0.0)
PT3 = (-2000.0 -2000.0 0.0)
PT4 = (-2141.42 -1858.58 0.0)
...............
...............
LOG Watch
...............
ANG1 = 2.35619
ANG2 = 45.0
ANG3 = -45.0
PT1 = (0.0 0.0 0.0)
PT2 = (-4000.0 4000.0 0.0)
PT3 = (-2000.0 2000.0 0.0)
PT4 = (-1858.58 2141.42 0.0)
...............
...............
LOG Watch
...............
ANG1 = 5.49779
ANG2 = 405.0
ANG3 = 315.0
PT1 = (0.0 0.0 0.0)
PT2 = (4000.0 -4000.0 0.0)
PT3 = (2000.0 -2000.0 0.0)
PT4 = (2141.42 -1858.58 0.0)
...............
...............
LOG Watch
...............
ANG1 = 4.71239
ANG2 = 180.0
ANG3 = 90.0
PT1 = (0.0 0.0 0.0)
PT2 = (0.0 -5000.0 0.0)
PT3 = (-4.59227e-013 -2500.0 0.0)(I EXPECT X = 0.0)
PT4 = (-200.0 -2500.0 0.0)
...............
...............
LOG Watch
...............
ANG1 = 3.14159
ANG2 = 90.0
ANG3 = 0.0
PT1 = (0.0 0.0 0.0)
PT2 = (-5000.0 0.0 0.0)
PT3 = (-2500.0 3.06152e-013 0.0)(I EXPECT y = 0)
PT4 = (-2500.0 200.0 0.0)

RE: LISP ROUTINE

Looks like round-off errors.  Pretty small - 10 x 10 to the -13 is pretty small!!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources