Need help with my code

Discussion in 'AutoCAD' started by kzalec, Oct 27, 2004.

  1. kzalec

    kzalec Guest

    Can someone help me get this simple AutoLISP routine working? I think there's something wrong with (only) the last line of code. I'm trying to array the bottom elliptical arc up the rod to create the appearance of threads on the rod. The routine works up to the very last part of the -ARRAY command (bottom line). For some reason, AutoCAD can't compute the array "row spacing" based on my code. Perhaps someone can tell me what I've done wrong. Following is my code:

    ;;;Creates isometric drawing of a threaded rod.
    ;;;Size and thread spacing specified by user.
    (defun dtr (a)
    (* (/ pi 180) a)
    )

    (defun c:ROD (/ p0 r L b w c ws p1 p2 p3 p4 p5)
    (setq p0 (getpoint "n\Enter first point:"))
    (setq r (getdist "n\Enter radius of rod:"))
    (setq L (getint "n\Enter length of rod:"))
    (setq b (getint "n\Enter number of threads per inch:"))
    (setq w (* L b));# of rows for array
    (setq c 1);# of columns for array
    (setq ws (/ L w));row spacing
    (setq p1 (polar p0 (dtr 0) (* r 1.22474488)))
    (setq p2 (polar p1 (dtr 90) L))
    (setq p3 (polar p0 (dtr 180) (* r 1.22474488)))
    (setq p4 (polar p3 (dtr 90) L))
    (setq p5 (polar p0 (dtr 90) L))
    (command "line" p1 p2 "");creates line from p1 to p2
    (command "line" p3 p4 "");creates line from p3 to p4
    ;creates isocircle on top:
    (command "ellipse" (polar p3 (dtr 90) L) p2 "r" 60)
    ;creates bottom isocircle half:
    (command "ellipse" "a" p3 p1 "r" 60 p3 180)
    (command "-array" "l" "" "r" w c ws ""); arrays "threads" up
    )
     
    kzalec, Oct 27, 2004
    #1
  2. kzalec

    CAB2k Guest

    Code:
    (defun c:rod (/ p0 r l b w c ws p1 p2 p3 p4 p5)
    (setq p0 (getpoint "\nPick lower left corner:"))
    (setq r (getdist "\n Enter radius of rod:"))
    (setq l (getdist "\n  Enter length of rod:")); cab use dist so it is a real num
    (setq b (getint "\n   Enter number of threads per inch:"))
    (setq w (fix(* l b))) ;# of rows for array ; cab -
    (setq c 1) ;# of columns for array
    (setq ws (/ l w)) ;row spacing
    (setq p1 (polar p0 (dtr 0) (* r 1.22474488)))
    (setq p2 (polar p1 (dtr 90) l))
    (setq p3 (polar p0 (dtr 180) (* r 1.22474488)))
    (setq p4 (polar p3 (dtr 90) l))
    (setq p5 (polar p0 (dtr 90) l))
    (command "line" p1 p2 "") ;creates line from p1 to p2
    (command "line" p3 p4 "") ;creates line from p3 to p4
    ;creates isocircle on top:
    (command "ellipse" (polar p3 (dtr 90) l) p2 "r" 60)
    ;creates bottom isocircle half:
    (command "ellipse" "a" p3 p1 "r" 60 p3 180)
    (command "array" "L" "" "r" w "" ws) ; arrays "threads" up
    (princ)
    )
     
    CAB2k, Oct 28, 2004
    #2
  3. kzalec

    kzalec Guest

    The reply from "CAB2k" did the trick. Thanks so much whoever you are! I'll try to figure out the logic tomorrow... Signing off for today. I sure appreciate the help.
     
    kzalec, Oct 28, 2004
    #3
  4. kzalec

    Douglas Barr Guest

    I'll try to figure out the logic tomorrow... Signing off for today. I sure
    appreciate the help.


    I fixed it a bit differently... When you wrote 'getdist', were you intending
    to 'rubber-band' the distance and pick a second point for your radius? If
    so, you needed to supply p0 after the 'getdist'.

    I used all reals, which when divided produce a real for ws rather than the
    integer 0 as your code produced. Then they're converted to integers within
    the array command.
    -doug


    (defun c:ROD (/ p0 r L b w c ws p1 p2 p3 p4 p5)
    (setq p0 (getpoint "\n Enter first point:"))
    (setq r (getdist p0 "\n Enter radius of rod:"))
    (setq L (getreal "\n Enter length of rod:"))
    (setq b (getreal "\n Enter number of threads per inch:"))
    (setq w (* L b));# of rows for array
    (setq c 1);# of columns for array
    (setq ws (/ L w));row spacing, should be 1 divided by threads per inch
    (setq p1 (polar p0 (dtr 0) (* r 1.22474488)))
    (setq p2 (polar p1 (dtr 90) L))
    (setq p3 (polar p0 (dtr 180) (* r 1.22474488)))
    (setq p4 (polar p3 (dtr 90) L))
    (setq p5 (polar p0 (dtr 90) L))
    (command "line" p1 p2 "");creates line from p1 to p2
    (command "line" p3 p4 "");creates line from p3 to p4
    ;creates isocircle on top:
    (command "ellipse" (polar p3 (dtr 90) L) p2 "r" 60)
    ;creates bottom isocircle:
    (command "ellipse" "a" p3 p1 "r" 60 p3 180)
    (command "-array" "L" "" "r" (fix w) c ws)
    (princ)
    )
     
    Douglas Barr, Oct 28, 2004
    #4
  5. My guess is, the problem is that

    (setq ws (/ L w))

    is dividing an integer by an integer (if L was an integer length), so it
    gives an integer result (probably zero). So I can't figure out why CAB2K's
    solution works, because (fix) is also supposed to return an integer. I
    suspect you need to ensure that among L, b and w, at least one is a real
    number, using (getreal) instead of (getint). Doing that for L would make
    the most sense, since L could easily be a non-integer length.

    Also, if you're setting c to 1 all the time, you could just feed in a "1" in
    the array command [or a "" as in CAB2K's, which could also have omitted the
    (setq c... line altogether], and save yourself a variable.
     
    Kent Cooper, AIA, Oct 28, 2004
    #5
  6. kzalec

    kzalec Guest

    ....is dividing an integer by an integer (if L was an integer length), so it gives an integer result (probably zero). <

    That's exactly what WAS happening. I was aware that this was the problem, but didn't know the function that would fix it. For example, during testing, I was using .25 as the radius, 3 inches as the length of the rod, and 10 "threads" per inch. The spacing between threads/rows would always return zero. For some reason, (fix) seemed to fix the problem. I'll have to study this and find out why.
    (setq c... line altogether], and save yourself a variable.<

    Yes, I had it that way at one time. Then I was thinking that AutoCAD might remember a previous "c" setting. I now see that it doesn't, and always has a default of "1" for this. So I'll use the "" and save myself a variable. Thanks for your help.
     
    kzalec, Oct 28, 2004
    #6
  7. kzalec

    kzalec Guest

    Thanks for the "p0". That's a good addition as many users prefer to "pick" the distance rather than type it in. It's best to give as many options as possible. Also, I appreciate the alternate use of the (fix w), preceded by use of all reals. I like seeing all the different ways of writing the code. I'm just a beginner at AutoLISP, but interested in learning more. Bought a few books, but there's not too much written on this subject. It's really nice to have this forum to get and receive help. Thanks much!
     
    kzalec, Oct 28, 2004
    #7
  8. kzalec

    kzalec Guest

    One last thing... I actually prefer "CAB2k"s way of using "fix" because with that method, it allows the user to PICK the length of the rod, rather than only being able to type in the length. Again, it gives the user the most options. But I like seeing the difference between the two approaches. This is how we all learn. Thanks again.
     
    kzalec, Oct 28, 2004
    #8
  9. kzalec

    Douglas Barr Guest

    It wasn't his 'fix' that allowed the pick, it was his 'getdist'. He could
    have alternatively used getreal. Don't forget to add the p0 to the 'getdist'
    if you want to drag a height for your rod from your base point.

    Not all... some of us learn from 'our own' foolish blunders rather than
    avoiding errors by seeing examples to choose among. And some of us admit to
    making mistakes, while 'others' profess total infallibility, thereby
    exposing themselves as the ignorant and dangerous morons they are.
     
    Douglas Barr, Oct 28, 2004
    #9
  10. kzalec

    CAB2k Guest

    Here is one with some error checking.
    (defun c:rod (/ r l b w ws p0 p1 p2 p3)
    (if (and (setq p0 (getpoint "\nPick lower left corner:"))
    (setq r (getdist p0 "\n Enter or pick radius of rod:"))
    (setq l (getdist p0 "\n Enter or pick length of rod:"))
    (setq b (getint "\n Enter number of threads per inch:"))
    )
    (progn
    (setq 90d (/ pi 2))
    (setq w (fix (* l b))) ;# of rows for array
    (setq ws (/ l w)) ;row spacing
    (setq p1 (polar p0 0 (* r 1.22474488)))
    (setq p2 (polar p1 90d l))
    (setq p3 (polar p0 pi (* r 1.22474488)))
    (command "line" p1 p2 "")
    (command "line" p3 (polar p3 90d l) "")
    (command "ellipse" (polar p3 90d l) p2 "r" 60) ;creates isocircle on top:
    (command "ellipse" "a" p3 p1 "r" 60 p3 180) ;creates bottom isocircle half:
    (command "array" "L" "" "r" w "" ws) ; arrays "threads" up
    )
    )
    (princ)
    )
     
    CAB2k, Oct 29, 2004
    #10
  11. kzalec

    kzalec Guest

    Yes, I discovered this myself as I was studying the code yesterday (getdist). I guess that "getdist" always returns a real number even if you type in an integer. That's why the "fix" is necessary to convert it back to an integer (because the "array" command (# of rows) only accepts an integer. I thought that was the problem all along, but didn't know the function to use (fix) to fix it. I always spend a long time trying to figure things out myself before asking others. But I think it's VERY helpful to have tools like this forum as a learning aid. Thanks to EVERYONE who replied. I really appreciate knowing the different ways of doing things. Yes, I could use either "getdist" of "getint" for the "number of threads per inch". It would be unusual for someone to type in anything other than an integer for this prompt. However, "getreal" gives the user the most options as a response, so perhaps that one would be the best. By the way, I wouldn't refer to anyone who dabbles in AutoLISP a "moron" : - ) Thanks again to everyone who replied to my posting.
     
    kzalec, Oct 29, 2004
    #11
  12. kzalec

    Douglas Barr Guest

    Neither would I.

    It was a (prohibited) political commentary, unrelated to anyone in here.
    -doug
     
    Douglas Barr, Oct 29, 2004
    #12
  13. kzalec

    BillZ Guest

    Go ahead Doug, let it out. ;^)



    Bill
     
    BillZ, Oct 29, 2004
    #13
  14. kzalec

    Douglas Barr Guest

    I wish I had more sway... but at least there is a growing list of
    influential people 'of the opposing persuasion' who are endorsing the
    opponent. Latest being ex-Senator Bob Smith (R, NH).
     
    Douglas Barr, Oct 29, 2004
    #14
  15. kzalec

    BillZ Guest

    "endorsing the
    opponent"

    Like endorsing the Flu.

    Kasara'

    Bill
     
    BillZ, Oct 29, 2004
    #15
  16. kzalec

    Douglas Barr Guest

    I googled 'kasara'

    Fire prevention at Asser Al-Kasara - Yemen Times
    .... Fire prevention at Asser Al-Kasara. ... A child washing dishes outside
    in Asser
    Al-Kasara in Sana'a (Yemen Times photo by Peter Willems). ...
    www.yementimes.com/article. shtml?i=781&p=community&a=2 - 26k - Cached -
    Similar pages
    HKFlix.com | Browse | kasara films
    .... YOU'RE CURRENTLY BROWSING KASARA DVDs & VCDs ... Click For Details!
    Asian Beauties (2003)
    Lynn Thomas, Francine Dee, Linda Tran, Kristen, Kasara, Suni, Linda . . .
    ....
    www.hkflix.com/xq/asp/person.kasara/qx/titles.htm - Similar pages

    House of Kasara - Klingon Family Line
    A well-respected family line within the Klingon Empire, House Kasara is best
    known
    for it's Schools of Diplomacy and Military Arts and it's large Merchant ...
    www.housekasara.org/ - 5k - Cached - Similar pages

    View Profile for Kasara - AT&T Wireless Support Forums
    .... AT&T Wireless Support Forums : View Profile for Kasara. User
    Information. Login,
    Kasara. Rank, Moderator. Online Status, Offline. Personal Icon, ...
    forums.attwireless.com/ attws/view_profile?user.id=157815 - 36k - Oct 27,
    2004 - Cached - Similar pages

    SuicideGirls > Girls > Kasara
    .... SUICIDEGIRL: KASARA. Kasara: ... PICS AND VIDEOS. Kasara: Ignite
    PHOTOSET. NOV 16, 2003.
    IGNITE. Kasara: Lewd PHOTOSET. MAY 14, 2004. LEWD. SEE MY FAVORITE SG PICS.
    ....
    suicidegirls.com/girls/Kasara/ - 69k - Cached - Similar pages

    SuicideGirls > Girls > Kasara
    ... New Features! Kickass Clothing. Doghouse contest. JOIN NOW FOR AS LOW
    AS $4 A MONTH.
    SUICIDEGIRL: KASARA. Kasara: ... PICS AND VIDEOS. Kasara: Ignite PHOTOSET.
    ....
    suicidegirls.com/members/Kasara/ - 70k - Cached - Similar pages
    [ More results from suicidegirls.com ]

    Bitum
    The Bitum of Kasara Ubaratutu -- [Entrance ] [Courtyard ] [Library ]
    [Study ]. Kasara's
    Friends (-) More of Kasara's - Friends... Kasara's Journals. ...
    www.ancientsites.com/member/Ubaratutu/Kasara - 18k - Cached - Similar pages

    Pushpak Express at Kasara
    ACTION AT KASARA Scene at the Kalyan end of Kasara station. Pushpak appears
    to be
    flaunting its superfast status as it powers into Kasara horns blaring. ...
    irfca.org/members/sridhar/pushpak.html - 5k - Cached - Similar pages

    Am I Right - Song Parodies, Kasara's Fat Chick Blues
    .... Song Parodies -> Kasara's Fat Chick Blues. "Folsom Prison Blues" Based
    on the
    performance by Johnny Cash "Kasara's Fat Chick Blues" Parody by Shane
    Frederick. ...
    www.amiright.com/parody/70s/johnnycash4.shtml - 29k - Cached - Similar pages

    Traffic Status
    l Bhor Ghat l Kasara Ghat l. Kasara Ghat on Mumbai-Agra Road (National
    Highway
    No. 3). Previous 24 Hours, Current, Announcements. October ...
    www.mahapwd.com/Traffic/TKStatus.asp - 11k - Cached - Similar pages

    Then I realized you meant 'que sera' ... 'what will be will be'
    Do you really believe that nothing anyone does will change the outcome?
     
    Douglas Barr, Oct 29, 2004
    #16
  17. kzalec

    Anne Brown Guest

    All political remarks posted after this message were removed.

    Anne
     
    Anne Brown, Oct 29, 2004
    #17
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.