Author Topic: pts list rearange along a closed pline  (Read 4826 times)

0 Members and 1 Guest are viewing this topic.

litss

  • Guest
pts list rearange along a closed pline
« on: May 09, 2008, 05:10:47 AM »
I have a list of points, and all the pts are on a closed pline. But the position of points in the list is random. I wish to rearange them and make a new list, so that they could be along the pline ( from the startpoint to the endpoint of the pline). How could I realize it? thx!


VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: pts list rearange along a closed pline
« Reply #1 on: May 09, 2008, 05:35:09 AM »
Code: [Select]
(vl-load-com)
(if (setq EntName (car (entsel "\nSelect pline")))
  (vl-sort PointsList
   (function (lambda (p1 p2)
       (< (vlax-curve-getDistAtPoint EntName p1)
  (vlax-curve-getDistAtPoint EntName p2)
       )
     )
   )
  )
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: pts list rearange along a closed pline
« Reply #2 on: May 09, 2008, 06:04:58 AM »

Came back to post an almost identical solution .... I had the EntName converted to a VLA-object ( 'cause thats what the docs say it should be )  :-)



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

litss

  • Guest
Re: pts list rearange along a closed pline
« Reply #3 on: May 11, 2008, 11:06:01 PM »
thx VovKa and Kerry!

I tried the code. but the result is not what I want. Here is a sample ptlist:

((13032.8 -182954.0 0.0) (12680.0 -182954.0 0.0) (13702.7 -182954.0 0.0)
(12680.0 -182365.0 0.0) (13032.8 -182365.0 0.0) (13702.7 -182365.0 0.0)
(12680.0 -181972.0 0.0) (12680.0 -181504.0 0.0) (13702.7 -181111.0 0.0)
(12680.0 -181111.0 0.0) (14055.5 -181111.0 0.0) (13032.8 -181111.0 0.0)
(13702.7 -181504.0 0.0) (14055.5 -181504.0 0.0) (13032.8 -181504.0 0.0)
(14055.5 -181972.0 0.0) (13702.7 -181972.0 0.0) (13032.8 -181972.0 0.0)
(14055.5 -182365.0 0.0) (14055.5 -182954.0 0.0) (13032.8 -183347.0 0.0)
(14055.5 -183347.0 0.0) (12680.0 -183347.0 0.0) (13702.7 -183347.0 0.0))

and the according pline in the attached dwg file.

By using the code written by Vovka, I get the result like the pic shows. It's not what I want:(


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: pts list rearange along a closed pline
« Reply #4 on: May 12, 2008, 12:12:52 AM »
Try this:
Note that vlax-curve-getDistAtPoint is unreliable, so use vlax-curve-getdistatparam
Code: [Select]
  (if (setq cCurve (car (entsel "\nSelect pline")))
      (setq newlist
             (vl-sort PointsList
                      (function (lambda (p1 p2)
                                  (< (vlax-curve-getdistatparam cCurve
                                       (vlax-curve-getparamatpoint  cCurve
                                         (vlax-curve-getclosestpointto cCurve P1)
                                       )
                                     )
                                     (vlax-curve-getdistatparam cCurve
                                       (vlax-curve-getparamatpoint cCurve
                                         (vlax-curve-getclosestpointto cCurve P2)
                                       )
                                     )
                                  )
                                )
                      )
             )
         )
      )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

litss

  • Guest
Re: pts list rearange along a closed pline
« Reply #5 on: May 12, 2008, 01:53:25 AM »
Thx, CAB!

It works perfectly! :)

BTW, what's the problem with vlax-curve-getDistAtPoint?

FengK

  • Guest
Re: pts list rearange along a closed pline
« Reply #6 on: May 12, 2008, 02:04:46 AM »
Note that vlax-curve-getDistAtPoint is unreliable

Alan, can you elaborate on this? Any example? Thanks.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: pts list rearange along a closed pline
« Reply #7 on: May 12, 2008, 09:43:10 AM »
Well I may have spoken too soon.
But, I am working on a Break with gap routine & haven't isolated the problem.
When I finish my current project I will test this to see if I can isolate the cause.

In the mean time you can use my test rig on litss pline.DWG found in his post.
Code: [Select]
(defun c:test2 ()
  (setq pointslist
         '((13032.8 -182954.0)
           (12680.0 -182954.0)
           (13702.7 -182954.0)
           (12680.0 -182365.0)
           (13032.8 -182365.0)
           (13702.7 -182365.0)
           (12680.0 -181972.0)
           (12680.0 -181504.0)
           (13702.7 -181111.0)
           (12680.0 -181111.0)
           (14055.5 -181111.0)
           (13032.8 -181111.0)
           (13702.7 -181504.0)
           (14055.5 -181504.0)
           (13032.8 -181504.0)
           (14055.5 -181972.0)
           (13702.7 -181972.0)
           (13032.8 -181972.0)
           (14055.5 -182365.0)
           (14055.5 -182954.0)
           (13032.8 -183347.0)
           (14055.5 -183347.0)
           (12680.0 -183347.0)
           (13702.7 -183347.0)
          )
  )
  (if (setq cCurve (car (entsel "\nSelect pline")))
    (progn


      ;;  example using vlax-curve-getdistatparam
      (setq newlist
             (vl-sort PointsList
                      (function (lambda (p1 p2)
                                  (< (vlax-curve-getdistatparam
                                       cCurve
                                       (vlax-curve-getparamatpoint
                                         cCurve
                                         (vlax-curve-getclosestpointto cCurve P1)
                                       )
                                     )
                                     (vlax-curve-getdistatparam
                                       cCurve
                                       (vlax-curve-getparamatpoint
                                         cCurve
                                         (vlax-curve-getclosestpointto cCurve P2)
                                       )
                                     )
                                  )
                                )
                      )
             )
      )

      ;|   ;;  example using vlax-curve-getdistatpoint
      (setq newlist
             (vl-sort PointsList
                      (function (lambda (p1 p2)
                                  (< (vlax-curve-getdistatpoint cCurve
                                         (vlax-curve-getclosestpointto cCurve P1)
                                     )
                                     (vlax-curve-getdistatpoint cCurve
                                         (vlax-curve-getclosestpointto cCurve P2)
                                     )
                                  )
                                )
                      )
             )
      )
|;

     

      (setq actDoc (vla-get-activedocument (vlax-get-acad-object))
            spFlag (vla-get-activespace actDoc)
      )
      (if (= 0 spFlag)
        (setq actSp (vla-get-paperspace actDoc))
        (setq actSp (vla-get-modelspace actDoc))
      )


      (setq idx 0)
      (foreach nextpt newlist
        (setq curDer (vlax-curve-getfirstderiv
                       cCurve
                       (vlax-curve-getparamatpoint
                         cCurve
                         (vlax-curve-getclosestpointto cCurve nextPt)
                       )
                     )
        )
        ;; Get angle 90 deg to curve
        (if (= (cadr curDer) 0.0)
          (setq curAng (/ pi 2))
          (setq curAng (- pi (atan (/ (car curDer) (cadr curDer)))))
        )
        (setq ptObj  (vla-addpoint actSp (vlax-3d-point nextPt))
              OffPt  (polar nextPt curAng (* 1.5 (getvar "TEXTSIZE")))
              txtObj (vla-addtext
                       actSp
                       (itoa idx)
                       (vlax-3d-point OffPt)
                       (getvar "TEXTSIZE")
                     )
        )
        (vla-put-alignment txtObj acalignmentmiddlecenter)
        (vla-put-textalignmentpoint txtobj (vlax-3d-point OffPt))
          ; (vla-put-layer ptObj (vla-get-name ptLay))
          ; (vla-put-layer txtObj (vla-get-name txtLay))
        (setq idx (1+ idx))
      )   ; end while

    )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: pts list rearange along a closed pline
« Reply #8 on: May 12, 2008, 12:04:32 PM »
the error was not caused by vlax-curve-getDistAtPoint
as soon as you've added of vlax-curve-getclosestpointto both vlax-curve-getDistAtPoint and vlax-curve-getParamAtPoint work OK on supplied pline.DWG
vlax-curve-getParamAtPoint appears to be faster than vlax-curve-getDistAtPoint, so i would suggest:
Code: [Select]
(vl-sort PointsList
                      (function (lambda (p1 p2)
                                  (< (vlax-curve-getparamatpoint cCurve
                                         (vlax-curve-getclosestpointto cCurve P1)
                                     )
                                     (vlax-curve-getparamatpoint cCurve
                                         (vlax-curve-getclosestpointto cCurve P2)
                                     )
                                  )
                                )
                      )
             )
« Last Edit: May 12, 2008, 12:17:30 PM by VovKa »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: pts list rearange along a closed pline
« Reply #9 on: May 12, 2008, 12:15:20 PM »
This what I get when I use this code.
Code: [Select]
      (setq newlist
             (vl-sort PointsList
                      (function (lambda (p1 p2)
                                  (< (vlax-curve-getdistatpoint cCurve
                                         (vlax-curve-getclosestpointto cCurve P1)
                                     )
                                     (vlax-curve-getdistatpoint cCurve
                                         (vlax-curve-getclosestpointto cCurve P2)
                                     )
                                  )
                                )
                      )
             )
      )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: pts list rearange along a closed pline
« Reply #10 on: May 12, 2008, 12:24:28 PM »
This what I get when I use this code.
and this is mine :)

this is strange, something is wrong with your acad :?
« Last Edit: May 12, 2008, 12:30:30 PM by VovKa »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: pts list rearange along a closed pline
« Reply #11 on: May 12, 2008, 01:04:44 PM »
Tested in ACAD 2000 plain.
 :lol:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: pts list rearange along a closed pline
« Reply #12 on: May 12, 2008, 01:19:55 PM »
mine is LDT 2004 sp2