New for AUTOLISP

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.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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. ___

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

I am writing a LISP routine for hob generation. I want to write pola

t
Hi Dan,here sample if this script useful for yo
; ccs is stand for create coil sprin ; Design by Ade Suharna < snipped-for-privacy@yuasabattery.co.id. ; 24 March 200 ; Program no.219/03/200 ; Edit by Ade Suharna 13/05/2005 1) ; Kevin Nehls 16/05/2005 2) ; Ade Suharna 11/07/2005 3) (defun c:ccs (/ lay seg ang cnt rad pit len leng x y point el p      rads con el1 el2 el3 iso (setq lay (getvar "clayer") (i (/= lay "SPRING" (command "_layer" "m" "SPRING "c" 1 "" "" (setq seg 36) (setq ang (/ (* 2 pi) seg)) (* 2 pi) = 36 (setq cnt 0 (setq rad (getdist "\nENTER NEW RADIUS<10> ")) ; (if (= rad nil)(setq rad 10) (setq pit (getreal "\nENTER NEW PITCH<3> ")) ; (if (= pit nil)(setq pit 3.0) (setq len (getdist "\nENTER LENGTH O SPRING<25>: ")) ; (if (= len nil)(setq len 25) (setq leng (fix (/ len pit)) (command "_vpoint" "r" 315 2 "" (command "3dpoly" (repeat len (repeat (1+ seg (setq x (* rad (sin (* cn ang))) (setq y (* rad (cos (* cn ang))) (setq z (* cnt (/ pit seg)) (setq point (list x y z) (command point (setq cnt (1+ cnt) (command "" (setq el (entlast)) ; 1) (setq p1 (polar (list 0 0 0)(* pi 0.5 rad)) ; 1) (command "_zoom" "d" "" (setq rads (getdist "\nENTER RADIUS O WIRE<1.25>: ")) ; 3) (if (= rads nil)(setq rads 1.25) (cond ((= rads pit)(setq rads (* pi 0.45))     ((> rads pit)(setq rads (* pi 0.45))     ((> rads (/ pit 2.0))(setq rads (* pi 0.45))     ) ; 3) (command "_circle" p1 rads) ; 1) (setq el1 (ssadd) (setq el1 (ssadd (entlast) el1) (if (not (member "geom3d.arx (arx))) ; 1) (arxload "geom3d")) ; 1) (rotate3d el1 "y" p1 "r" 0 90) ; 1). (setq el2 (entlast) (command "_extrude" el2 "" "p el) ; 1) (setq el3 (entlast) (command "_zoom" "e" "" (command "_erase" el "") ; 1) (setq iso (getvar "isolines") (setvar "isolines" (* 3 iso) (command "_regen" ;(if (not (member "acrender.arx (arx))) ; 1) ; (arxload "acrender") ;(c:render "Photo Real" "Viewport" 1 6 (list x y z)) ; 2) (command "_shademode" "g") ; 3) (princ)
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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)) )) )
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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) )

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Seems to be a parenthesis problem somewhere. I think it is in this line:

Should it be (setq lay (getvar "clayer"))) perhaps?
snipped-for-privacy@yuasabattery.co-dot-id.no-spam.invalid (Adesu) wrote:

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
It's correct with the two closing parentheses; why would you think otherwise? ___

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Because it produces a parenthesis error message when I run it - but not with the additional one...
...that's all.
(Paul Turvill) wrote:

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
There may be a missing ")" somewhere in the code, but the error isn't in the line you cited. Parentheses are always balanced by function; every opening "(" requires exactly one closing ")" -- no more, no fewer. The line you cited has a total of two "(" balanced by two ")". ___

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Yes indeed, so perhaps it's in the previous line where the parameters are defined. Seems to be two "(" but only one ")".
I'll give that a go.
Strange thing; putting the extra parenthesis after "clayer" seems to cause the code to run immediately it's loaded, without using the ccs command.
(Paul Turvill) wrote:

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
That's because that's the wrong place for the otherwise missing ")" ... The interpreter thinks the routine's done, but it isn't. Believe me, misplaced and/or improperly balanced parentheses can cause some very strange effects, and the errors aren't always immediately evident. LISP is a very structure-oriented language, and is very unforgiving in this respect. ___

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.