Jump to content

Recommended Posts

Posted

Hello Group,

 

It's been a long time since I posted anything on this forum.

I searched for this topic but didn't find anything to help me create it.

 

I'm trying to create a bevel symbol which will give the sloped/pitch info for a selected line.

Based off of 12" run and give the angle as well.

 

Any help would be greatly appreciated.

 

Sincerely,

Edward Borg

www.precisiondraftingllc.com

https://www.facebook.com/MiscIronDetailer/

40 Plus Years of Steel Construction Experience

 

Screenshot 2025-04-05 124652.png

Posted (edited)

A good task to start learning lisp. 

 

Select a line (entsel

Get X & Y of start and end points, work out X & Y, work out X rescaled to Y = 12 (entget (car (entsel

Ask for a point or hard code a distance away use (polar pt ang dist)& (getpoint

Draw the 3 lines (command "line"

Draw the text. (command "text"

 

Its not very hard so I would ask others to not post code, at some point learning how to do a simple lisp task is well worth while.

 

So have a go plenty here can help when you get stuck.

Edited by BIGAL
Posted

I have this for a metric system, I don't know if it would be suitable for a foot system...! But it can be a start for you.

(defun C:SLOPE ( / blp pt_o pt_f frac_prec sv_osmd e_last dxf_o slope slope_h slope_v nx sv_ortho pt_start pt_x t2_slope t1_slope pt_mid pt_text pt_int ed_1)
 (setvar "cmdecho" 0)
 (setq blp (getvar "blipmode"))
 (setvar "blipmode" 0)
 (initget 9)
 (setq pt_o (getpoint "\nSpecify the starting point: "))
 (cond
  (pt_o
   (initget 41)
   (setq pt_f (getpoint pt_o "\nChoosing the end point: "))
   (cond
    (pt_f
     (command "_.undo" "_group")
     (cond
      ((and (not (eq (getvar "USERI1") 1)) (not (eq (getvar "USERI1") 10)) (not (eq (getvar "USERI1") 100)))
       (initget "Unit Dozen Hundred")
       (setq frac_prec (getkword "\nFraction accuracy [Unit/Dozen/Hundred]<Dozen>: "))
       (if (not frac_prec) (setq frac_prec "Dozen"))
       (cond
        ((eq frac_prec "Unit") (setq slope_v 1))
        ((eq frac_prec "Dozen") (setq slope_v 10))
        ((eq frac_prec "Hundred") (setq slope_v 100))
       )
       (setvar "USERI1" slope_v)
      )
      (T (setq slope_v (getvar "USERI1")))
     )
     (setq sv_osmd (getvar "osmode"))
     (setvar "osmode" 0)
     (command "_.ray" pt_o pt_f "")
     (setq
      e_last (entlast)
      dxf_o (trans (cdr (assoc 11 (entget e_last))) 0 1 T)
     )
     (entdel e_last)
     (setq
      slope (abs (if (zerop (cadr dxf_o)) 0.0 (/ (car dxf_o) (cadr dxf_o))))
      slope_h (fix (* slope_v slope))
      nx (if (zerop slope_h) 0 (gcd slope_h slope_v))
      sv_ortho (getvar "orthomode")
     )
     (while (> nx 1)
      (setq slope_h (/ slope_h nx) slope_v (/ slope_v nx) nx (gcd slope_h slope_v)) 
     )
     (setvar "orthomode" 1)
     (setq pt_start (mapcar '/ (mapcar '+ pt_o pt_f) '(2.0 2.0 2.0)) pt_start (list (car pt_start) (cadr pt_start) 0.0))
     (initget 9)
     (setq pt_x (getpoint pt_start "\nSpecify the size of the symbol: ") pt_x (list (car pt_x) (cadr pt_x)))
     (if (equal (car pt_x) (car pt_start) 1E-12)
      (setq t2_slope (rtos slope_h 2 0) t1_slope (rtos slope_v 2 0))
      (setq t2_slope (rtos slope_v 2 0) t1_slope (rtos slope_h 2 0))
     )
     (repeat 2
      (command "_.dimordinate" pt_start "_text" t1_slope pt_x)
      (setq pt_mid (mapcar '/ (mapcar '+ pt_start pt_x) '(2.0 2.0 2.0)))
      (if (equal (car pt_x) (car pt_start) 1E-12)
       (setq pt_int (polar pt_x 0.0 (distance pt_start pt_x)))
       (setq pt_int (polar pt_x (/ pi 2.0) (distance pt_start pt_x)))
      )
      (setq
       pt_start (inters pt_o pt_f pt_x pt_int nil)
       t1_slope t2_slope
      )
      (if (null pt_start) (setq pt_start pt_x))
       (setq pt_text (polar pt_mid (angle pt_start pt_x) (getvar "dimtxt"))
      )
      (command "_aidimtextmove" "_2" (entlast) "" pt_text)
      (if (not ed_1) (setq ed_1 (entlast)))
     )
     (command "_.-group" "_create" "*" "" (entlast) ed_1 "")
     (setvar "orthomode" sv_ortho)
     (setvar "osmode" sv_osmd)
     (command "_.undo" "_end")
    )
   )
  )
 )
 (setvar "blipmode" blp)
 (setvar "cmdecho" 1)
 (prin1)
)

 

  • Like 1
Posted
  On 4/5/2025 at 11:19 PM, BIGAL said:

I would ask others to not post code, at some point learning how to do a simple lisp task is well worth while.

Expand  

Oops sorry, I was writing my post...

Posted
  On 4/5/2025 at 11:24 PM, Tsuky said:

I have this for a metric system, I don't know if it would be suitable for a foot system...! But it can be a start for you.

(defun C:SLOPE ( / blp pt_o pt_f frac_prec sv_osmd e_last dxf_o slope slope_h slope_v nx sv_ortho pt_start pt_x t2_slope t1_slope pt_mid pt_text pt_int ed_1)
 (setvar "cmdecho" 0)
 (setq blp (getvar "blipmode"))
 (setvar "blipmode" 0)
 (initget 9)
 (setq pt_o (getpoint "\nSpecify the starting point: "))
 (cond
  (pt_o
   (initget 41)
   (setq pt_f (getpoint pt_o "\nChoosing the end point: "))
   (cond
    (pt_f
     (command "_.undo" "_group")
     (cond
      ((and (not (eq (getvar "USERI1") 1)) (not (eq (getvar "USERI1") 10)) (not (eq (getvar "USERI1") 100)))
       (initget "Unit Dozen Hundred")
       (setq frac_prec (getkword "\nFraction accuracy [Unit/Dozen/Hundred]<Dozen>: "))
       (if (not frac_prec) (setq frac_prec "Dozen"))
       (cond
        ((eq frac_prec "Unit") (setq slope_v 1))
        ((eq frac_prec "Dozen") (setq slope_v 10))
        ((eq frac_prec "Hundred") (setq slope_v 100))
       )
       (setvar "USERI1" slope_v)
      )
      (T (setq slope_v (getvar "USERI1")))
     )
     (setq sv_osmd (getvar "osmode"))
     (setvar "osmode" 0)
     (command "_.ray" pt_o pt_f "")
     (setq
      e_last (entlast)
      dxf_o (trans (cdr (assoc 11 (entget e_last))) 0 1 T)
     )
     (entdel e_last)
     (setq
      slope (abs (if (zerop (cadr dxf_o)) 0.0 (/ (car dxf_o) (cadr dxf_o))))
      slope_h (fix (* slope_v slope))
      nx (if (zerop slope_h) 0 (gcd slope_h slope_v))
      sv_ortho (getvar "orthomode")
     )
     (while (> nx 1)
      (setq slope_h (/ slope_h nx) slope_v (/ slope_v nx) nx (gcd slope_h slope_v)) 
     )
     (setvar "orthomode" 1)
     (setq pt_start (mapcar '/ (mapcar '+ pt_o pt_f) '(2.0 2.0 2.0)) pt_start (list (car pt_start) (cadr pt_start) 0.0))
     (initget 9)
     (setq pt_x (getpoint pt_start "\nSpecify the size of the symbol: ") pt_x (list (car pt_x) (cadr pt_x)))
     (if (equal (car pt_x) (car pt_start) 1E-12)
      (setq t2_slope (rtos slope_h 2 0) t1_slope (rtos slope_v 2 0))
      (setq t2_slope (rtos slope_v 2 0) t1_slope (rtos slope_h 2 0))
     )
     (repeat 2
      (command "_.dimordinate" pt_start "_text" t1_slope pt_x)
      (setq pt_mid (mapcar '/ (mapcar '+ pt_start pt_x) '(2.0 2.0 2.0)))
      (if (equal (car pt_x) (car pt_start) 1E-12)
       (setq pt_int (polar pt_x 0.0 (distance pt_start pt_x)))
       (setq pt_int (polar pt_x (/ pi 2.0) (distance pt_start pt_x)))
      )
      (setq
       pt_start (inters pt_o pt_f pt_x pt_int nil)
       t1_slope t2_slope
      )
      (if (null pt_start) (setq pt_start pt_x))
       (setq pt_text (polar pt_mid (angle pt_start pt_x) (getvar "dimtxt"))
      )
      (command "_aidimtextmove" "_2" (entlast) "" pt_text)
      (if (not ed_1) (setq ed_1 (entlast)))
     )
     (command "_.-group" "_create" "*" "" (entlast) ed_1 "")
     (setvar "orthomode" sv_ortho)
     (setvar "osmode" sv_osmd)
     (command "_.undo" "_end")
    )
   )
  )
 )
 (setvar "blipmode" blp)
 (setvar "cmdecho" 1)
 (prin1)
)

 

Expand  

Hi Tsuky,

 

I tried AI to see if it can modify the code and this is what came back.

I see yours doesn't include the angle, which i would like to have as well.

How could the angle be added?

 

This AutoLISP code appears to be for drawing a slope symbol and labeling it with a ratio (like 1:10). It prompts the user for a start and end point, calculates the slope, and then draws and labels it.

To modify this code to work with imperial units, we need to consider what units are being used and how they are being represented. Based on the code, it seems the slope is calculated as a ratio without explicit unit measurements (like rise over run). The "Fraction accuracy" options (Unit, Dozen, Hundred) further suggest it's working with a unitless ratio.

Therefore, directly converting units like meters to feet isn't applicable here. The code calculates a ratio, and that ratio remains the same regardless of the underlying units used to determine the start and end points.

However, if you intend to interpret the drawn slope and its label as representing imperial units (e.g., a rise of 1 unit for every 10 units of run, where these units are now understood to be feet or inches), then the code itself doesn't need modification. The label will still be a ratio.

Here's a breakdown of why direct unit conversion isn't needed and what you should consider:

Slope as a Ratio: The core of the code calculates slope as the absolute ratio of the change in the Y-coordinate to the change in the X-coordinate ((/ (car dxf_o) (cadr dxf_o))). This ratio is unitless.

slope_h and slope_v: These variables become the numerator and denominator of the slope ratio after being multiplied by slope_v (which is based on the "Fraction accuracy") and simplified by their greatest common divisor (GCD). These are also unitless numbers in the ratio.

Labeling: The code uses rtos (real to string) to convert slope_h and slope_v into strings for the label. These strings represent the parts of the ratio.

What you might need to adjust if your intention involves specific imperial units:

User Interpretation: When you use this command after this point, you need to understand that the units you pick the start and end points in (e.g., feet or inches in your AutoCAD drawing) will be the basis for the slope ratio. If you pick points that are 1 foot apart horizontally and 0.1 feet apart vertically, the slope will be represented as a ratio (potentially simplified).

Drawing Scale: Your AutoCAD drawing scale will determine the real-world distances represented by the units you are working in. The slope ratio will be accurate regardless of the scale, but the visual representation of the slope will be affected by it.

If you did have code that explicitly dealt with measured lengths: If the original code had variables that stored lengths in metric units (e.g., length_m = 10.0), then you would need to convert those values to imperial units (e.g., length_ft = (* length_m 3.28084)). However, this specific C:SLOPE function doesn't appear to do this.

In summary, to use this C:SLOPE command in an imperial drawing:

Set your AutoCAD units to imperial (e.g., feet or inches).

Use the SLOPE command and pick your start and end points based on your desired imperial units.

The label generated will be a ratio based on the difference in the coordinates you picked, expressed as a simplified fraction (depending on the "Fraction accuracy" you choose).

No direct modification of the AutoLISP code is necessary for it to be used in an imperial drawing context, as it deals with ratios, not explicit unit measurements.

If you have other parts of your workflow or other code that do involve explicit metric measurements that you need to convert, please provide that code, and I can help you modify it.

 

Sincerely,

Edward Borg

www.precisiondraftingllc.com

https://www.facebook.com/MiscIronDetailer/

40 Plus Years of Steel Construction Experience

Posted

Plus, I would like the label to be dragged afterwards for placement with the line extension being adjustable.

So, the label will be placed outside the line (like my image) and not centered like yours does.

Posted (edited)
  On 4/5/2025 at 11:24 PM, Tsuky said:

 

Expand  

Okay I tried to modify the code with AI to base the ratio on 12 and got the following results.

This line happened to be greater than 45 degrees, so the result is greater than 12 versus swapping the base of 12 from horizontal to vertical.

Plus, it just gave me the results instead of providing a label to place.

Here is the code it gave me.


 

(defun C:SLOPE ( / blp pt_o pt_f frac_prec sv_osmd e_last dxf_o slope slope_h slope_v nx sv_ortho pt_start pt_x t2_slope t1_slope pt_mid pt_text pt_int ed_1 angle)
  ;; Turn off command echo and blip mode
  (setvar "cmdecho" 0)
  (setq blp (getvar "blipmode"))
  (setvar "blipmode" 0)

  ;; Get start point
  (setq pt_o (getpoint "\nSpecify the starting point: "))
  (cond
    (pt_o
     ;; Get end point
     (setq pt_f (getpoint pt_o "\nSpecify the ending point: "))
     (cond
       (pt_f
        (command "_.undo" "_group")
        
        ;; Set fraction precision
        (setq slope_v 12) ;; Fixed as 12-inch run for imperial standard

        ;; Get slope ratio
        (setq slope (abs (if (zerop (cadr pt_f)) 0.0 (/ (- (cadr pt_f) (cadr pt_o)) (- (car pt_f) (car pt_o)))))
              slope_h (fix (* slope_v slope))
              nx (if (zerop slope_h) 0 (gcd slope_h slope_v))
        )

        ;; Simplify the ratio using GCD
        (while (> nx 1)
          (setq slope_h (/ slope_h nx)
                slope_v (/ slope_v nx)
                nx (gcd slope_h slope_v))
        )

        ;; Calculate angle in degrees
        (setq angle (atan slope))
        (setq angle (* angle (/ 180.0 pi))) ;; Convert radians to degrees

        ;; Display slope ratio and angle
        (alert (strcat "Slope Ratio: " (rtos slope_h 2 0) ":" (rtos slope_v 2 0)
                       "\nAngle: " (rtos angle 2 2) " degrees"))

        ;; Add other functionalities, like symbol creation and text placement, here.
       )
     )
    )
  )
  ;; Restore blip mode and command echo
  (setvar "blipmode" blp)
  (setvar "cmdecho" 1)
  (prin1)
)

 

 

Screenshot 2025-04-06 110249.png

Edited by SLW210
Added Code Tags!!
Posted

Glad to see your having a go, some more hints you don't need to pick two points you can just pick a line, you can get the start and end properties.

 

(setq ent (entsel "\npick a line "))
(setq entg (entget (car ent)))
(setq startpt (cdr (assoc 10 entg)))
(setq endpt (cdr (assoc 11 entg)))
(setq ang (angle startpt endpt))

 

Ok now you have the 2 points but they are based on the drawn direction so your points may be in a reverse direction so you can do a check and this is what I use. You pick a line near  an end so this sets a direction of the 2 points.

 

(setq pt cadr ent))
(setq d1 (distance pt startpt))
(setq d2 (distance pt endpt))
(if (> d1 d2)
  (setq tmp startpt
    startpt endpt
    endpt tmp
  )
)
(setq ang (angle startpt endpt))

 

Pick a point form the endpt to get a distance away form the endpt to draw the angled line, get its end point, and work backwards from that for the other line work again using polar.

Posted

Please use Code Tags for your code in the future. (<> in the editor toolbar)

Posted

Hi Bigal,

 

Thanks for that information.

How do I apply these codes you provided?

Where should they be put in and what should be replaced?

 

Sincerely,

Edward Borg

www.precisiondraftingllc.com

https://www.facebook.com/MiscIronDetailer/

40 Plus Years of Steel Construction Experience

Posted

I have done something and it looks at the 4 quadrants, the problem I have before I go any further is I need a real dwg as I need to match text styles etc.

 

Can you please post one with before and after. Will fix dim on outside and offset from line work.

image.png.d2c4280d9e03b1982e7927227dbfd063.png

Posted

Hi Bigal,

 

Thanks for taking the time to help me with this.

I greatly appreciate it!

 

Not sure what you mean about before and after.

I have attached a rail detail with and without these bevel labels.

I see yours has the hypotenuse instead of the angle and the scale and text size seems to be off.

Can the triangle be smaller and the text be bigger and the placement of the text be slightly off the line?

Similar to how my initial image showed.

Would it be based on the current scale and text style?

 

Sincerely,

Edward Borg

www.precisiondraftingllc.com

https://www.facebook.com/MiscIronDetailer/

40 Plus Years of Steel Construction Experience

R_4(R1).dwgFetching info... R_4.dwgFetching info...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...