Jump to content

2D grade lisp for output from 12D or MX


SunnyTurtle

Did you want a dimension for grade/slope  

3 members have voted

  1. 1. Did you want a dimension for grade/slope



Recommended Posts

Ever wanted a dimension for the grade of a slope. (when drawing in 2d/plan)

well i have, so i created this lisp to save time in manual calculating and creating some text.

; Grade     
;      
;  by Robert Condon   
; 13/9/12     
;      
;      
;  To use: Select two points from left to 
;  right and it will give you the 
;  grade between the points 
;      
;       
;      

(defun c:grd ()

(setq p1 (getpoint "\n1st point of Grade:"))

(setq p1X (car p1))

(setq p1Y (cadr p1))

(setq p2 (getpoint "\n2nd point of Grade:"))

(setq p2X (car p2))

(setq p2Y (cadr p2))

(setq rise (- p2Y p1Y))

(setq run (- p2X p1X))

(setq textposY (float
  (if(> (+ p1Y p2Y) 0)
    (/ (+ p1Y p2Y) 2 )
    (setq textdisp 0)
        )))

(setq textposX (float(/ (+ p1X p2X) 2 )))

(setq textpos (list textposX textposY 0.0))

(setq trot (angle p1 p2))
(if (> rise 0)
 (progn
   (setq rise1a (/ run rise)
  )
   (setq rise1 (rtos(/ run rise)
  )
     )
 )
 )
 (if (< rise 0)
 (progn
   (setq rise1a (/ run rise)
  )
   (setq rise1 (rtos(/ run rise)
  )
     )
 )
 )
(if (> run 0)
(setq grade (rtos(* 100 (/ rise run))
  )
     )
 )
 (if (< run 0)
(setq grade (rtos(* 100 (/ rise run))
  )
     )
 )

(if (>= 9.999 rise1a)
 (setq textdisp (strcat "[url="file://\\pxsa1.4286"]\\pxsa1.4286[/url];" rise1 ":1"))
 (setq textdisp (strcat "[url="file://\\pxsa1.4286"]\\pxsa1.4286[/url];" grade "%"))
 )
(if (progn (> 1 rise1a)(< 0 rise1a)
 )
(setq textdisp (strcat "[url="file://\\pxsa1.4286"]\\pxsa1.4286[/url];" "1:" (rtos(* rise1a 100)
  ) ))
      )
(if (progn (< -1 rise1a)(> 0 rise1a)
 )
(setq textdisp (strcat "[url="file://\\pxsa1.4286"]\\pxsa1.4286[/url];" "1:" (rtos(* rise1a 100)
  ) ))
      )

 (if (= rise 0)
    (progn (setq textdisp "")(princ "\nGrade is flat"))
   )

 (if (= run 0)
    (progn (setq textdisp "")(princ "\nGrade is vertical")
      )
   )

;(setq text size (getint "Text size: "))

(entmake (list
   '(0 . "MTEXT")
   '(100 . "AcDbEntity")
   '(67 . 0)
   '(410 . "Model")
   '(100 . "AcDbMText")
   (cons 10 textpos)
   '(40 . 0.5)
   '(41 . 0)
   '(71 . 
   '(72 . 5)
   (cons 1 textdisp)
   '(7 . "ISO3098B")
   '(210 0.0 0.0 1.0)
   '(11 1.0 0.0 0.0)
   '(42 . 0.833333)
   '(43 . 4.66667)
   (cons 50 trot)
   '(73 . 
   '(44 . 1.0)))
 (princ)
)

Link to comment
Share on other sites

Two comments at first glance:

  • Not sure what this "\\pxsa1.4286;" code means, please verify that seems to be parsed as link when shown (in Advanced editor there is an "Automatically parse links in text" option that you may want to disable).
  • I would like a dynamical line when select the second point as visual helper and also for compatibility with built-in commands:

(setq p2 (getpoint [color=magenta]p1[/color] "\n2nd point of Grade:"))

Link to comment
Share on other sites

  • Not sure what this "\\pxsa1.4286;" code means, please verify that seems to be parsed as link when shown (in Advanced editor there is an "Automatically parse links in text" option that you may want to disable).

this offsets the text 1.4286 from the insertion point. it is just something i inherited for a periouse lisp remove if you want.

 

 

 

 

  • I would like a dynamical line when select the second point as visual helper and also for compatibility with built-in commands:

(setq p2 (getpoint [color=magenta]p1[/color] "\n2nd point of Grade:"))

Thanks for that code i was unsure how to do that thanks

Edited by SunnyTurtle
Link to comment
Share on other sites

Civ3d has an option for slope lables if this helps pick two points.

 

Yes is does but the is for working with 2D outputs from MX or 12D

 

worked on this a bit to remove some errors i was getting

; Grade     
;      
;  by Robert Condon   
; 29/10/12    
;      
;      
;  To use: Select two points from left to 
;  right and it will give you the 
;  grade between the points 
;      
;       
;      

(defun c:grd ()
 
(setq p1 (getpoint "\n1st point of Grade:"))
 
(setq p1X (car p1))
 
(setq p1Y (cadr p1))
 
(setq p2 (getpoint p1 "\n2nd point of Grade:"))
 
(setq p2X (car p2))
 
(setq p2Y (cadr p2))
 
(setq rise (- p2Y p1Y))
 
(setq run (- p2X p1X))
 
(setq textposY (float
  (if(> (+ p1Y p2Y) 0)
    (/ (+ p1Y p2Y) 2 )
    (setq textdisp 0)
        )))
 
(setq textposX (float(/ (+ p1X p2X) 2 )))
 
(setq textpos (list textposX textposY 0.0))
 
(setq trot (angle p1 p2))
(if (> rise 0)
 (progn
   (setq rise1a (/ run rise)
  )
   (setq rise1 (rtos(/ run rise)
  )
     )
 )
 )
 (if (< rise 0)
 (progn
   (setq rise1a (/ run rise)
  )
   (setq rise1 (rtos(/ run rise)
  )
     )
 )
 )
(if (> run 0)
 (progn
(setq grade (rtos(* 100 (/ rise run))
  )
     )
(setq gradeA (* 100 (/ rise run))))
 )
 
 (if (< run 0)
(progn
(setq grade (rtos(* 100 (/ rise run))
  )
     )
(setq gradeA (* 100 (/ rise run))))
 )
 
(if (cond (< 10 gradeA)(> -10 gradeA))
 (setq textdisp (strcat "[url="file://\\pxsa1.4286"]\\pxsa1.4286[/url];" rise1 ":1"))
 )
 
(if (= nil (< 10 gradeA)(> -10 gradeA))
 (setq textdisp (strcat "[url="file://\\pxsa1.4286"]\\pxsa1.4286[/url];" grade "%"))
 )
 
(if (and(< 100 gradeA)(< 0 gradeA))
 
(setq textdisp (strcat "[url="file://\\pxsa1.4286"]\\pxsa1.4286[/url];" "1:" (rtos(* rise1a 100)
  ) ))
      )
(if (and(> -100 gradeA)(> 0 gradeA))
 
(setq textdisp (strcat "[url="file://\\pxsa1.4286"]\\pxsa1.4286[/url];" "1:" (rtos(* rise1a 100)
  ) ))
      )

 (if (= rise 0)
    (progn (setq textdisp "")(princ "ERROR\nGrade is flat"))
   )

 (if (= run 0)
    (progn (setq textdisp "")(princ "ERROR\nGrade is vertical")
      )
   )

;(setq text size (getint "Text size: "))
 
(entmake (list
   '(0 . "MTEXT")
   '(100 . "AcDbEntity")
   '(67 . 0)
   '(410 . "Model")
   '(100 . "AcDbMText")
   (cons 10 textpos)
   '(40 . 0.5)
   '(41 . 0)
   '(71 . 
   '(72 . 5)
   (cons 1 textdisp)
   '(7 . "ISO3098B")
   '(210 0.0 0.0 1.0)
   '(11 1.0 0.0 0.0)
   '(42 . 0.833333)
   '(43 . 4.66667)
   (cons 50 trot)
   '(73 . 
   '(44 . 1.0)))
 (princ)
)

Edited by SunnyTurtle
Link to comment
Share on other sites

I notticed this assigning:

(setq textposY [s][color=red](float[/color][/s]
  (if (> (+ p1Y p2Y) 0)
    (/ (+ p1Y p2Y) 2.0)
    [s][color=red](setq textdisp[/color][/s] 0.0[s][color=red])[/color][/s]
[color=red]       [s])[/s][/color]))

A good programming practice is to ensure that at least one part of a division operation is a real number (double) to avoid getting a rounded result:

(/ (+ p1Y p2Y) 2)     ;may return an integer
(/ (+ p1Y p2Y) 2.0)   ;will always return a real number

(I'm aware that the coordinates comming from GETPOINT ar real numbers)

Link to comment
Share on other sites

A good programming practice is to ensure that at least one part of a division operation is a real number (double) to avoid getting a rounded result:

(/ (+ p1Y p2Y) 2)     ;may return an integer
(/ (+ p1Y p2Y) 2.0)   ;will always return a real number

Thanks for the advice i will take that into consideration. But in this instance it does not really matter becasue it only need to be rough

Link to comment
Share on other sites

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...