New for AUTOLISP
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
New for AUTOLISP

 
Post new topic   Reply to topic    CADForums.net Forum Index -> AutoCAD
Author Message
Dan
Guest





Posted: Thu Aug 04, 2005 12:10 am    Post subject: New for AUTOLISP Reply with quote

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.

Back to top
Adesu



Joined: 20 Jul 2005
Posts: 31

Posted: Thu Aug 04, 2005 5:59 am    Post subject: Re: New for AUTOLISP Reply with quote

Dan wrote:
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.


Hi Dan,here sample if this script useful for you

Code:

; ccs is stand for create coil spring
;       Design by Ade Suharna <mteybid@yuasabattery.co.id.>
;       24 March 2005
;       Program no.219/03/2005
;       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 z point el p1
        rads con el1 el2 el3 iso)
  (setq lay (getvar "clayer"))
  (if
    (/= lay "SPRING")
    (command "_layer" "m" "SPRING" "c" 1 "" "")
    )
  (setq seg 36)                               
  (setq ang (/ (* 2 pi) seg))               ; (* 2 pi) = 360
  (setq cnt 0)
  (setq rad (getdist "\nENTER NEW RADIUS<10>: "))        ; 3
  (if (= rad nil)(setq rad 10))
  (setq pit (getreal "\nENTER NEW PITCH<3>: "))          ; 3
  (if (= pit nil)(setq pit 3.0))
  (setq len (getdist "\nENTER LENGTH OF SPRING<25>: "))  ; 3
  (if (= len nil)(setq len 25))
  (setq leng (fix (/ len pit)))
  (command "_vpoint" "r" 315 25 "")
  (command "3dpoly")
  (repeat leng
    (repeat (1+ seg)
      (setq x (* rad (sin (* cnt ang))))
      (setq y (* rad (cos (* cnt 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 OF WIRE<1.25>: "))          ; 3).
  (if (= rads nil)(setq rads 1.25))
  (cond ((= rads pit)(setq rads (* pit 0.45)))
   ((> rads pit)(setq rads (* pit 0.45)))
   ((> rads (/ pit 2.0))(setq rads (* pit 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 60 (list x y z))      ; 2).
  (command "_shademode" "g")                                 ; 3).
  (princ) 
  )
Back to top
View user's profile Send private message
Paul Turvill
Guest





Posted: Thu Aug 04, 2005 6:01 am    Post subject: Re: New for AUTOLISP Reply with quote

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.
___

"Dan" <dschitale@yahoo.ca> wrote in message
news:1123102691.255755.22860@g49g2000cwa.googlegroups.com...
Quote:
DOes AutoLISP
recongnize trigonomtric fnctions?


Back to top
Dan
Guest





Posted: Fri Aug 05, 2005 8:10 pm    Post subject: Re: New for AUTOLISP Reply with quote

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))


))
)
Back to top
Brian Salt
Guest





Posted: Fri Aug 05, 2005 10:34 pm    Post subject: Re: New for AUTOLISP Reply with quote

Seems to be a parenthesis problem somewhere. I think it is in this line:

Quote:
(setq lay (getvar "clayer"))

Should it be (setq lay (getvar "clayer"))) perhaps?


In article <0uadnWEh_9X9UGzfRVn_vQ@giganews.com>,
mteybid@yuasabattery.co-dot-id.no-spam.invalid (Adesu) wrote:

> (setq lay (getvar "clayer"))
Back to top
Paul Turvill
Guest





Posted: Sat Aug 06, 2005 5:36 am    Post subject: Re: New for AUTOLISP Reply with quote

It's correct with the two closing parentheses; why would you think
otherwise?
___

"Brian Salt" <briansalt@NScix.co.uk> wrote in message
news:memo.20050805233456.33123A@briansalt.compulink.co.uk...
Quote:

Seems to be a parenthesis problem somewhere. I think it is in this line:

(setq lay (getvar "clayer"))

Should it be (setq lay (getvar "clayer"))) perhaps?
Back to top
Paul Turvill
Guest





Posted: Sat Aug 06, 2005 6:25 am    Post subject: Re: New for AUTOLISP Reply with quote

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)
)


"Dan" <dschitale@yahoo.ca> wrote in message
news:1123271383.742116.170530@g47g2000cwa.googlegroups.com...
Quote:

(command "rotate" "W" pt2 pt3 cpg (* rgt theta))
Back to top
Brian Salt
Guest





Posted: Sat Aug 06, 2005 11:49 pm    Post subject: Re: New for AUTOLISP Reply with quote

Because it produces a parenthesis error message when I run it - but not
with the additional one...

....that's all.


In article <LMWdnTsLD6dumGnfRVn-pQ@whidbeytel.com>, nospam@turvill.com
(Paul Turvill) wrote:

Quote:
It's correct with the two closing parentheses; why would you think
otherwise?
Back to top
Paul Turvill
Guest





Posted: Sun Aug 07, 2005 5:33 am    Post subject: Re: New for AUTOLISP Reply with quote

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 ")".
___

"Brian Salt" <briansalt@NScix.co.uk> wrote in message
news:memo.20050807004946.37991A@briansalt.compulink.co.uk...
Quote:

Because it produces a parenthesis error message when I run it - but not
with the additional one...
Back to top
Brian Salt
Guest





Posted: Mon Aug 08, 2005 7:35 pm    Post subject: Re: New for AUTOLISP Reply with quote

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.

In article <CPydndRu2YVay2jfRVn-sQ@whidbeytel.com>, nospam@turvill.com
(Paul Turvill) wrote:

Quote:
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 ")".
Back to top
Paul Turvill
Guest





Posted: Tue Aug 09, 2005 12:10 am    Post subject: Re: New for AUTOLISP Reply with quote

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.
___

"Brian Salt" <briansalt@NScix.co.uk> wrote in message
news:memo.20050808203536.36925A@briansalt.compulink.co.uk...
Quote:

Strange thing; putting the extra parenthesis after "clayer" seems to cause
the code to run immediately it's loaded, without using the ccs command.
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> AutoCAD All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB