Nikon Posted April 29 Author Posted April 29 (edited) If you don't need " + " and " - " when calculating the difference, replace these lines: (cons 1 (if (> (- n1 n2) 0) (strcat "+" (rtos (- n1 n2) 2 3)) (rtos (- n1 n2) 2 3) ) ) with (cons 1 (rtos (- n1 n2) 2 2)) or replace it with (cons 1 (rtos (+ n1 n2) 2 2)) or (cons 1 (rtos (* n1 n2) 2 2)) Perhaps someone can add this to the code (getkword "\n...Whick Operation?...\n[+/-/*]<+>: ") to make it more universal? Edited April 29 by Nikon Quote
GLAVCVS Posted April 29 Posted April 29 Made in the Universe, for the Universe = UNIVERSAL (defun c:Df2Column (/ col1 col2 n1 n2 p1 p2 p3 basept dy txt1 txt2 i ent1 ent2 l1 l2 ordena op opt sg r) (defun ordena (cj1 cj2 / e l n m c) (foreach cj (list cj1 cj2) (setq l (cons (vl-sort (while (setq e (ssname cj (setq n (if n (1+ n) 0 ) ) ) ) (setq c (cons (list (caddr (assoc 10 (entget e))) e) c)) ) '(lambda (a b) (> (car a) (car b))) ) l ) c nil n nil ) ) (setq l1 (cadr l) l2 (car l) ) ) (princ "\nSelect the texts of the first column: ") (setq col1 (ssget '((0 . "TEXT,MTEXT")))) (if (not col1) (progn (princ "\nThe objects of the first column are not selected.") (exit) ) ) (princ "\nSelect the texts of the second column: ") (setq col2 (ssget '((0 . "TEXT,MTEXT")))) (if (not col2) (progn (princ "\nThe objects of the second column are not selected." ) (exit) ) ) (if (/= (sslength col1) (sslength col2)) (progn (princ "\nThe number of objects in the columns does not match." ) (exit) ) ) (ordena col1 col2) (while (not (member (setq op (strcase (getstring (strcat "\nWhat operation do you want? { +|-|*|/ } <" (if *op* *op* "+") ">: ")))) '("" "+" "-" "*" "/"))) (princ "\n** Invalid option ** Try again...") ) (if (= op "") (if *op* (setq op (eval (read *op*))) (setq *op* "+" op +) ) (setq *op* op op (eval (read op))) ) (while (not (member (setq opt (strcase (getstring "\nMeaning positive numbers? No/<Yes>: "))) '("" "Y" "N"))) (princ "\n** Invalid option ** Try again...") ) (if (/= opt "N") (setq sg T) (setq sg nil)) (setq basept (getpoint "\nSpecify the insertion point of the third column: ")) ;; Defining the step by Y between the elements of the second column (setq i 0) (repeat (length l1);(sslength col1) (setq ent1 (cadr (nth i l1))) (setq ent2 (cadr (nth i l2))) (setq txt1 (cdr (assoc 1 (entget ent1)))) (setq txt2 (cdr (assoc 1 (entget ent2)))) (setq n1 (atof txt1)) (setq n2 (atof txt2)) (if (and n1 n2) (progn (setq p3 (list (car basept) (car (nth i l2)) 0.0)) ;(+ (cadr basept) (* i dy)) 0.0)) (entmakex (list (cons 0 "TEXT") (cons 8 (cdr (assoc 8 (entget ent2)))) (cons 10 p3) (cons 40 (cdr (assoc 40 (entget ent2)))) (cons 1 (if (> (setq r (op n1 n2)) 0) (strcat (if sg "+" "") (rtos r 2 (if (= r (fix r)) 0 3))) (rtos r 2 (if (= r (fix r)) 0 3)) ) ) ) ) ) ) (setq i (1+ i)) ) (princ) ) 1 Quote
Nikon Posted April 30 Author Posted April 30 (edited) 18 hours ago, GLAVCVS said: Made in the Universe, for the Universe = UNIVERSAL Thank you so much (Muchas gracias), this is a wonderful code, but I want to change it a little. For operations "+", "*", "/" adding the "+" and "-" signs before the result is not required, for the "-" operation it is rarely required, and this addition can be removed from the code. In this code, you can select operations with backlight: ; https://www.cadtutor.net/forum/topic/97603-the-result-of-the-difference-of-two-columns-with-numbers/page/2/#comments ; Thanks to GLAVCVS 29.04.2025 / Operations "+", "-", "*", "/" for two columns + backlight (defun c:Oper2Column-light (/ col1 col2 n1 n2 p1 p2 p3 basept dy txt1 txt2 i ent1 ent2 l1 l2 ordena op *op* r) (defun ordena (cj1 cj2 / e l n m c) (foreach cj (list cj1 cj2) (setq l (cons (vl-sort (while (setq e (ssname cj (setq n (if n (1+ n) 0)))) (setq c (cons (list (caddr (assoc 10 (entget e))) e) c)) ) '(lambda (a b) (> (car a) (car b))) ) l ) c nil n nil ) ) (setq l1 (cadr l) l2 (car l) ) ) (princ "\nSelect the texts of the first column: ") (setq col1 (ssget '((0 . "TEXT,MTEXT")))) (if (not col1) (progn (princ "\nThe objects of the first column are not selected.") (exit) ) ) (princ "\nSelect the texts of the second column: ") (setq col2 (ssget '((0 . "TEXT,MTEXT")))) (if (not col2) (progn (princ "\nThe objects of the second column are not selected.") (exit) ) ) (if (/= (sslength col1) (sslength col2)) (progn (princ "\nThe number of objects in the columns does not match.") (exit) ) ) (ordena col1 col2) (initget 6 "+ - * /") (setq op (getkword "\nWhat operation do you want? [+/-/*//]<+>: ")) (or op (setq op "+")) (cond ((= op "+") (setq op '+)) ((= op "-") (setq op '-)) ((= op "*") (setq op '*)) ((= op "/") (setq op '/)) ) (setq basept (getpoint "\nSpecify the insertion point of the third column: ")) (setq i 0) (repeat (length l1) (setq ent1 (cadr (nth i l1))) (setq ent2 (cadr (nth i l2))) (setq txt1 (cdr (assoc 1 (entget ent1)))) (setq txt2 (cdr (assoc 1 (entget ent2)))) (setq n1 (atof txt1)) (setq n2 (atof txt2)) (if (and n1 n2) (progn (setq p3 (list (car basept) (car (nth i l2)) 0.0)) (entmakex (list (cons 0 "TEXT") (cons 8 (cdr (assoc 8 (entget ent2)))) (cons 10 p3) (cons 40 (cdr (assoc 40 (entget ent2)))) (cons 1 (rtos (setq r (apply op (list n1 n2))) 2 (if (= r (fix r)) 0 3))) )) ) ) (setq i (1+ i)) ) (princ) ) Edited April 30 by Nikon Quote
BIGAL Posted April 30 Posted April 30 (edited) Just a comment, there is no need to do the select columns twice, just select all, you can sort on Y then X the list of values. it will then produce a list of 2 values repeated. ; sorts on 1st two items (setq lst (vl-sort lst '(lambda (a b) (cond ((< (car a) (car b))) ((= (car a) (car b)) (< (cadr a) (cadr b))) ) ) ) ) Edited April 30 by BIGAL 1 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.