Grade in % and 1 in XXX based on 3 text Values

Grade in % and 1 in XXX based on 3 text Values

Anonymous
Not applicable
1,200 Views
5 Replies
Message 1 of 6

Grade in % and 1 in XXX based on 3 text Values

Anonymous
Not applicable

Hey guys,

 

Wondering if anyone has a lisp that will calculate the grade in both % and 1 in XXX based on values contained in 3 text. Example, Text A (a level) = 10, Text B (a level) = 5, Text C (a distance) = 50. This would Output "1 in 10, 10.0%"

 

% = (A-B)/C*100

1in = C/(A-B)

 

I understand the maths is simple, but I have no idea how to do this in a lisp.

 

Basically we need to continually update a long section with as constructed information, we are provided the upstream and downstream invert levels and a length of pipe as text format. We need to output the grade of each section in both % and 1 in XXX formats as new piece of text that is inserted at mouse click.

0 Likes
Accepted solutions (1)
1,201 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

... a lisp that will calculate the grade in both % and 1 in XXX based on values contained in 3 text. …. Output "1 in 10, 10.0%"….

% = (A-B)/C*100

1in = C/(A-B)

…. output the grade of each section in both % and 1 in XXX formats as new piece of text that is inserted at mouse click.


 

In very simplest terms, and minimally tested, try this:

(defun C:SLOPETEXT (/ A B C delta pct 1in)
  (setq
    A (distof (cdr (assoc 1 (entget (car (entsel "\nSelect Text for elevation at one end: "))))))
    B (distof (cdr (assoc 1 (entget (car (entsel "\nSelect Text for elevation at other end: "))))))
    C (distof (cdr (assoc 1 (entget (car (entsel "\nSelect Text for horizontal distance between: "))))))
    pct (* (/ (setq delta (abs (- A B))) C) 100)
    1in (/ C delta)
  ); setq
  (command "_.text" pause "" ""
    (strcat "1 in " (rtos 1in 2 1) ", " (rtos pct 2 1) "%")
  ); command
  (princ)
); defun

That assumes the Text pieces are purely numerical-content, that you don't miss in picking any of them, that the current Text Style is appropriate for the purpose and is not of fixed height, and that the current Text height and justification are appropriate for the purpose.  If any of those conditions may differ, it wouldn't be hard to account for them -- verify appropriate selections, pre-set a Text Style [and a Layer, or use the Layer of one of the selected pieces], specify a justification, etc., as well as other typical enhancements [error handling, etc.].

Kent Cooper, AIA
0 Likes
Message 3 of 6

Anonymous
Not applicable

This is a good start, however the calc for the "1 in" isn't correct, and it errors after clicking for the text placement.

0 Likes
Message 4 of 6

dbhunia
Advisor
Advisor

I am not getting any error by this code.......

 

Post a sample drawing ..... & what error you are getting?

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 6

Anonymous
Not applicable

Thanks, there was some random override on the 1 drawing I was trying it on.

Tried it on others and it worked perfectly.

 

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Thanks, there was some random override on the 1 drawing I was trying it on.

Tried it on others and it worked perfectly.


 

In case the "random override" in the one drawing was that the current Text Style had a fixed height [assumed not to be the case in the code], here's another approach that avoids having to account for that possibility, and also any question of current Style or Layer.  It uses COPY with one of the selected Text objects, overrides its text content, and starts a MOVE command that it leaves you in, with which you can place it, seeing it in final form for drag-&-drop  placement.  That's an improvement over the other, where you had to specify the insertion point "blind," and might often have wanted to Move it after it was drawn and its size became apparent.

(defun C:SLOPETEXT (/ A B C txt delta pct 1in tdata)
  (setq
    A (distof (cdr (assoc 1 (entget (car (entsel "\nSelect Text for elevation at one end: "))))))
    B (distof (cdr (assoc 1 (entget (car (entsel "\nSelect Text for elevation at other end: "))))))
    C (distof (cdr (assoc 1 (entget (setq txt (car (entsel "\nSelect Text for horizontal distance between: ")))))))
    pct (* (/ (setq delta (abs (- A B))) C) 100)
    1in (/ C delta)
  ); setq
  (command "_.copy" txt "" "0,0" "")
  (setq tdata (entget (entlast)))
  (entmod
    (subst
      (cons 1 (strcat "1 in " (rtos 1in 2 1) ", " (rtos pct 2 1) "%"))
      (assoc 1 tdata)
      tdata
    ); subst
  ); entmod
  (command "_.move" "_last" "" (cdr (assoc 10 (entget (entlast)))))
); defun
Kent Cooper, AIA
0 Likes