Jump to content

Recommended Posts

Posted

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

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • aaryan

    11

  • pBe

    9

  • MSasu

    5

Top Posters In This Topic

Posted

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?

Posted

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

Posted (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 by MSasu
Fixed the code
Posted

(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

Posted

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

Posted

@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

Posted

@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)
     )

Posted
@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.

Posted

Thanks

@pBe I actually wanted you to modify your code and not me because you all are masters..

 

@Mircea Thanks for the favor

Posted
@Mircea Thanks for the favor

No problem!

Posted
Thanks

I 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. :thumbsup:

 

Cheers

Posted

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.

Posted

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)
     )

Posted

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.

Posted

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.

Posted
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. :thumbsup:

Go for it Aaryan.

 

 

I need an aspirin :sick:

Posted

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.

Posted
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

Posted

I will definitely share here pBe.

 

Regards

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...