finding points..

Discussion in 'AutoCAD' started by Court Myers, Jul 7, 2004.

  1. Court Myers

    Court Myers Guest

    how do i find the last two points in a polyline that i has just drawn in
    lisp? is there a way to map all the points and recall the last two? do i
    use the mapcar command? if so how....

    exp.

    (command "_.PLINE")
    (while (> (getvar "CMDACTIVE") 0)
    (getvar lp01 (getvar "nexttolastpoint")
    (getvar lp02 (getvar "lastpoint")
    (setq lp03 (polar lp02 (angle lp01 lp02) (* scale01 0.2656250)))

    Thanks Court

    ps..... this is a variation on my last post..
     
    Court Myers, Jul 7, 2004
    #1
  2. A "nextotolastpoint" system variable sure could be handy sometimes. So
    could a "next-to-last-entity" option in object selection, or a
    "the-last-<x>-entities" option. (I've built myself an
    erase-the-last-<x>-entities routine.)

    You should be able to save each point as you go, and make your own
    next-to-last point by setting the lp01 to the "old" lastpoint before picking
    a "new" one with the next point on the Pline.

    At first I thought you probably don't need to save that lp03 future
    insertion point after every pline segment you draw, just after the last one
    (i.e. after the end of the "while" operation):

    (command "_.PLINE")
    (while (> (getvar "CMDACTIVE") 0)
    (setq lp01 lp02
    lp02 (getpoint lp01)
    (
    (
    (setq lp03 (polar lp02 (angle lp01 lp02) (* scale01 0.2656250)))

    But no, that wouldn't work, because it would go back around and set lp01
    equal to lp02 before you got a chance to end the Pline command, so you'd end
    up with lp01 and lp02 being the same, which would spoil the setting of lp03.

    So maybe you should, after all, set lp03 each time, but you need some setq's
    and a getpoint in place of some getvar's. Does this work?

    (command "_.PLINE")
    (while (> (getvar "CMDACTIVE") 0)
    (setq lp01 lp02)
    lp02 (getpoint lp01)
    lp03 (polar lp02 (angle lp01 lp02) (* scale01 0.2656250))
    )
    )
    <...insert at lp03...>

    I'm assuming the still-active Pline command will supply a prompt for the
    next point, so you don't need to put one in with the "getpoint" function.

    Then, even if it goes back and sets lp01 equal to lp02 again before you end
    Pline, it won't matter because you'll already have the lp03 location defined
    anyway.

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Jul 7, 2004
    #2
  3. Court Myers

    Jürg Menzi Guest

    Hi Court

    One solution can be the use of vlax-curve-xxxx functions:

    <snip>
    (vl-load-com)
    ....
    (command "_.PLINE")
    (while...)
    (setq TmpObj (vlax-ename->vla-object (entlast))
    lp03 (polar
    (vlax-curve-getEndPoint TmpObj)
    (Vec2Ang
    (vlax-curve-getFirstDeriv
    TmpObj
    (vlax-curve-getEndParam TmpObj)
    )
    )
    (* scale01 0.2656250)
    )
    )
    <snip>

    ;
    ; == Function Vec2Ang
    ; Converts a vector to an angle.
    ; Arguments [Type]:
    ; Vec = Vector value

    • ; Return [Type]:
      ; > Angle value [REAL]
      ; Notes:
      ; Credits to Luis Esquivel
      ;
      (defun Vec2Ang (Vec / XvcVal YvcVal)
      (setq XvcVal (car Vec)
      YvcVal (cadr Vec)
      )
      (cond
      ((equal XvcVal 0 1E-4) (if (minusp YvcVal) (* pi 1.5) (* pi 0.5)))
      ((equal XvcVal -1 1E-4) pi)
      ((equal YvcVal 0 1E-4) (if (minusp XvcVal) pi 0.0))
      ((atan YvcVal XvcVal))
      )
      )

      This will work with all kind of Polylines, Splines, Lines, Arcs etc.
      Because we use the end tangent also no prob with 'bulged' Polylines...

      Cheers
     
    Jürg Menzi, Jul 7, 2004
    #3
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.