Function Syntax: Slope_Ro Version: 1 Date: 07.04.2025 AI+https://forums.augi.com/showthread.php?107096-Slopes-and-angles-of-a-polyline-in-2d-autocad Description This routine defines the command SLOPE_01. It prompts the user for two points (start and end), computes the slope between them, simplifies that slope to an imperial “rise per 12 inches of run” ratio using a greatest-common-divisor reduction, computes the corresponding angle (degrees), and displays both values in an alert dialog. It also brackets the operation in an UNDO group and temporarily suppresses screen blips and command echo. User workflow 1) Run SLOPE_01. 2) Prompt: Specify the starting point: pick pt_o. 3) Prompt: Specify the ending point: pick pt_f (rubber-banded from pt_o). 4) The routine displays an alert with: - A simplified slope ratio formatted as 12 : rise (see note below). - The slope angle in degrees. 5) The routine exits and restores system variables it changed. System variable handling - CMDECHO is set to 0 at start and restored to 1 at the end. - BLIPMODE is saved to blp, set to 0 during execution, then restored to its prior value at the end. These changes reduce command-line noise and cursor “blip” marks while picking points. UNDO handling After the end point is selected, the routine executes: (command "_.undo" "_group") This starts an UNDO group. There is no explicit matching UNDO _END call in the provided code, which means the UNDO grouping may remain open longer than intended depending on AutoCAD behavior. If you want strict pairing, you would typically close with (command "_.undo" "_end") before exiting (including in cancel/error paths). How the slope is computed Given start point pt_o = (x0, y0) and end point pt_f = (x1, y1): - Raw slope is computed as: slope = abs( (y1 - y0) / (x1 - x0) ) - The run is fixed to an imperial standard of 12 inches: slope_v = 12 - The rise is computed as an integer truncation (not rounded): slope_h = fix( slope_v * slope ) This means the displayed “rise” is the floor of the true rise-per-12 value. For example, if true rise-per-12 is 3.9, it will report 3 (before simplification). Ratio simplification The routine uses the greatest common divisor to simplify slope_h and slope_v: - Computes nx = gcd(slope_h, slope_v) (guarded to 0 when slope_h=0). - While nx > 1, divides both by nx and recomputes gcd until fully reduced. Result: the ratio is reduced to lowest integer terms. Angle calculation - Uses (atan slope) to get the angle in radians relative to horizontal. - Converts radians to degrees: angle_deg = atan(slope) * 180 / pi - Displays with two decimal places using (rtos angle 2 2). Output and formatting The alert displays: - Slope_Ro: 12 : rise (based on your current concatenation order). - Angle: XX.XX degrees. Important: your variables are named slope_v (run=12) and slope_h (rise), but the alert string prints them as: (rtos slope_v ...) ":" (rtos slope_h ...) So it is printing run : rise. If your intent was the more common “rise in 12” representation (rise:12), swap the order in the alert string. Right now it reads “12:rise”. Key limitations / edge cases 1) Division by zero risk (vertical line): The code tests (zerop (cadr pt_f)), which checks the Y value of the end point—not the horizontal delta. The denominator used is (- (car pt_f) (car pt_o)). If x1 = x0 (vertical line), the division will fault. The guard should instead check (equal x1 x0 ...) or (zerop (- (car pt_f) (car pt_o))) with tolerance. 2) Integer truncation: fix truncates, so the displayed rise per 12 will systematically underreport unless the value is already an integer. If you want rounding, you’d use a rounding approach instead of fix. 3) Point cancellation paths: If the user presses ESC at either point prompt, the code simply falls through and restores vars—reasonable, but there is no explicit *error* handler; errors (e.g., vertical line division) may leave CMDECHO/BLIPMODE not restored. 4) UNDO group closure: As noted, the UNDO group is started but not explicitly ended. 5) Only reporting: The code comments mention adding symbol creation and text placement, but the current routine only computes and displays values; it does not draw any geometry or annotate the drawing. Net effect SLOPE_01 is currently a slope/angle calculator for two picked points, producing a simplified “12-inch run” slope ratio and the corresponding angle, shown via an alert dialog, while temporarily quieting command echo and blip mode.