Author Topic: Help finding pline endpoint nearest GetEntity selected point  (Read 311 times)

0 Members and 1 Guest are viewing this topic.

dpeisenbeisz

  • Mosquito
  • Posts: 6
Help finding pline endpoint nearest GetEntity selected point
« on: December 07, 2018, 01:49:03 PM »
I'm sure I'm not the first to ask this, but I can't seem to find an answer to this simple problem after a few hours of searching.  I have a subroutine that I use to create roadway striping, dashed lines to be specific.  It basically asks the user to input the length and width of an individual stripe and the gap between stripes.  A block is created for an individual stripe.  Then it uses GetEntity to ask the user to select a polyline that is created from the base topo that comes from our field survey.  Finally, the sub uses the SendCommand method to invoke a "measure" command that measures the selected polyline with the stripe block at the appropriate interval according to the gap and stripe lengths input by the user.

The problem I am having is the inherent limitation of the measure command whereby it does not insert a block at the start of the picked line.  Currently, after running the routine, I have to then insert the block manually at the endpoint of the polyline and then and orient it by picking points.  It would be nice if I could automate the entire thing and avoid having to insert individual stripes manually at the endpoint (startpoint) of the polyline.

I cannot find a way to pass the endpoint of the selected polyline nearest to the picked point because the point itself is usually not on the entity.  Finding the nearest vertex is also unreliable because the polylines can have numerous segments (both line and arc) and I don't want the program to insert a stripe at some intermediate vertex.  Using the first set of coordinates also doesn't work reliably because sometimes that is the other end of the polyline from where the GetEntity point was selected.

I have found a vague reference to using GetPoint, which will obey osnap settings, and then cycling through the drawing entities to find the entity that can use that point as a GetEntity selected point, but the post did not include any code and I'm not sure how to format the for each loop to find the entity that GetEntity would work on. 

Does anybody have an idea how to find the end of a polyline nearest the GetEntity pickpoint?  I guess I could just calc the distance from the point to the first and last vertex and compare them, but if there is another simpler method, I am all ears.

Thanks for any help, and if you need my code I can post it.  I don't think it will provide any insight into the problem, but if you think it will help, I will do that.

ronjonp

  • Needs a day job
  • Posts: 6908
Re: Help finding pline endpoint nearest GetEntity selected point
« Reply #1 on: December 07, 2018, 02:19:58 PM »
Not sure about VBA but perhaps this can be translated:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ e p)
  2.  (cond ((and (setq e (entsel "\nPick polyline near an end: "))
  3.      (= "LWPOLYLINE" (cdr (assoc 0 (entget (car e)))))
  4.      (setq p (vlax-curve-getclosestpointto (car e) (cadr e)))
  5. )
  6. (if (= 0 (fix (vlax-curve-getparamatpoint (setq e (car e)) p)))
  7. )
  8. )
  9.  )
  10. )

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC