Author Topic: help to change a slope lisp  (Read 1099 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
help to change a slope lisp
« on: January 17, 2022, 05:27:59 PM »
Hi. i want to do two changes in this slope lisp code

1) The angle for the insert text is not correct. The problem is tham my template use grads .I upload my unit settigs

2) This code is created to give all the time the result as 1: 1.50 or 1:0.67 ..... 1:xxxx. I believe that is not the correct way . Some time the slope  is 2:3 (not 1:0.67)  or 3:2 (not 1:1.50) . Perhaps must be  3:5 or 5:2. The question is that ... Is any way to calculate the slope in more correct way


Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2. (setvar "OSMODE" 35)
  3. (setq sl1 (getpoint "\nPick first point: "))
  4. (setq sl2 (getpoint "\nPick second point: "))
  5. (setq sl1x (car sl1))
  6. (setq sl1y (cadr sl1))
  7. (setq sl2x (car sl2))
  8. (setq sl2y (cadr sl2))
  9. (setq slopl (abs (/ (- sl1x sl2x) (- sl1y sl2y))))
  10. (setq slopl (strcat "1 : "(rtos slopl 2 2)))
  11. (setvar "OSMODE" 0)
  12. (setq texl (getpoint "\n Specify text insertion point: "))
  13. (setq texangl (* (/ 180 pi) (atan (/ (- sl1y sl2y) (- sl1x sl2x)))))
  14. (command "style" "arial" "arial.ttf" 0 "" "" "" "" "")
  15. (command "text" "s" "arial" "c" texl 0.5 texangl slopl)
  16. (command "osmode" 35)
  17. )
  18.  

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: help to change a slope lisp
« Reply #1 on: January 17, 2022, 08:34:15 PM »
You can set the units to say radians whilst running the lisp then reset at end back to Grads, AUNITS.

If you can work out how 1:0.67 = 2:3 using a calculator then can be programmed. 2/3 =0.67 but what about 0.68.
A man who never made a mistake never made anything

PM

  • Guest
Re: help to change a slope lisp
« Reply #2 on: January 18, 2022, 01:36:26 AM »
Hi BIGAL. I Know that 2/3 = 0.67  but in all drawings will see the slope as 2:3 not 1:0.67 ... is more correct to see 2:3

for example in this cross section the slope is 2:1 not 1:0.50

Thanks
« Last Edit: January 18, 2022, 01:43:39 AM by PM »

PM

  • Guest
Re: help to change a slope lisp
« Reply #3 on: January 18, 2022, 01:54:13 AM »
I change the angle to rad but is not fix the problem

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.   (setq lun (getvar "LUNITS"))
  3.   (setq lup (getvar "LUPREC"))
  4.   (setq aun (getvar "AUNITS"))
  5.   (setq aup (getvar "AUPREC"))
  6.   (setq ang (getvar "ANGDIR"))
  7.   (setvar "LUNITS" 2)
  8.   (setvar "LUPREC" 3)
  9.   (setvar "AUNITS" 4); rad
  10.   (setvar "AUPREC" 4)
  11.   (setvar "ANGDIR" 1)
  12. (setvar "OSMODE" 35)
  13. (setq sl1 (getpoint "\nPick first point: "))
  14. (setq sl2 (getpoint "\nPick second point: "))
  15. (setq sl1x (car sl1))
  16. (setq sl1y (cadr sl1))
  17. (setq sl2x (car sl2))
  18. (setq sl2y (cadr sl2))
  19. (setq slopl (abs (/ (- sl1x sl2x) (- sl1y sl2y))))
  20. (setq slopl (strcat "1 : "(rtos slopl 2 2)))
  21. (setvar "OSMODE" 0)
  22. (setq texl (getpoint "\n Specify text insertion point: "))
  23. (setq texangl (* (/ 180 pi) (atan (/ (- sl1y sl2y) (- sl1x sl2x)))))
  24. (command "style" "arial" "arial.ttf" 0 "" "" "" "" "")
  25. (command "text" "s" "arial" "c" texl 0.5 texangl slopl)
  26. (command "osmode" 35)
  27.   (setvar "LUNITS" lun)
  28.   (setvar "LUPREC" lup)
  29.   (setvar "AUNITS" aun)
  30.   (setvar "AUPREC" aup)
  31.   (setvar "ANGDIR" ang)
  32. )
  33.  
  34.  
  35.  

kirby

  • Newt
  • Posts: 127
Re: help to change a slope lisp
« Reply #4 on: January 18, 2022, 03:18:49 PM »
It's best to express slopes as a ratio vs 1  e.g. X:1  or 1:X where X is a number greater than one.

Often also use 'h' and 'v' suffix to help clarify which number is which, e.g. 4h : 1v means 4 horizontal to 1 vertical

1h:0.67v
divide by smaller value 0.67 to reduce smallest number to 1.0
Also note greatest common divisor gcd(1, 0.67) = 1
 --> 1.49h:1.0v
round as required to suit your desired level of accuracy
--> 1.5h:1v (or 1.49:1  or 1.490:1, etc.)

Check:
3:2
3/2 = 1.5
--> 1.5:1


BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: help to change a slope lisp
« Reply #5 on: January 19, 2022, 12:45:48 AM »
Like Kirby compare the 2 values X : Y which one is less than 1 if so gives the multiply factor for the other value.
A man who never made a mistake never made anything