Intersection Functions
Here I present a set of functions which involve retrieving a list of all points of intersection between either two VLA-Objects, a Selection Set / list of VLA-Objects, or between objects found in two Selection Sets / lists of VLA-Objects.
Each of the following functions is essentially a wrapper for the Visual LISP intersectwith method; consequently, the functions will only accept objects for which this method is applicable.
Contents
Intersections
Function Syntax | (LM:intersections <ob1> <ob2> <mod>) |
Current Version | 1.0 |
Donate |
Arguments | ||
---|---|---|
Symbol | Type | Description |
ob1 , ob2 | VLA-Object | VLA-Objects for which to retrieve points of intersection |
mod | Integer | acextendoption enumeration of the intersectwith method |
Returns | ||
Type | Description | |
List | A list of all points of intersection between the two objects for the given intersection mode |
Function Description
This function will return a list of 3D WCS points of intersection between two supplied objects, or nil if the objects do not intersect under the specified intersection mode.
The function requires two VLA-Object arguments and a third acextendoption enumeration argument as required by the intersectwith method to determine the intersection mode.
The mod parameter may be one of the following symbols:
Mode | Intersection Behaviour |
---|---|
acextendnone | Do not extend either object |
acextendthisentity | Extend obj1 to meet obj2 |
acextendotherentity | Extend obj2 to meet obj1 |
acextendboth | Extend both objects |
The image below demonstrates the effect of the intersection mode parameter on the point returned by this function; in the following diagram, the object parameters supplied to the function are labelled and the point returned by the function is shown in red:
;; Intersections - Lee Mac ;; Returns a list of all points of intersection between two objects ;; for the given intersection mode. ;; ob1,ob2 - [vla] VLA-Objects ;; mod - [int] acextendoption enum of intersectwith method (defun LM:intersections ( ob1 ob2 mod / lst rtn ) (setq lst (vlax-invoke ob1 'intersectwith ob2 mod)) (repeat (/ (length lst) 3) (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn) lst (cdddr lst) ) ) (reverse rtn) )
Test Program
The following example program will prompt the user to select two objects in the drawing and will then generate AutoCAD Points at every point of intersection (if any exist) between the two selected objects.
(defun c:inter ( / obj1 obj2 ) (if (and (setq obj1 (car (entsel "\nSelect 1st Object: "))) (setq obj2 (car (entsel "\nSelect 2nd Object: "))) ) (foreach pnt (LM:intersections (vlax-ename->vla-object obj1) (vlax-ename->vla-object obj2) acextendnone) (entmake (list '(0 . "POINT") (cons 10 pnt))) ) ) (princ) ) (vl-load-com) (princ)
Intersections in Set
Function Syntax | (LM:intersectionsinset <sel>) |
Current Version | 1.0 |
Donate |
Arguments | ||
---|---|---|
Symbol | Type | Description |
sel | Selection Set | Selection Set of objects for which to return points of intersection |
Returns | ||
Type | Description | |
List | A list of all points of intersection between all objects in the Selection Set |
Function Description
This function will return a list of all points of intersection between all objects in a given Selection Set.
When called with a valid Selection Set argument, this function will iterate over every object in the set and will call the above LM:Intersections function with mode parameter set to acextendnone for every object pair combination, returning all points of intersection between all possible pairs of objects in the set.
;; Intersections in Set - Lee Mac ;; Returns a list of all points of intersection between all objects in a supplied selection set. ;; sel - [sel] Selection Set (defun LM:intersectionsinset ( sel / id1 id2 ob1 ob2 rtn ) (repeat (setq id1 (sslength sel)) (setq ob1 (vlax-ename->vla-object (ssname sel (setq id1 (1- id1))))) (repeat (setq id2 id1) (setq ob2 (vlax-ename->vla-object (ssname sel (setq id2 (1- id2)))) rtn (cons (LM:intersections ob1 ob2 acextendnone) rtn) ) ) ) (apply 'append (reverse rtn)) )
Test Program
As demonstrated by the above animation, the following example program will prompt the user for a selection of objects and will then generate AutoCAD Points at every point of intersection between all objects in the selection.
(defun c:interset ( / sel ) (if (setq sel (ssget)) (foreach pnt (LM:intersectionsinset sel) (entmake (list '(0 . "POINT") (cons 10 pnt))) ) ) (princ) ) (vl-load-com) (princ)
Intersections in Object List
Function Syntax | (LM:intersectionsinobjlist <lst>) |
Current Version | 1.0 |
Donate |
Arguments | ||
---|---|---|
Symbol | Type | Description |
lst | List | List of VLA-Objects for which to return points of intersection |
Returns | ||
Type | Description | |
List | A list of all points of intersection between all objects in the list |
Function Description
This function will return a list of all points of intersection between all objects in a list of VLA-Objects.
The function has identical behaviour to the above LM:IntersectionsInSet function, however, will accept a list of VLA-Objects as an argument in lieu of a Selection Set.
;; Intersections in Object List - Lee Mac ;; Returns a list of all points of intersection between all objects in a list of VLA-Objects. ;; lst - [lst] List of VLA-Objects (defun LM:intersectionsinobjlist ( lst / ob1 rtn ) (while (setq ob1 (car lst)) (foreach ob2 (setq lst (cdr lst)) (setq rtn (cons (LM:intersections ob1 ob2 acextendnone) rtn)) ) ) (apply 'append (reverse rtn)) )
Intersections Between Sets
Function Syntax | (LM:intersectionsbetweensets <ss1> <ss2>) |
Current Version | 1.0 |
Donate |
Arguments | ||
---|---|---|
Symbol | Type | Description |
ss1, ss2 | Selection Set | Selection Sets for which to return points of intersection |
Returns | ||
Type | Description | |
List | A list of all points of intersection between objects in each set |
Function Description
This function will return a list of all points of intersection between objects in each supplied Selection Set.
Note that this functionality differs from that exhibited by the above LM:IntersectionsInSet function in that this function will test for intersections between objects from one set and objects from another, and will not return points of intersection between objects residing within the same set.
This behaviour is illustrated by the following demonstration in which intersection points between objects in each set (green / cyan) are displayed, however, points of intersection between objects of the same set are ignored.
;; Intersections Between Sets - Lee Mac ;; Returns a list of all points of intersection between objects in two selection sets. ;; ss1,ss2 - [sel] Selection sets (defun LM:intersectionsbetweensets ( ss1 ss2 / id1 id2 ob1 ob2 rtn ) (repeat (setq id1 (sslength ss1)) (setq ob1 (vlax-ename->vla-object (ssname ss1 (setq id1 (1- id1))))) (repeat (setq id2 (sslength ss2)) (setq ob2 (vlax-ename->vla-object (ssname ss2 (setq id2 (1- id2)))) rtn (cons (LM:intersections ob1 ob2 acextendnone) rtn) ) ) ) (apply 'append (reverse rtn)) )
Test Program
As demonstrated by the above animation, the following example program will prompt the user to make two selections and will then generate AutoCAD Point at all points of intersection between the sets.
(defun c:intersets ( / ss1 ss2 ) (if (and (setq ss1 (ssget)) (setq ss2 (ssget)) ) (foreach pnt (LM:intersectionsbetweensets ss1 ss2) (entmake (list '(0 . "POINT") (cons 10 pnt))) ) ) (princ) ) (vl-load-com) (princ)
Intersections Between Object Lists
Function Syntax | (LM:intersectionsbetweenobjlists <ol1> <ol2>) |
Current Version | 1.0 |
Donate |
Arguments | ||
---|---|---|
Symbol | Type | Description |
ol1, ol2 | List | Lists of VLA-Objects for which to return points of intersection |
Returns | ||
Type | Description | |
List | A list of all points of intersection between objects in each list |
Function Description
This function has identical behaviour to the above LM:IntersectionsBetweenSets function, however, will accept two lists of VLA-Objects as arguments in place of Selection Sets.
;; Intersections Between Object Lists - Lee Mac ;; Returns a list of all points of intersection between objects in two lists of VLA-Objects. ;; ol1,ol2 - [lst] Lists of VLA-Objects (defun LM:intersectionsbetweenobjlists ( ol1 ol2 / rtn ) (foreach ob1 ol1 (foreach ob2 ol2 (setq rtn (cons (LM:intersections ob1 ob2 acextendnone) rtn)) ) ) (apply 'append (reverse rtn)) )