Short description
Purpose: Compute and report a simplified slope ratio and angle between two user-picked points Run style: Interactive two-point measurement with no drawing modifications Standard: Uses a fixed 12-unit horizontal run for imperial slope representation Output: Displays slope ratio and angle through an alert dialog only

Command:
Command: SLOPE_01 Start: User picks a start point Next: User picks an end point Action: Calculates ratio rise:run (simplified), computes angle in degrees, displays both
Description:
This routine requests two points from the user, computes the vertical and horizontal differences, converts them into a simplified rise-over-run ratio based on a constant 12-unit run, and calculates the slope angle using arctangent mathematics. The resulting slope and angle are shown in a dialog box, allowing quick field verification without producing any entities or altering the drawing. The routine cleans up after itself by restoring BLIPMODE and CMDECHO system variables.
Helper function: (if any)
• System variable handling — Disables BLIPMODE and CMDECHO temporarily for clean operation • Slope formula — Computes slope as |ΔY ÷ ΔX| with protection for division by zero • Ratio reduction — Uses repeated GCD to simplify rise and run until they cannot be reduced further • Angle calculation — Uses ATAN then converts radians to degrees • Undo grouping — Begins an UNDO group to encapsulate any future extensions
Functionalities:
• Two-point slope measurement — Uses user input for start and end points • Imperial 12-run standard — Converts slope to a rise-per-12-units format • Automatic ratio simplification — Ensures output is reduced (e.g., 12:6 → 2:1) • Angle reporting — Provides the slope angle with two decimal precision • Error-safe logic — Prevents zero-division and handles flat slopes correctly • Clean environment — Restores system variables on exit
Result:
• Displayed slope ratio — Presented as Slope_Ro: run:rise after simplification • Displayed slope angle — Angle shown in degrees with two decimals • No geometry created — Does not draw text, objects, or symbols • Useful for quick checks — Ideal for rapid field/plan slope validation • Environment restored — BLIPMODE and CMDECHO returned to original values
Images, animations etc.
Log in to download.
Log in
Log in
XAML code:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:Autodesk.Windows;assembly=AdWindows">
<src:RibbonToolTip x:Key="Slope_Ro">
<src:RibbonToolTip.ExpandedContent>
<StackPanel>
<TextBlock Background="AntiqueWhite" TextAlignment="Left">
<Bold>Function Syntax: Slope_Ro</Bold>
<LineBreak/>
<Bold>Version: 1 Date: 07.04.2025</Bold>
<LineBreak/>
<LineBreak/>
<Hyperlink>AI+https://forums.augi.com/showthread.php?107096-Slopes-and-angles-of-a-polyline-in-2d-autocad</Hyperlink>
<LineBreak/>
<Bold>Description</Bold><LineBreak/>
This routine defines the command <Run Foreground="Red">SLOPE_01</Run>. 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.<LineBreak/>
<LineBreak/>
<Bold>User workflow</Bold><LineBreak/>
1) Run <Run Foreground="Red">SLOPE_01</Run>.<LineBreak/>
2) Prompt: <Run Foreground="DarkRed">Specify the starting point:</Run> pick <Run Foreground="DarkRed">pt_o</Run>.<LineBreak/>
3) Prompt: <Run Foreground="DarkRed">Specify the ending point:</Run> pick <Run Foreground="DarkRed">pt_f</Run> (rubber-banded from pt_o).<LineBreak/>
4) The routine displays an alert with:<LineBreak/>
- A simplified slope ratio formatted as <Run Foreground="DarkRed">12 : rise</Run> (see note below).<LineBreak/>
- The slope angle in degrees.<LineBreak/>
5) The routine exits and restores system variables it changed.<LineBreak/>
<LineBreak/>
<Bold>System variable handling</Bold><LineBreak/>
- <Run Foreground="DarkRed">CMDECHO</Run> is set to 0 at start and restored to 1 at the end.<LineBreak/>
- <Run Foreground="DarkRed">BLIPMODE</Run> is saved to <Run Foreground="DarkRed">blp</Run>, set to 0 during execution, then restored to its prior value at the end.<LineBreak/>
These changes reduce command-line noise and cursor “blip” marks while picking points.<LineBreak/>
<LineBreak/>
<Bold>UNDO handling</Bold><LineBreak/>
After the end point is selected, the routine executes:<LineBreak/>
<Run Foreground="DarkRed">(command "_.undo" "_group")</Run><LineBreak/>
This starts an UNDO group. There is no explicit matching <Run Foreground="DarkRed">UNDO _END</Run> 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 <Run Foreground="DarkRed">(command "_.undo" "_end")</Run> before exiting (including in cancel/error paths).<LineBreak/>
<LineBreak/>
<Bold>How the slope is computed</Bold><LineBreak/>
Given start point <Run Foreground="DarkRed">pt_o = (x0, y0)</Run> and end point <Run Foreground="DarkRed">pt_f = (x1, y1)</Run>:<LineBreak/>
- Raw slope is computed as:<LineBreak/>
<Run Foreground="DarkRed">slope = abs( (y1 - y0) / (x1 - x0) )</Run><LineBreak/>
- The run is fixed to an imperial standard of 12 inches:<LineBreak/>
<Run Foreground="DarkRed">slope_v = 12</Run><LineBreak/>
- The rise is computed as an integer truncation (not rounded):<LineBreak/>
<Run Foreground="DarkRed">slope_h = fix( slope_v * slope )</Run><LineBreak/>
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).<LineBreak/>
<LineBreak/>
<Bold>Ratio simplification</Bold><LineBreak/>
The routine uses the greatest common divisor to simplify <Run Foreground="DarkRed">slope_h</Run> and <Run Foreground="DarkRed">slope_v</Run>:<LineBreak/>
- Computes <Run Foreground="DarkRed">nx = gcd(slope_h, slope_v)</Run> (guarded to 0 when slope_h=0).<LineBreak/>
- While nx > 1, divides both by nx and recomputes gcd until fully reduced.<LineBreak/>
Result: the ratio is reduced to lowest integer terms.<LineBreak/>
<LineBreak/>
<Bold>Angle calculation</Bold><LineBreak/>
- Uses <Run Foreground="DarkRed">(atan slope)</Run> to get the angle in radians relative to horizontal.<LineBreak/>
- Converts radians to degrees:<LineBreak/>
<Run Foreground="DarkRed">angle_deg = atan(slope) * 180 / pi</Run><LineBreak/>
- Displays with two decimal places using <Run Foreground="DarkRed">(rtos angle 2 2)</Run>.<LineBreak/>
<LineBreak/>
<Bold>Output and formatting</Bold><LineBreak/>
The alert displays:<LineBreak/>
- <Run Foreground="DarkRed">Slope_Ro: 12 : rise</Run> (based on your current concatenation order).<LineBreak/>
- <Run Foreground="DarkRed">Angle: XX.XX degrees</Run>.<LineBreak/>
<LineBreak/>
Important: your variables are named <Run Foreground="DarkRed">slope_v</Run> (run=12) and <Run Foreground="DarkRed">slope_h</Run> (rise), but the alert string prints them as:<LineBreak/>
<Run Foreground="DarkRed">(rtos slope_v ...) ":" (rtos slope_h ...)</Run><LineBreak/>
So it is printing <Run Foreground="DarkRed">run : rise</Run>. 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”.<LineBreak/>
<LineBreak/>
<Bold>Key limitations / edge cases</Bold><LineBreak/>
1) <Bold>Division by zero risk (vertical line)</Bold>: The code tests <Run Foreground="DarkRed">(zerop (cadr pt_f))</Run>, which checks the Y value of the end point—not the horizontal delta. The denominator used is <Run Foreground="DarkRed">(- (car pt_f) (car pt_o))</Run>. If <Run Foreground="DarkRed">x1 = x0</Run> (vertical line), the division will fault. The guard should instead check <Run Foreground="DarkRed">(equal x1 x0 ...)</Run> or <Run Foreground="DarkRed">(zerop (- (car pt_f) (car pt_o)))</Run> with tolerance.<LineBreak/>
2) <Bold>Integer truncation</Bold>: <Run Foreground="DarkRed">fix</Run> 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 <Run Foreground="DarkRed">fix</Run>.<LineBreak/>
3) <Bold>Point cancellation paths</Bold>: 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.<LineBreak/>
4) <Bold>UNDO group closure</Bold>: As noted, the UNDO group is started but not explicitly ended.<LineBreak/>
5) <Bold>Only reporting</Bold>: 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.<LineBreak/>
<LineBreak/>
<Bold>Net effect</Bold><LineBreak/>
<Run Foreground="Red">SLOPE_01</Run> 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.<LineBreak/>
</TextBlock>
<Grid>
<Image Source="Slope_Ro.png" Stretch="Uniform"/>
</Grid>
<Grid>
<MediaElement
Source="GIF"
Stretch="Uniform"
Visibility="Visible"/>
</Grid>
</StackPanel>
</src:RibbonToolTip.ExpandedContent>
</src:RibbonToolTip>
</ResourceDictionary>
Additional info:
Learn more:
Open Website
Share this page:
Subscribe
Login
0 Comments
Oldest
Tags: 🏷️ Autocad Lisps, 🏷️ Polyline menu
Tags: 🏷️ Autocad Lisps, 🏷️ Polyline menu
