Segment of a polygon

Discussion in 'AutoCAD' started by Ken Alexander, Jul 15, 2004.

  1. I am struggling on coming up with a way to determine which segment of
    a polygon is picked by clicking on the segment. My end goal is to put
    rectangles along a selected segment at a certain spacing. Could
    someone give me a kick in the right direction. Thanks.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 15, 2004
    #1
  2. Ken Alexander

    Jeff Mishler Guest

    You mean like this? The segments are 0 based, so the first one is 0, second
    is 1, etc.

    (setq obj (vlax-ename->vla-object (car (entsel "Select pline: "))))
    (setq pt (vlax-curve-getClosestPointTo obj (getpoint "Select point: ")))
    (setq param (vlax-curve-getparamatpoint obj pt))
    (setq seg# (fix param))

    Then with help of the other vlax-curve- functions your spacing portion
    should be a snap.

    HTH,
    Lord knows you've helped me a lot over the years ;-)
    Jeff
     
    Jeff Mishler, Jul 15, 2004
    #2
  3. Jeff,

    Those dog gone curve functions. Thanks, I believe that is the "kick"
    I needed.
    I'll give them a go.

    Thanks a bunch,

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 15, 2004
    #3
  4. Hi Ken,

    Haven't seen you around much these days.
    Hope all is well.

    I picked this up from someone in this group,
    just don't remember who.

    (setq point (cadr (entsel "\nselect an object: ")))

    (nth 2 (car (ssnamex (ssget point))))


    Just alternative to Jeff's suggestion.
     
    Jason Piercey, Jul 15, 2004
    #4
  5. Ken Alexander

    Joe Burke Guest

    Hi Ken,

    You might want to compare what you have so far with John Uhden's SegmentPts function.
    It does exactly what you want. It's been posted here quite a few times. I'm sure all
    flavors are not the same. But of course the methods are what would be of interest.

    I'll post what I have if you can't find it. Or maybe the author will grace us with
    his presence... We miss you, John. ;-)

    Regards
    Joe Burke
     
    Joe Burke, Jul 16, 2004
    #5
  6. Hey Jason,

    Yeah I don't get to do much with Acad customization anymore. Seems
    I've built all the custom tools we need. :-( Been diving into some
    SQL and heading into VB and CNC stuff. It all comes back to Acad
    though. Visual Basic is pretty cool. Thanks to this NG I've been
    able to pick up on it a little. I have an idea that here shortly I'll
    be living in the VBA NG.

    Thanks for the help. I'm putting together a few tools for drawing CNC
    milling operations. Got stuck on the very first one.

    Thanks again.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 16, 2004
    #6
  7. Joe,

    This is what I have so far: <grin>

    (defun Horz_D315_32mm ()
    (princ)
    )

    I did a quick search through OE didn't come up with anything. I'll do
    some gooooogling. I look forward to comparing.......using John's
    function.

    Thanks

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 16, 2004
    #7
  8. Ken Alexander

    Joe Burke Guest

    Ken,

    Good work so far... ;-)

    Google search would find John's function, but don't bother. Here's what I have. As I
    said, it may not be what John posted most recently. But it does demonstrate how to
    use the vlax-curve functions to solve the problem.

    Joe Burke

    ;returns a list of two 3D points, the end points of the segment picked
    ;argument: ENT as returned by entsel
    ;works with lines, arcs and all types of plines
    ;by John Uhden - revised 9/28/02
    (defun SegmentPts (ent / e pnt vobj Name param1 param2 p1 p2)
    ;(vl-load-com)
    (and
    (setq e (car ent))
    (= (type e) 'ENAME)
    (setq pnt (cadr ent))
    (listp pnt)
    (not (atom (cdr pnt)))
    (vl-every (function (lambda (x)(= (type x) 'REAL))) pnt)
    (setq vobj (vlax-ename->vla-object (car ent)))
    (setq pnt (trans (cadr ent) 1 0))
    (setq pnt (vlax-curve-getClosestPointTo vobj pnt))
    (setq Name (vla-get-ObjectName vobj))
    (cond
    ((vl-position Name '("AcDbArc" "AcDbLine"))
    (setq p1 (vlax-curve-getStartPoint vobj))
    (setq p2 (vlax-curve-getEndPoint vobj))
    )
    ((wcmatch (strcase Name) "*POLYLINE")
    (setq param1 (vlax-curve-getParamAtPoint vobj pnt))
    (setq param1 (fix param1))
    (setq param2 (1+ param1))
    (if (equal param1 (vlax-curve-getStartParam vobj) 1e-10)
    (setq p1 (vlax-curve-getStartPoint vobj))
    (setq p1 (vlax-curve-getPointAtParam vobj param1))
    )
    (if (equal param2 (vlax-curve-getEndParam vobj) 1e-10)
    (setq p2 (vlax-curve-getEndPoint vobj))
    (setq p2 (vlax-curve-getPointAtParam vobj param2))
    )
    )
    (T (prompt (strcat "\nHaven't figured out a(n) " Name " yet.")))
    )
    p1 p2
    )
    (list p1 p2)
    ) ;end
     
    Joe Burke, Jul 16, 2004
    #8
  9. Hey thanks Joe. That is exactly what I was looking to do.

    BTW feel free to use, modify, and distribute my function.


    Thanks again.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein

     
    Ken Alexander, Jul 16, 2004
    #9
  10. Ken Alexander

    Joe Burke Guest

    Ken,

    It's a small repayment for your GetNumber function back around January of this year.
    That solved a bunch of problems on my end.

    Joe
     
    Joe Burke, Jul 16, 2004
    #10
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.