Line angle problem

Discussion in 'AutoCAD' started by Jamie Myers, Aug 11, 2003.

  1. Jamie Myers

    Jamie Myers Guest

    Bear with me while I try to explain this. It's a little complicated. Let's
    say that I have a line that starts at point 10,20 and ends at point 40,30.
    I know, this will give a line angle of 18.43494882. Now, let's say that
    there is another line that runs completely opposite of this, starts at point
    40,30 and ends at point 10,20 which has a line angle of 198.43494882. A 180
    degree turnaround. My problem is when I try to insert a block onto one side
    of either of these lines using lisp. Where the insert command asks for the
    angle, if I put in either of these angles, it will always be on one side of
    the line. If my insertion point is closer to one end, then my block will be
    put in either on the top of the line, or below the line depending on which
    end the insertion point is. I'm using assoc 10 & 11 codes to find the start
    and end points of the line so that I can specify a certain distance from the
    end of the line. I dunno if this makes any sense, but it causing me
    problems in several of my routines not only with blocks, but with drawing
    lines from that line to a certain angle and/or distance away. I have a
    routine for creating a section line which can only be used at either 0, 90,
    180, and 270 degrees. It might be a good example to use so that everyone
    can be on the same track. I don't know about posting it in here, because, I
    know that there are alot of people who make there money off of routines like
    this. It would be cheaper for our company to just buy these, but the seem
    to not understand that the time I spend on doing these routines is far more
    expensive. Therefore, I have to create my own if I want to stay ahead of
    the game. I really don't know what the proper etiquette would be for
    posting that.
     
    Jamie Myers, Aug 11, 2003
    #1
  2. Is "osmode" set to 0 prior to inseringt blocks or drawing lines. Your
    program might be snapping to a point with the running osnaps turned on.
     
    Jamie Richardson, Aug 11, 2003
    #2

  3. Would this help ?? remove unwanted parts and go whoopie all night long !!!

    ;;; LTR.lsp - select Line entity and Text entitiy. Rotate text based on line
    angle.
    ;;; By: Jeffery P Sanders 10/9/02
    ;;;
    ;;; Modified March 2003
    ;;; By Pierre Marcotte

    (DEFUN C:LTR ()
    (SETVAR "cmdecho" 0)
    (PRINC "\n Select LINE with Correct Angle")
    (IF (SETQ eset (ENTSEL " : "))
    (PROGN
    (REDRAW (car eset) 3)
    (SETQ en (CAR eset))
    (SETQ enlist (ENTGET en))
    (IF (= "LINE" (CDR (ASSOC 0 enlist)))
    (PROGN
    (PRINC "\n Select TEXT to Match Line Angle")
    (IF (SETQ eset2 (ENTSEL " : "))
    (PROGN
    (SETQ ept1 (CDR (ASSOC 10 enlist)))
    (SETQ ept2 (CDR (ASSOC 11 enlist)))
    (SETQ ang1 (ANGLE ept1 ept2))

    ************** This is the part you're probably after *********
    (COND ((< ang1 0) (SETQ ang1 (+ ang1 (* 2 PI))))
    ((AND (> ang1 (/ PI 2)) (<= ang1 PI))
    (SETQ ang1 (- ang1 PI))
    )
    ((AND (> ang1 PI) (<= ang1 (* 1.5 PI)))
    (SETQ ang1 (+ ang1 PI))
    )
    ) ;_ end of COND
    ************** End of part *****************

    (SETQ en2 (CAR eset2))
    (SETQ enlist2 (ENTGET en2))
    (SETQ enlist2 (SUBST (CONS 50 ang1)
    (ASSOC 50 enlist2)
    enlist2
    ) ;_ end of SUBST
    ) ;_ end of SETQ
    (ENTMOD enlist2)
    ) ;_ end of PROGN
    (PRINC "\n Select Text Entity Please. Program Aborted.")
    ) ;_ end of IF
    ) ;_ end of PROGN
    (PRINC
    "\n Enitity selected was not a LINE. Program Aborted."
    ) ;_ end of PRINC
    ) ;_ end of IF
    (REDRAW (car eset) 4)
    ) ;_ end of PROGN
    (PRINC "\n Nothing selected. Program Aborted.")
    ) ;_ end of IF
    (SETVAR "cmdecho" 1)
    (PRINC)
    ) ;_ end of DEFUN

    Dr Fleau
     
    Pierre Marcotte, Aug 11, 2003
    #3
  4. Jamie Myers

    Jamie Myers Guest

    Nope. The problem is having autocad read the line angle correctly. What I
    have gotten to work has been using alot of if functions and then its only in
    4 directions. I've tried rotating the ucs, readjusting the baseangle and
    several other things. Rotating the UCS seems to be the most practacle, but
    I'm still having trouble. I would believ that it's a fairly common thing
    everyone does.

    Let me try another example. Let's say that I had a routine to draw a
    window, then insert it on a wall.
    If I use something like this:

    (setq Line (entsel "/nPick line: "))
    (setq Start (assoc 10 (entget Line)))
    (setq End (assoc 11 (entget Line)))
    (setq InsertionPoint (cadr Line))
    (setq LineAngle Start End)
    (command "_insert" MyBlock InsertionPoint "" "" LineAngle)

    *If I got the syntax wrong on these I apologize. I'm trying to do this off
    memory. Hopefully you'll get the idea.*

    If the line runs at a 45 degree angle starting at point 10,10 , then the
    window will be put in correctly. now, if the line was drawn at a 225 degree
    angle, then the window would be put in on the wrong side. How can I correct
    this, and make it work for *any* angle?

    If you need more info, let me know.
     
    Jamie Myers, Aug 11, 2003
    #4
  5. Jamie Myers

    Joe Burke Guest

    Of course: (setq LineAngle (angle Start End))


     
    Joe Burke, Aug 11, 2003
    #5
  6. Jamie Myers

    Jamie Myers Guest

    Okay, that works. Let's try taking this a little farter. What happens if I
    want the window inserted at a specified point from the one end or the other.
    Let's say that I want the window center to be at 10'-0" from the start point
    of the line. It would insert on one end. Now if the start point was at
    10,10, the window would be placed correctly. But, if the start point was to
    be at 100,100 then the window would insert on the wrong end. And if you
    think about it, what would happen if the insertion point was to be
    at -10,-10? Then the math used to get the 10'-0" distance gets screwed up.
    I know, it's starting to get complicated. Agian, if I'm not making much
    sense, I'll try to explain it a little better.
     
    Jamie Myers, Aug 11, 2003
    #6
  7. Jamie Myers

    Jamie Myers Guest

    See my reply to Jow Burke.
     
    Jamie Myers, Aug 11, 2003
    #7
  8. Jamie Myers

    Jamie Myers Guest

    Jow or Joe take your pick. ;-)
     
    Jamie Myers, Aug 11, 2003
    #8
  9. Jamie Myers

    Jason Wilder Guest

    Well, a quick suggestion that comes to mind. Can you simply check the
    degree of the angle and then subtract 270, 180 or 90 from it?

    I've done something similar to what you're talking about, in regard to
    angles. I've done it both ways, where I devote a portion of code to
    determining the 'corrected' angle required.

    Such as in your window example, if the angle shows to be 225, then just
    subtract 180 from it before handing it to the insert command.
     
    Jason Wilder, Aug 11, 2003
    #9
  10. Jamie Myers

    Joe Burke Guest

    Good points, Jason.

    Jamie,

    Before you go any further, maybe consider a different approach. My
    experience is you pretty much have to determine in advance at what point
    along a wall a window will be placed. So what I do is go around the plan and
    draw a line across the wall (extending beyond the wall on both sides) to
    establish the centerlines of all the windows. The program prompts the user
    to pick the two intersection points, inside face of wall first. Those two
    points establish the angle, location and wall thickness. The program draws
    the window on-the-fly rather than using a block. Window size is user input.
    It also erases the temporary centerlines.

    You could do something similar using blocks. It would be a fairly simple
    program compared to where I think you are headed.

    HTH
    Joe Burke
     
    Joe Burke, Aug 11, 2003
    #10
  11. Jamie Myers

    Scribble Guest

    Jamie
    would this be any help:

    (setq start (assoc 10...
    (setq end (assoc 11...
    (if (> (dist pick start)(dist pick end))
    (progn (swap start end)........
     
    Scribble, Aug 12, 2003
    #11
  12. Jamie Myers

    Jamie Myers Guest

    It actually goes beyond just inserting a block on a wall. I have set up my
    routines to use the angle of the line to determine which way to draw a
    line/circle/text/etc. from my line. Like Joe was talking about, not
    inserting a block but drawing it with lisp, I would need a *reference angle*
    to work from. Now Joe touched on something, putting a line through a wall
    to draw a window and getting the points from that. That's great for windows
    and doors, but what about other things. I've got a routine for section
    lines as stated before. I cannot get it to work for other angles. I'm sure
    that this would be a routine joe and you already have, so I'll send Joe and
    you mine and let you see what I have.
     
    Jamie Myers, Aug 12, 2003
    #12
  13. Jamie Myers

    Jamie Myers Guest

    Spoke to soon Jason, I need your email address. Send it to jamie_myers at
    yahoo dot com.
     
    Jamie Myers, Aug 12, 2003
    #13
  14. Jamie Myers

    Joe Burke Guest

    Jamie,

    Just to clarify, my suggestion about drawing a line across the wall only
    applies to windows. For instance, I don't do that in my door insert
    programs. Inserting a window or a door in a wall share similar problems from
    a programming standpoint. What they don't have in common, in my opinion, is
    the thought process involved in deciding where the item should be placed.

    A door is almost always placed in relation to a wall corner. Give the user a
    default offset from corner with an option to change it. It ain't that simple
    with a window where you may need to consider the window's location in
    relation to other windows (exterior elevation) and/or furniture layout in
    the room. So to me it doesn't make sense to try to interactively place a
    window while in the program as it does with a door. You might as well set
    the location of the window beforehand. Which in turn makes the programming
    quite a bit easier.

    Joe Burke
     
    Joe Burke, Aug 12, 2003
    #14
  15. Jamie Myers

    Jamie Myers Guest

    What I planned on doing in the situation of a window or a door was to divide
    the exterior wall line up into 3 pieces, and depending on where on the line
    the insertion point is picked at, would determine if the insert will be
    offset from the end a predetermined distance or inserted in the middle. I
    have managed to get this to successfully work with exception of this line
    angle problem. I can get it to work a 0 and 90 degrees, but not for 180 and
    270. And, what if a wall is drawn at 45 degrees? It's a problem I have had
    with several other routines I'm working on, not just the ones with doors and
    windows. I'm certain others have had problems with this. I need to learn
    how they got around it, or, if I'm going about the whole thing the wrong
    way. The methods I use to get my routines to work are valid. I've put a
    lot of thought into the processes and what I want to acheive. I try ot make
    routines which are easier for my users to work with. The less iformation
    they have to put into it, the better. These guys are what most people would
    call a nightmare. Their cad knowledge is not that great and they are lazy
    when it comes to their drawings. I had to creat routines for layering
    because they are too lazy to change the layer name before they draw.
    Instead of trimming or glueing lines together, they just simply draw across
    another line. I understand what you mean by keeping the routine as simple
    as possible. But if I don't put alot of extra care and attention into it,
    then it wouldn't be used at all. The users would complain that it's too
    complicated. I'd rather leave the complications and the complexity in
    capable hands, mine.

    And don't get me wrong, you'd be amazed at how much I appreciate the help
    you guys are giving me. I've already learned quite a bit from this thread
    alone.
     
    Jamie Myers, Aug 12, 2003
    #15
  16. Jamie Myers

    Jason Wilder Guest

    I sent it to your e-mail, but I'll also post it here.

    This is a snipet of code I've used for a couple of my routines. The
    point(s) 'dir_pnt' are two arbitrary points picked by the user and then I
    translate a bit based on the angle. The remainder of this routine places a
    line that has tails on it that are drawn a certain way and then text is
    placed on or above the line. Which of course depending on angle needs to be
    drawn correctly so that it get's displayed on the drawing appropriately.

    So I utilize the (trans) function for my points and turn my UCS. We operate
    strictly in 2D, so this is a fairly easy process to use. I've done more
    complicated routines in the past that utilized the trans function
    throughout. The most difficult part of doing it this way is keeping the
    process 'straight' when you're coding it. Once you're complete, it should
    work rather nicely. Hope this helps some.


    (setq
    pnt1 (getpoint "First Point of direction notation: ")
    pnt2 (getpoint pnt1 "Second Point of direction notation: ")
    dirang (atoi (angtos (angle pnt1 pnt2)))
    tflag NIL
    )

    (if (or (= dirang 0) (= dirang 90) (= dirang 180) (= dirang 270))
    (progn
    (setq
    dir_pt1 pnt1
    dir_pt2 pnt2
    dirang_chk dirang
    )
    )
    (progn
    (if (and (> dirang 0) (< dirang 90)) (setq ucs_ang (itoa dirang)))
    (if (and (> dirang 90) (< dirang 180)) (setq ucs_ang (itoa (- dirang
    180))))
    (if (and (> dirang 180) (< dirang 270)) (setq ucs_ang (itoa (- dirang
    180))))
    (if (and (> dirang 270) (< dirang 360)) (setq ucs_ang (itoa (- dirang
    360))))
    (command ".ucs" "z" ucs_ang)
    (setq
    ucs_chk T
    dir_pt1 (trans pnt1 0 1)
    dir_pt2 (trans pnt2 0 1)
    dirang_chk (atoi (angtos (angle dir_pt1 dir_pt2) 0 3))
    )
    )
    )

    (setq
    pnt1x (car dir_pt1)
    pnt1y (cadr dir_pt1)
    pnt2x (car dir_pt2)
    pnt2y (cadr dir_pt2)
    dirlen (distance dir_pt1 dir_pt2)
    fwid 0.5
    )
     
    Jason Wilder, Aug 12, 2003
    #16
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.