|
|
Description
SDIST is an AutoLisp program with a command named SDIST, by CadToolChest, which functions within AutoCAD 2002, and later (possibly earlier). It finds the shortest distance between two 2D and 3D objects or between a 3D point and a 2D or 3D object. Open ended objects can be extended (for calculation purposes) to the shortest distance points. The distance and the coordinates of the two shortest distance points are displayed on the text screen and assigned to global AutoLisp variables. Optionally, a line can be drawn between the shortest distance points (a sphere is substituted for the line when the distance between the objects is zero).
The sub-functions of the SDIST command can be called by your AutoLisp programs (syntax shown below). They will return a data list for use by your program.
This program requires additional CadToolChest files which must be downloaded separately (see left margin).
Command Prompts:
The following are the prompts issued by the command for the object-to-object (with line) method. The Point to Object prompts are similar.
Shortest distance method/Help/Quit/Pt-to-object/<Object-to-object>:
Draw a line at the shortest distance/No<Yes>:
Enter color for shortest line/Bylayer/<Red>:
Select first object for shortest distance calculation/<exit>:
Select second object for shortest distance calculation/<reselect first>:
The shortest distance (!DIST1)=84.85281374.
Point on 1st object (!PT-10)=85.4714,-52.0807,170.0000
Point on 2nd object (!PT-20)=25.4714,7.9193,170.0000
The names shown enclosed in parenthesis are Global AutoLisp Variables (more information later in this document).
Suppoted Object Types:
Currently, the following object types are supported.
ARC
CIRCLE
LINE
LWPOLYLINE
RAY
SPLINE
XLINE
Calling the SDIST Sub-Function from other AutoLisp Programs:
SDIST contains sub-functions that can be called by other AutoLISP programs, bypassing the input prompts and looping behavior of the SDIST command. The sub-functions support all of the SDIST options, and return a 3 element list consisting of the shortest distance (a real), and a 3 element list for each of the two coordinates at the shortest distance points, for example:
(84.85281374 (85.4714 -52.0807 170.0000) (25.4714 7.9193 170.0000))
Syntax of the four callable sub-functons:
(T%SDIST-Object-2-Object-1 EN1 EN2 Extend1 Messages1 Draw1 Lyr2 Color1)
Call function T%SDIST-Object-2-Object-1 when you want to supply two line objects as arguments.
(T%SDIST-Object-2-Object--Any-Curve EN1-PT EN2-PT Extend1 Messages1 Draw1 Lyr2 Color1)
Call function T%SDIST-Object-2-Object-Any-Curve when you want to supply two supported objects as arguments (can be lines).
(T%SDIST-Object-2-Object-2 PT1a PT1b PT2a PT2b Extend1 Messages1 Draw1 Lyr1 Lyr2 Color1)
Call function T%SDIST-Object-2-Object-2 when you want to supply four 3D points as arguments.
(T%SDIST-Point-2-Object-1 PT3 EN1 Extend1 Messages1 Draw1 Lyr2 Color1)
Call function T%SDIST-Point-2-Object-1 when you want to supply one 3D point and one supported object as arguments.
Where:
Note: For greater and specific details on each function, refer to the comments for the function inside the T%SDIST.FAS file.
EN1=The entity name of the first object whose shortest distance to another line is to be found.
EN2=The entity name of the second object whose shortest distance to the first line is to be found.
EN1-PT=The entity name of, and 3D point on, the first object whose shortest distance to another object is to be found. This is the same fomat as returned by the AutoLisp ENTSEL function.
EN2-PT=The entity name of, and 3D point on, the second object whose shortest distance to another object is to be found. This is the same fomat as returned by the AutoLisp ENTSEL function.
PT1a=The 3D start point of the 1st vector.
PT1b=The 3D end point of the 1st vector.
PT2a=The 3D start point of the 2nd vector.
PT2b=The 3D end point of the 2nd vector.
PT3=The 3D point where the measurement will begin.
Extend1=If true, extend the object or vector, for calculation purposes only, in order to find the shortest distance point when the point is beyond the end of the object.
Messages1=If true, display the prompts, otherwise, do not display them.
Draw1=If true, draw a line between the shortest distance points, or a sphere if the lines physically intersect. If nil, do not create these objects.
LYR1=The name of the layer to use as the base layer when DRAW1 is true and
LYR2 begins with an asterisk (*). Optionally, supply the entity name of
the object from which to obtain the base layer name. If nil and LYR2
begins with an asterisk, the current layer will be used for the base layer.
Lyr2=The layer on which to create the objects. If it is a string whose first character is an asterisk (*), place the objects on the layer of the first selected object (or LYR1 when LYR1 is an argument), but with a suffix of the string in LYR2 (without the asterisk). If any other string, place the objects on that layer. If the layer does not exist, make it. If nil or null string, place the objects on the same layer as the first selected object.
Note: The Draw1 option must be True, or this option is ignored.
Color1=The color to assign to the new object. It can be BYLAYER, or a color number (in either string or integer format). If nil, the color will be the current AutoCAD color setting.
Note: The Draw1 option must be True, or this option is ignored.
Example 1:
(T%SDIST-Object-2-Object-1 EN1 EN2 Extend1 Messages1 Draw1 Lyr2 Color1)
(T%SDIST-Object-2-Object-1 (car (entsel)) (car (entsel)) T T T "*-Sdist" "R")
Might return (9.20358 (14.5534 20.7981 358.467) (18.0828 20.0923 349.996))
This draws a line, between the shortest distance points between two LINE objects, on a layer whose name begins with the name of the layer of the first selected LINE and suffixed with "-Sdist" and color it red. If necessary, extend the line(s) to the shortest distance points.
Example 2:
(T%SDIST-Object-2-Object-Any-Curve EN1-PT EN2-PT Extend1 Messages1 Draw1 Lyr2 Color1)
(T%SDIST-Object-2-Object-Any-Curve (entsel) (entsel) T T T "SDIST" "W")
Might return (15.9941 (-32.2574 110.504 179.526) (-26.0911 110.504 194.283))
This draws a line, between the shortest distance points between two supported objects, on laye "SDIST" and color it white. If necessary, extend the object(s) to the shortest distance points.
Example 3a:
(T%SDIST-Object-2-Object-2 PT1a PT1b PT2a PT2b Extend1 Messages1 Draw1 Lyr1 Lyr2 Color1)
(T%SDIST-Object-2-Object-2 (getpoint) (getpoint) (getpoint) (getpoint) nil T T "My-Layer" "*-01" "R")
Might return (9.20358 (-117.788 41.9985 -58.3177) (-120.226 50.868 -58.012))
This draws a line, between the shortest distance points between vectors formed by four 3D points, on a layer whose name begins with "My-Layer" and suffixed with "-01" and color it red. Do NOT extend the vectors to the shortest distance points (in this example that would not make any difference).
Example 3b:
(T%SDIST-Object-2-Object-2 PT1a PT1b PT2a PT2b Extend1 Messages1 Draw1 Lyr1 Lyr2 Color1)
(T%SDIST-Object-2-Object-2 (getpoint) (getpoint) (getpoint) (getpoint) nil T T "My-Layer" "*-01" "R")
Might return (28.2843 (68.612 -1.95399e-013 2.2501e-014) (67.1387 28.2459 3.05012e-014))
This draws a line, between the shortest distance points between vectors formed by four 3D points, on a layer whose name begins with "My-Layer" and suffixed with "-01" and color it red. Do NOT extend the vectos to the shortest distance points. Since the vectors are not to be extended, that makes PT2a the closest point to the secod vector.
Example 4:
(T%SDIST-Point-2-Object-1 PT3 EN1 Extend1 Messages1 Draw1 Lyr2 Color1)
(T%SDIST-Point-2-Object-1 (getpoint) (car (entsel)) nil nil nil nil nil)
Might return (76.9455 (-137.804 153.361 49.645) (-140.675 196.479 -14.0195))
Find the shortest shortest distance points between a 3D point and an object. Do not extend objects and do not draw a line between the shortest distance points.
GLOBAL AutoLisp VARIABLES
Three global AutoLisp variables are produced which are accessible on the AutoCAD command line or by other AutoLisp prgrams. When used at th AutoCAD command line, each must be prefixed with an exclamation mark (for example !dist1). They can be passed as arguments to other AutoCAD commands or simply listed on the text screen for reference purposes.
DIST1=The shortest distance (a real).
PT-10=The coordinate along the first object at the shortest distance point.
PT-20=The coordinate along the second object at the shortest distance point.
|