New for AUTOLISP

Discussion in 'AutoCAD' started by Dan, Aug 3, 2005.

  1. Dan

    Dan Guest

    I am writing a LISP routine for hob generation. I want to write a polar
    coordinate involving tangent function of an angle. DOes AutoLISP
    recongnize trigonomtric fnctions? If yes how to write them and how to
    write polar fnctions? ANy examples will be appreciated.
     
    Dan, Aug 3, 2005
    #1
  2. Dan

    Paul Turvill Guest

    AutoLISP has built-in SIN, COS, and ATAN functions, which can be combined in
    the usual manner (i.e., TANx = SINx / COSx) to derive other functions as
    needed.
    ___
     
    Paul Turvill, Aug 4, 2005
    #2
  3. Dan

    Dan Guest

    I have tried the following program but somehow the repeat loop is not
    getting executed. Can anybody read this program and see if there is any
    error in this?

    This program is for generating the gear involute profile using a
    straight flank hob. I draw the PCD, Hob profile and feed the roll angle
    and then I calculated the polar cooardinates where the hob should be
    inserted and rotated.


    (defun c:HOB()
    (command "SNAP" "OFF")
    (setq cpg (list 0 0))
    (setq ntg (getreal "\nEnter number of teeth on gear: "))
    (setq dpg 1.000)
    (setq pdg (getreal "\nEnter generating pitch dia of gear: "))
    (setq rolrad (/ pdg 2))
    (setq rolangdeg (getreal "\nEnter Roll Angle of the tooth from OD to
    BD: "))
    (setq numtgt (getint "\nEnter number of tangents: "))

    (setq rolangrad (/ (* rolangdeg pi) 180.0))

    (setq theta (/ rolangrad numtgt))
    (setq pt2 (list -3 4))
    (setq pt3 (list 3 7))


    (setq rgt 1.0)

    (while (<= rgt numtgt)

    (progn
    (setq pt1 (polar cpg (atan (- 1.570796327 (* rgt theta))) (/ rolrad
    (cos(atan(* rgt theta))))))
    (command "INSERT" "HOB" pt1 1 1 0)
    (command "rotate" "W" pt2 pt3 cpg (* rgt theta))
    (setq rgt (+ 1 rgt))


    ))
    )
     
    Dan, Aug 5, 2005
    #3
  4. Dan

    Paul Turvill Guest

    I believe your problem is in trying to select the last insertion of HOB with
    a window. Try using (entlast) and don't forget to add an extra set of "" in
    your (command ...) statements to close out object selection. Here's a
    modified version of your code; I can't tell for sure if it's working as you
    expect, since I don't have a copy of your HOB block. Also, you don't need
    to use (progn ... ) with (while ...).

    (defun c:HOB(/ cpg ntg dpg pdg rolrad rolangdeg numtgt theta pt2 pt3 rgt)
    (setvar "osmode" 0)
    (setq cpg (list 0 0))
    (setq ntg (getint "\nEnter number of teeth on gear: "))
    (setq dpg 1.0)
    (setq pdg (getdist "\nEnter generating pitch dia of gear: "))
    (setq rolrad (/ pdg 2))
    (setq rolangdeg (getreal "\nEnter Roll Angle of the tooth from OD to BD:
    "))
    (setq numtgt (getint "\nEnter number of tangents: "))
    (setq rolangrad (/ (* rolangdeg pi) 180.0))
    (setq theta (/ rolangrad numtgt))
    (setq rgt 1)
    (while (<= rgt numtgt)
    (setq pt1 (polar cpg
    (atan (- 1.570796327 (* rgt theta)))
    (/ rolrad (cos(atan(* rgt theta)))))
    );;setq
    (command "_.INSERT" "HOB" pt1 1 1 0)
    (command "_.rotate" (entlast) "" cpg (* rgt theta))
    (setq rgt (1+ rgt))
    );;while
    (princ)
    )
     
    Paul Turvill, Aug 6, 2005
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.