How to find out which segment of LWPOLYLINE is selected?

Discussion in 'AutoCAD' started by Alexander V. Koshman, Nov 25, 2004.

  1. Hello to everybody here!
    ----------------------------
    Do you can tell me,
    how to find out which segment of LWPOLYLINE is selected?

    I figured out to
    1. (entget ...) the selected LWPOLYLINE;
    2. reconstruct it with LINEs and ARCs;
    3. number these new entities;
    4. select some new entity with (entsel ...);
    5. find out which element was selected by its number...

    But I think there must be a simple way to do it...

    Thank you all again!
     
    Alexander V. Koshman, Nov 25, 2004
    #1
  2. Alexander V. Koshman

    Jeff Mishler Guest

    Here's an example of how you can do this. The segment index is 0 based, so
    if you want to report that the first segment was selected add 1 to this
    result. Yes, this code can be condensed, but I show it like this so you can
    clearly see the steps taken.

    (setq pline (entsel))
    (setq pick (cadr pline))
    (setq plObj (vlax-ename->vla-object (car pline)))
    (setq pick2 (vlax-curve-getclosestpointto plobj pick))
    (setq param (vlax-curve-getparamatpoint plObj pick2))
    (setq segment (fix param))
     
    Jeff Mishler, Nov 25, 2004
    #2
  3. Thank you Jeff!!!
    ------------------
    Sorry for delay but I missed my Internet connection for a while.

    I hoped there is some way in VisualLISP.

    Thank you again!
     
    Alexander V. Koshman, Nov 28, 2004
    #3
  4. Hi Jeff!
    ----------
    I don't understand something or I do something wrong?

    I draw the LWPOLYLINE then run your code.
    For example I pick the first segment of LWPOLY
    and get for the result some 4-digit number...

    What is it???

    ******************************************************
    Command: (setq pline (entsel))

    Select object: (<Entity name: 40071140> (18733.0 12086.0 0.0))

    Command: (setq pick (cadr pline))
    (18733.0 12086.0 0.0)

    Command: (setq plObj (vlax-ename->vla-object (car pline)))
    #<VLA-OBJECT IAcadLine 029da1a4>

    Command: (setq pick2 (vlax-curve-getclosestpointto plobj pick))
    (18760.2 12059.6 0.0)

    Command: (setq param (vlax-curve-getparamatpoint plObj pick2))
    5701.33

    Command: (setq segment (fix param))
    5701

    ******************************************************

    From the Help:

    (vlax-curve-getParamAtPoint curve-obj point)
    ===================================

    Return Values:
    ---------------
    A real number representing a parameter, if successful, otherwise nil.

    ******************************************************


    Help me!.. : (
     
    Alexander V. Koshman, Nov 28, 2004
    #4
  5. Alexander V. Koshman

    Jeff Mishler Guest

    Hi Alexander,
    I'm glad you got your internet connection back :)

    The param will return the length from the start to the picked point if you
    select a line. You apparently mistakenly selected a line, not a LWPolyline:
    Try it again with a polyline :)
     
    Jeff Mishler, Nov 28, 2004
    #5
  6. Try it again with a polyline :)

    Oh!.. Jeff...
    -------------
    I'm so sorry... ;-(

    YOU WERE ABSOLUTELY RIGHT!
    You know it was the Sunday evening...

    Thank you again for your PATIENCE!!!
     
    Alexander V. Koshman, Nov 28, 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.