Author Topic: VLA-INTERSECTWITH Question  (Read 3735 times)

0 Members and 1 Guest are viewing this topic.

Peter Guappa

  • Guest
VLA-INTERSECTWITH Question
« on: January 22, 2013, 02:09:16 PM »
To find the intersection of a polyline and a virtual line (not in dwg), I "entmake" a temporary line , get the intersection with vla-intersectwith and "entdel" the temporary line.

Are there other/better options to do this? Because when the user presses the escape-button before the routine terminates, these temporary lines remain in the dwg.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: VLA-INTERSECTWITH Question
« Reply #1 on: January 22, 2013, 02:12:00 PM »
Are there other/better options to do this?

You could use the inters function with each segment of the polyline, however, this would only work with straight-segmented polylines.

A quick example of such a function might be:

Code - Auto/Visual Lisp: [Select]
  1. (defun _polyinters ( en p1 p2 / vl )
  2.     (setq en (entget en)
  3.           vl (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) en))
  4.     )
  5.     (vl-remove-if 'null
  6.         (mapcar '(lambda ( p3 p4 ) (inters p1 p2 p3 p4))
  7.             vl
  8.             (if (= 1 (logand 1 (cdr (assoc 70 en))))
  9.                 (append (cdr vl) (list (car vl)))
  10.                 (cdr vl)
  11.             )
  12.         )
  13.     )
  14. )

Code - Auto/Visual Lisp: [Select]
  1. (_polyinters <LWPolyline-entity> <point1> <point2>)

Because when the user presses the escape-button before the routine terminates, these temporary lines remain in the dwg.

You could easily incorporate an error handler (a redefined *error* function) to erase the temporary lines should the user press Esc. I have written a short tutorial on this topic here.
« Last Edit: January 22, 2013, 02:19:05 PM by Lee Mac »

Peter Guappa

  • Guest
Re: VLA-INTERSECTWITH Question
« Reply #2 on: January 22, 2013, 02:19:46 PM »
So, the best thing I can do is entmake the line in a layer with a unique name like "9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A"

and in the *error* do a ssget "x" on that layer, erase the selectionset and purge the layer?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: VLA-INTERSECTWITH Question
« Reply #3 on: January 22, 2013, 02:27:30 PM »
So, the best thing I can do is entmake the line in a layer with a unique name like "9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A"

and in the *error* do a ssget "x" on that layer, erase the selectionset and purge the layer?

No, just entdel the entity name in the *error* function, if it exists and is unerased.

Peter Guappa

  • Guest
Re: VLA-INTERSECTWITH Question
« Reply #4 on: January 22, 2013, 02:39:17 PM »
That would be easier   :lol:
I should get some sleep....

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: VLA-INTERSECTWITH Question
« Reply #5 on: January 23, 2013, 11:32:03 AM »
A word of Caution, if the item has been deleted the entdel will restore it to the drawing.

Consider (vlax-erased-p obj)
« Last Edit: January 23, 2013, 11:36:09 AM by CAB »
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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: VLA-INTERSECTWITH Question
« Reply #6 on: January 23, 2013, 11:52:12 AM »
A word of Caution, if the item has been deleted the entdel will restore it to the drawing.

Consider (vlax-erased-p obj)

Or (entget <entity>) for enames. :-)