TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: litss 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!
-
(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)
)
)
)
)
)
-
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 ) :-)
-
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:(
-
Try this:
Note that vlax-curve-getDistAtPoint is unreliable, so use vlax-curve-getdistatparam
(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)
)
)
)
)
)
)
)
)
-
Thx, CAB!
It works perfectly! :)
BTW, what's the problem with vlax-curve-getDistAtPoint?
-
Note that vlax-curve-getDistAtPoint is unreliable
Alan, can you elaborate on this? Any example? Thanks.
-
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.
(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)
)
-
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:
(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)
)
)
)
)
)
-
This what I get when I use this code.
(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)
)
)
)
)
)
)
-
This what I get when I use this code.
and this is mine :)
this is strange, something is wrong with your acad :?
-
Tested in ACAD 2000 plain.
:lol:
-
mine is LDT 2004 sp2