Author Topic: Help with little program  (Read 1949 times)

0 Members and 1 Guest are viewing this topic.

mbdoyle

  • Guest
Help with little program
« on: August 02, 2010, 01:17:38 PM »
Hello everybody,

 I am trying to write my first lisp program and I was hoping to get a little assistance. This code I mostly pieced together from an Autolisp book; Autolisp in Plain English.Anyways, I modified it slightly, the hope being that you pick two points and give an offset. The program SHOULD hopefully draw two parallel lines @ the given offset from the line that would result from the two points given. When I load and run the following code I get the error: Too Few Arguments. I'm not sure where another argument should be supplied. Any help I could get would be greatly appreciated.

Thanks,
Matt

Code: [Select]
(defun dtr (b)
  (* pi (/ b 180.0))
  )
;


(defun C:mitre (/pnt1 pnt2 pnt3 pnt4 pnt5 pnt6 a d1)
  (graphscr)
  (setq pnt1 (getpoint "\nSelect First Point: "))
  (setq pnt2 (getpoint "\nSelect Second Point: "))
  (setq d1 (getdist "\nEnter Offset: "))
  (setq a (angle pnt1 pnt2))
  (setq pnt3 (polar pnt1 (- a (dtr 90)) d1))
  (setq pnt4 (polar pnt2 (- a (dtr 90)) d1))
  (setq pnt5 (polar pnt1 (+ a (dtr 90)) d1))
  (setq pnt6 (polar pnt2 (+ a (dtr 90)) d1))
  (command "line" pnt3 pnt4 "")
  (command "line" pnt5 pnt6 "")
 
 )
;
<edit: code tags added>
« Last Edit: August 04, 2010, 07:31:42 AM by CAB »

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Help with little program
« Reply #1 on: August 02, 2010, 01:30:47 PM »
You have an error because your first line should be:

Code: [Select]
(/pnt1 pnt2 pnt3 pnt4 pnt5 pnt6 a d1)
Code: [Select]
(/ pnt1 pnt2 pnt3 pnt4 pnt5 pnt6 a d1)
This may point you in the right direction, please ask if you have questions  ;-)

Code: [Select]
(defun c:mitre ( / p1 p2 d a pi/2 )

  (graphscr)

  ;; If all of the following conditions are true

  (if (and (setq p1 (getpoint "\nSelect First Point: "))
           (setq p2 (getpoint "\nSelect Second Point: " p1)) ;; rubberband
           (setq d  (getdist "\nEnter Offset: " p2)))
    (progn
      ;; Wrap the following statements so that they may be treated as a
      ;; single 'progn' statement constituting the 'then' argument for
      ;; the IF function.

      (setq a (angle p1 p2) pi/2 (/ pi 2.))

      (command "_.line" "_non" ;; Disregard OSnap

        (polar p1 (- a pi/2) d) "_non"

        (polar p2 (- a pi/2) d) ""
      )

      (command "_.line" "_non"

        (polar p1 (+ a pi/2) d) "_non"

        (polar p2 (+ a pi/2) d) ""

      )

    ) ; End Progn
   
  ) ; End IF

  (princ) ;; Shhh..

)

« Last Edit: August 03, 2010, 01:24:15 PM by Lee Mac »

jmcshane

  • Newt
  • Posts: 83
Re: Help with little program
« Reply #2 on: August 03, 2010, 12:23:06 PM »
Quote
;; Shhh..
:-D
John.

Civil 3D 2021. Windows 10

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Help with little program
« Reply #3 on: August 03, 2010, 01:23:36 PM »
Quote
;; Shhh..
:-D

I'll admit: borrowed from MP  8-)

mbdoyle

  • Guest
Re: Help with little program
« Reply #4 on: August 04, 2010, 02:04:12 PM »

 Lee,

I didn't see the space after the / in the defun  for two days. I was like "What is he showing here, its exactly what I wrote!?!" I was trying everything else, until finally I went back to the first line of your reply and there it was. I felt like such an idiot. Rookie mistake I guess, thank you very much for your help.

Matt

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Help with little program
« Reply #5 on: August 04, 2010, 02:14:39 PM »
You're welcome Matt  :-)