if - angle = - then

Discussion in 'AutoCAD' started by JB, Jan 20, 2004.

  1. JB

    JB Guest

    Can someone help me with lisp code for the following problem

    if angle betweet PT1 and PT2 = 0 to 90 then do this
    if angle betweet PT1 and PT2 = 270 to 360 then do this

    I am working on a routine to insert blocks that represent ridge line roof
    tiles. It works fine as long as the pitch inclines from left to right.
    They are upside down if the pitch is inclined from right to left.

    Thanks!

    -JB

    here is what I have so far


    (defun ridgeline_er (s)
    (if (/= s "function cancelled")
    (if (= s "quit / exit abort")
    (princ)
    (princ (strcat "\nError:"s))
    )
    )
    (setvar "snapang" 0)
    (setq *error* olderr)
    (princ)
    )

    (defun c:ridgeline ()
    (setq olderr *error*
    *error* ridgeline_er)
    (setvar "cmdecho" 0)
    (graphscr)
    (setq PT1 (getpoint "\nSelect bottom point of Ridgeline:"))
    (setq PT2 (getpoint "\nSelect top point of Ridgeline:"))
    (setq LAY (cdr (assoc 8 ENAME)))
    (setq CLR (cdr (assoc 62 (tblsearch "layer" LAY))))
    (setq ANG (* (/(angle PT1 PT2)pi)180))
    (setq DIST (distance PT1 PT2))
    (setq QTYR (/ DIST 12))
    (setq QTYI (fix QTYR))
    (setq SCL "1")
    (setq blknam "ridgetile")
    (command "_.insert" blknam PT1 SCL "" ANG)
    (setq STD (entlast))
    (command "snap" "r" "0,0" ANG)
    (setq cpyang (strcat "@12<" (rtos ang 2 2)))
    (repeat QTYI (setq STD (entlast))(command "copy" STD "" "@" cpyang))
    (setvar "snapang" 0)
    )
     
    JB, Jan 20, 2004
    #1
  2. JB

    Tom Smith Guest

    Don't you mean 0 to 90 and 90 to 180? If you're picking from bottom to top,
    you shouldn't get angles over 180.

    I think that giving the block a negative y scale when needed should flip it
    right side up. If that's true, you could change your (setq SCL "1") to:

    (setq SCLX "1")

    (if (> ANG 90)
    (setq SCLY "-1")
    (setq SCLY "1")
    )

    And change (command "_.insert" blknam PT1 SCL "" ANG) to:

    (command "_.insert" blknam PT1 SCLX SCLY ANG)
     
    Tom Smith, Jan 20, 2004
    #2
  3. JB

    Tom Smith Guest

    Don't you mean 0 to 90 and 90 to 180? If you're picking from bottom to top,
    you shouldn't get angles over 180.

    I think you can flip the block right side up by giving it a negative Y scale
    if the angle is over 90 degrees.

    (setq SCLX "1")
    (if (> ANG 90)
    (setq SCLY "-1")
    (setq SCLY "1")
    )

    (command "_.insert" blknam PT1 SCLX SCLY ANG)
     
    Tom Smith, Jan 20, 2004
    #3
  4. JB

    Rudy Tovar Guest

    Depending on if you're using 'entsel' to select lines, there will be times
    when an angle of greater than 360 will be returned. This is a known fact.
    Some angles of 0 return 360, as well as 180 return odd angles greater than
    360. Another option is provided below that can be used in a number of
    different combinations.

    (= (angtos angle1 0 4) (angtos angle2 0 4))
    --

    AUTODESK
    Authorized Developer
    www.Cadentity.com
    MASi
     
    Rudy Tovar, Jan 20, 2004
    #4
  5. JB

    JB Guest

    Worked perfectly Thanks!

    I am sure the others would have worked too but my simple mind could only
    sort out so much.
     
    JB, Jan 20, 2004
    #5
  6. JB

    Tom Smith Guest

    my simple mind could only sort out so much.

    That's me too. I try not to think any more than necessary :)
     
    Tom Smith, Jan 20, 2004
    #6
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.