aaryan Posted June 22, 2012 Posted June 22, 2012 Hi All, Need help again. Actually i am trying to write a code but not getting a start. I want to: a, Trace a polyline. i.e Select polyline and pick point anywhere on polyline and get a distance from stating vertex. b, if i pick a point except (anywhere right side or left side) of polyline it should also give me an offset distance. I made few lines but stuck. Any help to get me started would be appreciable... Regards Aaryan Quote
pBe Posted June 22, 2012 Posted June 22, 2012 for item "a" (defun c:test () (setvar 'osmode 0) (setq a (entsel "\nSelect polyline:")) (vlax-curve-getDistAtPoint (car a) (vlax-curve-getClosestPointTo (car a) (cadr a)))) For item "b": I'm not sure what you mean. Is that still part of item "A" , if the pick point is not on the polyline then it will give you a distance from pick point nearest to the polyline? Quote
aaryan Posted June 22, 2012 Author Posted June 22, 2012 Thanks pBe for your reply, For item "B" if the pick point is not on polyline then it should give me a perpendicular distance from the point picked to the point perdicular on polyline. in addition item "A" to be applied on 'point perpendicular on polyline'. I hope its clear for item "B". for item "A" i need something like this but its giving me a distance from ending vertex of a polyline.. (Defun c:KpInquiry() (setq Kproute (car (entsel "\nSelect Polyline Route:")) Kpprop (entget Kproute) Ppoint (getpoint "\nSpecify Point on polyline:")) (command "break" Kproute Ppoint ppoint "") (command "_list" "l" "") (setq Ppointlen (getvar "perimeter")) (command "_undo" 2 "") (princ (strcat "\nKP on this point is:" (rtos Ppointlen 2 3))) (princ)) Thanks and Regards Aaryan Quote
MSasu Posted June 22, 2012 Posted June 22, 2012 (edited) Please check if this is what you were looking for by second question: (vl-load-com) (defun c:test2( / thePoly thePoint ) (if (setq thePoly (ssget "_:S" '((0 . "LWPOLYLINE")))) (while (setq thePoint (getpoint "\nPick a point: ")) (prompt (strcat "\nDistance is " (rtos (distance thePoint (vlax-curve-getClosestPointTo (ssname thePoly 0) thePoint T)) 2 5))) ) ) (princ) ) Edited June 22, 2012 by MSasu Fixed the code Quote
pBe Posted June 22, 2012 Posted June 22, 2012 (defun c:test () (setvar 'osmode 0) (setq a (entsel "\nSelect polyline:")) (setq dist (vlax-curve-getDistAtPoint (car a) (vlax-curve-getClosestPointTo (car a) (cadr a)))) (princ (strcat "\nKP on this point is: " (rtos dist 2 3))) (princ) ) Not sure what the break is for. i guess the call to undo will "unbreak" the pline. Now depending on how the pline is created the result is subjective Quote
pBe Posted June 22, 2012 Posted June 22, 2012 perhaps this.. (defun c:test () (setvar 'osmode 0) (setq a (entsel "\nSelect polyline:")) (setq dist (vlax-curve-getDistAtParam (car a) (vlax-curve-getParamAtPoint (Car a) (vlax-curve-getClosestPointTo (car a) (cadr a))) )) (princ (strcat "\nKP on this point is: " (rtos dist 2 3))) (princ) ) Distance given will always be from the start point Quote
aaryan Posted June 22, 2012 Author Posted June 22, 2012 @msasu error: bad argument type: 2D/3D point: nil. @pBe I want to pick a point with a cursor (like when we use getpoint) and from your code its a small square box because of which i cannot cross check the distance.. Regards Quote
pBe Posted June 22, 2012 Posted June 22, 2012 @pBe I want to pick a point with a cursor (like when we use getpoint) and from your code its a small square box because of which i cannot cross check the distance.. Regards dont you see? (cadr a) is the "point" when you select the polyline and (car a) is the ename. think of it as like two for one Anyhooo (defun c:test () (setq a (car (entsel "\nSelect polyline:"))) (setq pt (getpoint "\nPick point:")) (setq dist (vlax-curve-getDistAtParam a (vlax-curve-getParamAtPoint a (vlax-curve-getClosestPointTo a pt)) )) (princ (strcat "\nKP on this point is: " (rtos dist 2 3))) (princ) ) Quote
MSasu Posted June 22, 2012 Posted June 22, 2012 @msasu error: bad argument type: 2D/3D point: nil. You are right, I have edited the code to change the name of a variable and missed one occurrence - please test the adjusted version. Sorry for inconvenience. Quote
aaryan Posted June 22, 2012 Author Posted June 22, 2012 Thanks @pBe I actually wanted you to modify your code and not me because you all are masters.. @Mircea Thanks for the favor Quote
pBe Posted June 22, 2012 Posted June 22, 2012 ThanksI actually wanted you to modify your code and not me because you all are masters.. Master I'm not, but thats nice of you to say, you are too kind But you know what? its all you Aaryan.. we're just here to assist and point you in the right direction. Cheers Quote
aaryan Posted June 22, 2012 Author Posted June 22, 2012 Thank You So much Mircea and pBe.. I've checked the code and its working perfectly even for the points selected outside of polyline, but if i pick a point (not on polyline) i am not getting the perpendicular distance. Can you check it please. Quote
pBe Posted June 22, 2012 Posted June 22, 2012 If the user did pick a poitn outisde the pline. it will give you intead the distance between the pick point and perpendicular to polyline? is that correct? (defun c:test3 () (setq a (car (entsel "\nSelect polyline:"))) (setq pt (getpoint "\nPick point:")) (setq dist (if (vlax-curve-getDistAtPoint a pt) (vlax-curve-getDistAtParam a (vlax-curve-getParamAtPoint a pt)) (distance (vlax-curve-getClosestPointTo a pt) pt))) (princ (strcat "\nKP on this point is: " (rtos dist 2 3))) (princ) ) Quote
aaryan Posted June 22, 2012 Author Posted June 22, 2012 Not only the distance between a point picked and a point perpendicular to polyline but also the KP from a point which is perpendicular to polyline. Like (princ (strcat "\nKp on this point is:" "xyz" "and offset from route is:abc")) and offset could be positive and negative that means if my point picked is on right side it would be positive offset and if it is on left side then it would be negative. Quote
MSasu Posted June 22, 2012 Posted June 22, 2012 I think that you will get that result by combining the code examples given by pBe and me - it will be a good exercise for you. Quote
pBe Posted June 22, 2012 Posted June 22, 2012 I think that you will get that result by combining the code examples given by pBe and me - it will be a good exercise for you. Thats not a bad idea. I concur. Go for it Aaryan. I need an aspirin Quote
aaryan Posted June 22, 2012 Author Posted June 22, 2012 OK this will be my work... anyways my problem is solved now. I appreciate both of YOUR WORK and HELP for me. I will come again with another question and another topic. Thanks and Best Regards Aaryan. Quote
pBe Posted June 22, 2012 Posted June 22, 2012 OK this will be my work...anyways my problem is solved now. Thanks and Best Regards Aaryan. If you dont mind, share youir code here when you're done Aaryan. Keep on coding Quote
aaryan Posted June 22, 2012 Author Posted June 22, 2012 I will definitely share here pBe. Regards Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.