ToniMuniz Posted December 31, 2022 Posted December 31, 2022 Hey guys. I`m new here, so srr if I this is not the right place to put this question. Oh, and english is not my first language, so srr, about some comunication issues XD. I work with aerial electric projects, and one of most time consuming part of my work is to calc an important variable thats tell the electricians how much traction put on a cable. To do that im using excel, but I think I can use lisp to catch the cable lenght direct from the drawning and calc that on the fly. Here is the formula that I need to use: R=√a³+b³+c³.../a+b+c... On this formula "a", "b" and "c" are the lenght of cable between the structures, and R is the result. My idea is to use an lisp to get the lenght info from the text on the drawning, then ask the lisp to use this formula and return the result. Its possible to do this? Or lisps only can make some default math operation? I`ll put send a print from the drawning to illustrate how it is. Quote
devitg Posted December 31, 2022 Posted December 31, 2022 Hola Toni . por favor sube tu DWG . Hi Toni , please upload your DWG. Lisp can do any mathematical formula as it have this functions 1 Mathematics + --------- Add - --------- Subtract * --------- Multiply / --------- Divide rem ------- Remainder of integer division 1+ -------- Increment by one 1- -------- Decrement by one abs ------- Absolute fix ------- Truncates a real to an integer float ----- Converts an integer to a real gcd ------- Greatest common denominator min ------- Smallest (least) of group max ------- Largest (greatest) of group sqrt ------ Square root expt ------ Exponent exp ------- Power of e log ------- Natural log cvunit ---- Converts a value from one unit to another 2 Geometry & trigonometry distance -- Returns distance between two points angle ----- Returns angle between two points polar ----- Returns a point at a given distance and angle from a base point inters ---- Returns point at which two lines intersect sin ------- Sine cos ------- Cosine atan ------ Arctangent 1 1 Quote
devitg Posted December 31, 2022 Posted December 31, 2022 Viendo la imagen , parece que eres de Brasil , As I can see at image , it seem to be from BRASIL RON LEIGH CURSO LISP.doc Quote
ToniMuniz Posted December 31, 2022 Author Posted December 31, 2022 Tyvm Devitg, its good to know thats possible to creat this lisp. I`m from Brasil XD. I`m uploading my most recent dwg. I think ill already saw something that grab the distance form MText on the drawning, so probably the entire function can be done with one single lisp, do you think its possible? 21 R60708 D20221208 C30103 PROJETO NS 1171686289 PEDRO LEOPOLDO.dwg Quote
Steven P Posted December 31, 2022 Posted December 31, 2022 Yes, this is all possible, as Devitg says you can use all those mathematical operations. You can enter the cable length as a value in the command line or you can select the text on screen. You could even select the lengths clicking between points - however you want. I'll come back to this later (tomorrow maybe) unless anyone else gives an answer before then. Quote
BIGAL Posted January 1, 2023 Posted January 1, 2023 (edited) Provide the formula in a more readable way even hand write it and take a photo of it and post. There is some convert formula to lisp formula code out there. (setq r (sqrt (+ (expt a 3)(expt b 3)(expt c 3)))) looks like more values in formula above. Edited January 1, 2023 by BIGAL Quote
Steven P Posted January 1, 2023 Posted January 1, 2023 6 hours ago, BIGAL said: Provide the formula in a more readable way even hand write it and take a photo of it and post. There is some convert formula to lisp formula code out there. (setq r (sqrt (+ (expt a 3)(expt b 3)(expt c 3)))) looks like more values in formula above. I had the formula more like: R = √( a³+b³+c³...n³ ) / ( a+b+c+..... + n) for n number of structures (setq r (/ (sqrt (+ (expt a 3 )(expt b 3) (expt c 3)..... (expt n 3)) ) (+ a b c ..... n)) ) Quote
ToniMuniz Posted January 2, 2023 Author Posted January 2, 2023 On 12/31/2022 at 1:19 PM, Steven P said: Yes, this is all possible, as Devitg says you can use all those mathematical operations. You can enter the cable length as a value in the command line or you can select the text on screen. You could even select the lengths clicking between points - however you want. I'll come back to this later (tomorrow maybe) unless anyone else gives an answer before then. Oh thas`ts awesome, Devit is helping me to create this tool. Im very new on lisps, and this community is helping me a lot, tyvm for the support. Quote
ToniMuniz Posted January 2, 2023 Author Posted January 2, 2023 19 hours ago, BIGAL said: Provide the formula in a more readable way even hand write it and take a photo of it and post. There is some convert formula to lisp formula code out there. (setq r (sqrt (+ (expt a 3)(expt b 3)(expt c 3)))) looks like more values in formula above. Oh ill send it right now my friend, tx for the interest in helping me. Quote
ToniMuniz Posted January 2, 2023 Author Posted January 2, 2023 12 hours ago, Steven P said: I had the formula more like: R = √( a³+b³+c³...n³ ) / ( a+b+c+..... + n) for n number of structures (setq r (/ (sqrt (+ (expt a 3 )(expt b 3) (expt c 3)..... (expt n 3)) ) (+ a b c ..... n)) ) You got it my friend, tyvm for the structure suggest, ill try it. Quote
mhupp Posted January 2, 2023 Posted January 2, 2023 (edited) Convert formula's into lisp math. (str2prefix "(a^3 + b^3 + c^3) / (a + b + c)") (/ (+ (+ (EXPT A 3) (EXPT B 3)) (EXPT C 3)) (+ (+ A B) C)) add a sqrt (sqrt (/ (+ (+ (EXPT A 3) (EXPT B 3)) (EXPT C 3)) (+ (+ A B) C))) ;Original code from: http://www.lispology.com/show?JIH by: johnsondavies ;Infix notation Converter and Calculator ; Supports: + - * / ^ ( ) ;(str2prefix "B*8-5/2^(2 PI)") -> (- (* B 8) (/ 5 (EXPT 2 (* 2 PI)))) ;(setq B 4.6) ;(calculate "B*8-5/2^(2 PI)") -> 36.7358 ;(eval (infix-prefix '(10 - 3 - 2 - 1))) -> 4 ;(infix-prefix '(10 - 3 - 2 - 1)) -> (- (- (- 10 3) 2) 1) ;It also handles unary - and +, and implicit multiplication: ; (infix-prefix '(- 2 a + b)) -> (+ (* (- 2) A) B) (defun str2prefix (str / i cache) (setq i 1 cache "(") (repeat (strlen str) (setq char (substr str i 1)) (if (member char '( "+" "-" "*" "/" "(" ")" "^" "%")) (setq cache (strcat cache " " char " ")) (setq cache (strcat cache char)) ) (setq i (1+ i)) ) (setq cache (strcat cache ")")) (infix-prefix (read cache)) ) (defun calculate (str) (eval (str2prefix str))) (setq *binary-operators* '((+ 1 +) (- 1 -) (* 2 *) (/ 2 /) (^ 3 expt))) ;removed (x 2 *) to avoid accidents (setq *unary-operators* '((+ 4 +) (- 4 -))) (defun weight (c) (cadr (assoc c *binary-operators*))) (defun binary-opcode (c) (caddr (assoc c *binary-operators*))) (defun unary-opcode (c) (caddr (assoc c *unary-operators*))) (defun infix-prefix (ae) (cond ((atom ae) ae) (t (inf-aux ae nil nil)) ) ) (defun inf-aux (ae operators operands) (cond ;; Unary operator ((and (atom (car ae)) (assoc (car ae) *unary-operators*)) (inf-iter (cddr ae) operators (cons (list (unary-opcode (car ae)) (infix-prefix (cadr ae)) ) operands ) ) ) (t (inf-iter (cdr ae) operators (cons (infix-prefix (car ae)) operands))) ) ) (defun inf-iter (ae operators operands) (cond ((and (null ae) (null operators)) (car operands)) ;; Implicit multiplication ((and ae (or (listp (car ae)) (null (weight (car ae))) ) ) (inf-iter (cons '* ae) operators operands) ) ((and ae (or (null operators) (> (weight (car ae)) (weight (car operators))) ) ) (inf-aux (cdr ae) (cons (car ae) operators) operands) ) (t (inf-iter ae (cdr operators) (cons (list (binary-opcode (car operators)) (cadr operands) (car operands) ) (cddr operands) ) ) ) ) ) Edited January 2, 2023 by mhupp Quote
rog1n Posted January 2, 2023 Posted January 2, 2023 Try this: (defun c:calcVR(/ sum sumCubic ss i dim m) (setq sum 0 sumCubic 0 ) (setq ss (ssget '((0 . "DIMENSION")))) (repeat (setq i (sslength ss)) (setq dim (vlax-ename->vla-object (ssname ss (setq i (1- i))))) (if (/= (vlax-get dim 'textOverride) "") (setq m (atof (vlax-get dim 'textOverride))) (setq m (atof (rtos (vlax-get dim 'measurement) 2 (vlax-get dim 'TolerancePrecision)))) ) (setq sum (+ sum m) sumCubic (+ sumCubic (expt m 3)) ) ) (alert (strcat "Vão regulador: " (rtos (sqrt (/ sumCubic sum)) 2 0))) (princ) ) 1 1 1 Quote
thecocuk07 Posted January 21, 2023 Posted January 21, 2023 On 1/2/2023 at 3:40 AM, ToniMuniz said: You got it my friend, tyvm for the structure suggest, ill try it. hi what is the result? Quote
Recommended Posts
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.