Temy Posted December 23, 2019 Posted December 23, 2019 My job all day is to measure the diameter of a circle and then look at the board and assign it a parameter. Look up the table so hard, it's so boring, guys. Can anyone help me write a Lisp but instead of measuring the diameter and dimensions, always include the parameters in the table for me, please! I have attached the file. thank you very much I wish you health and happiness! Furanji.dwg Quote
Emmanuel Delay Posted December 23, 2019 Posted December 23, 2019 Happy with this? What to do: - You draw the blue diameter dimension objects (they will display the diameter) - command CDL (for Convert Dimensions Lookuptable) - select a circle - select a diameter dimension objects -> the routine will read the radius of the circle, lookup the code in the table, if it finds it it will put that code as the text override of the dim I put it in a while loop. Press escape to exit Check the data of the lookuptable and correct/extend if needed. (setq lookuptable (list (list 75 "5K-10A") (list 80 "5K-15A") (list 85 "5K-20A") (list 95 "5K-25A") (list 115 "5K-32A") (list 120 "5K-40A") (list 130 "5K-50A") (list 155 "5K-65A") (list 180 "5K-80A") (list 190 "5K-90A") (list 200 "5K-100A") (list 235 "5K-125A") (list 265 "5K-150A") (list 300 "5K-175A") (list 345 "5K-225A") (list 385 "5K-250A") (list 430 "5K-300A") (list 480 "5K-350A") ) ) (defun textOverrideDim (dim txt / ) (entmod (subst (cons 1 txt) (assoc 1 (entget dim)) (entget dim)) ) ) ;; test of textOverrideDim (defun c:test (/) (textOverrideDim (car (entsel)) "Hello") ) ;;;;;;;;;;;;; (defun searchInLookupTable (rad / a b c res) (foreach a lookuptable (setq b (atoi (rtos rad 2 0))) (setq c (nth 0 a)) (if (= c b) (setq res (nth 1 a)) ) ) res ) ;; Convert Dimensions Lookuptable (defun c:cdl ( / circle dim rad diameter code) (while T (setq code nil) ;; select circle (setq circle (car (entsel "\nSelect Circle: "))) ;; select Dim (setq dim (car (entsel "\nSelect Dim: "))) ;; read diameter (setq rad (cdr (assoc 40 (entget circle)))) ;; lookup 2X radius, code returned (setq code (searchInLookupTable (* rad 2.0))) (if code (textOverrideDim dim code) ) ) ) 1 Quote
devitg Posted December 23, 2019 Posted December 23, 2019 First , make the list as doted pair , so you can get the value by ASSOC . (setq doted-pair-table (list (cons 75 "5K-10A") (cons 80 "5K-15A") (cons 85 "5K-20A") (cons 95 "5K-25A") (cons 115 "5K-32A") (cons 120 "5K-40A") (cons 130 "5K-50A") (cons 155 "5K-65A") (cons 180 "5K-80A") (cons 190 "5K-90A") (cons 200 "5K-100A") (cons 235 "5K-125A") (cons 265 "5K-150A") (cons 300 "5K-175A") (cons 345 "5K-225A") (cons 385 "5K-250A") (cons 430 "5K-300A") (cons 480 "5K-350A") ) ) (setq text (cdr (assoc 235 doted-pair-table))) ;; it give "5K-125A" 1 Quote
devitg Posted December 23, 2019 Posted December 23, 2019 First step by a new way (defun textOverrideDim (dim txt / ) (entmod (subst (cons 1 txt) (assoc 1 (entget dim)) (entget dim)) ) ) ;; test of textOverrideDim (defun c:test (/) (textOverrideDim (car (entsel)) "Hello") ) ;;;;;;;;;;;;; (defun searchInLookupTable (rad / a b c res) (foreach a lookuptable (setq b (atoi (rtos rad 2 0))) (setq c (nth 0 a)) (if (= c b) (setq res (nth 1 a)) ) ) res ) ;; Convert Dimensions Lookuptable (defun c:cdl ( / circle dim rad diameter code) (while T (setq code nil) ;; select circle (setq circle (car (entsel "\nSelect Circle: "))) ;; select Dim (setq dim (car (entsel "\nSelect Dim: "))) ;; read diameter (setq rad (cdr (assoc 40 (entget circle)))) ;; lookup 2X radius, code returned (setq code (searchInLookupTable (* rad 2.0))) (if code (textOverrideDim dim code) ) ) ) 1 Quote
BIGAL Posted December 24, 2019 Posted December 24, 2019 1st question to devitg why dotted pair ? (nth 1 (nth x)) & (nth 2 (nth x)) 2nd question is to temy do the dims exist or do they need to be added to the circle ? 1 Quote
Temy Posted December 24, 2019 Author Posted December 24, 2019 (edited) Thanks everyone! With this lisp I have accepted it however I want it to be more complete for me. I want to keep the diameter size and it has a tolerance of + -0.5 and it has its own layer!!! Sorry everyone, please help me again Edited December 24, 2019 by Temy Quote
devitg Posted December 24, 2019 Posted December 24, 2019 as per BIGAL question Quote 1st question to devitg why dotted pair ? (nth 1 (nth x)) & (nth 2 (nth x)) Just as it is easy to get the value by ASSOC (setq code (Cdr (assoc (fix (* rad 2.0)) doted-pair-table))) (if code (textOverrideDim dim code) ) Quote
devitg Posted December 24, 2019 Posted December 24, 2019 Quote Thanks everyone! With this lisp I have accepted it however I want it to be more complete for me. I want to keep the diameter size and it has a tolerance of + -0.5 and it has its own layer!!! Sorry everyone, please help me again Edited 7 hours ago by Temy Please upload a sample dwg . with a before and after Quote
Lee Mac Posted December 24, 2019 Posted December 24, 2019 (edited) 1 hour ago, devitg said: as per BIGAL question Just as it is easy to get the value by ASSOC (setq code (Cdr (assoc (fix (* rad 2.0)) doted-pair-table))) (if code (textOverrideDim dim code) ) Note that you can use assoc with any list of sublists, not only with an association list of dotted pairs, however, I agree that, in this particular circumstance, dotted pairs would be more appropriate as the data is stored more efficiently than a linked list. Edited December 24, 2019 by Lee Mac Quote
Lee Mac Posted December 24, 2019 Posted December 24, 2019 (edited) Assuming that the diametric dimensions already exist in the drawing, you could reduce the program to a single prompt for a selection of multiple dimensions, extracting the diameter from the dimension measurement: (defun c:diapar ( / i l m s v x ) (setq l '( ( 75.0 . "5K-10A" ) ( 80.0 . "5K-15A" ) ( 85.0 . "5K-20A" ) ( 95.0 . "5K-25A" ) (115.0 . "5K-32A" ) (120.0 . "5K-40A" ) (130.0 . "5K-50A" ) (155.0 . "5K-65A" ) (180.0 . "5K-80A" ) (190.0 . "5K-90A" ) (200.0 . "5K-100A") (235.0 . "5K-125A") (265.0 . "5K-150A") (300.0 . "5K-175A") (320.0 . "5K-200A") (345.0 . "5K-225A") (385.0 . "5K-250A") (430.0 . "5K-300A") (480.0 . "5K-350A") ) ) (if (setq s (ssget "_:L" '( (0 . "*DIMENSION") (-4 . "<OR") (070 . 003) (070 . 035) (070 . 067) (070 . 099) (070 . 131) (070 . 163) (070 . 195) (070 . 227) (-4 . "OR>") ) ) ) (repeat (setq i (sslength s)) (if (setq i (1- i) x (entget (ssname s i)) m (cdr (assoc 42 x)) v (vl-some '(lambda ( x ) (if (equal m (car x) 0.5) (cdr x))) l) ) (entmod (subst (cons 1 v) (assoc 1 x) x)) ) ) ) (princ) ) Edited December 24, 2019 by Lee Mac 1 Quote
devitg Posted December 24, 2019 Posted December 24, 2019 3 hours ago, Lee Mac said: Note that you can use assoc with any list of sublists, Hi Lee. Please clear me how to use ASSOC in this case Quote
Lee Mac Posted December 24, 2019 Posted December 24, 2019 2 hours ago, devitg said: Hi Lee. Please clear me how to use ASSOC in this case For example - _$ (setq lst1 '((1 "a" "b" "c") (2 "d" "e" "f") (3 "g" "h" "i"))) ((1 "a" "b" "c") (2 "d" "e" "f") (3 "g" "h" "i")) _$ (setq lst2 '((1 . "a") (2 . "b") (3 . "c"))) ((1 . "a") (2 . "b") (3 . "c")) _$ (assoc 1 lst1) (1 "a" "b" "c") _$ (assoc 1 lst2) (1 . "a") 1 Quote
Temy Posted December 25, 2019 Author Posted December 25, 2019 9 hours ago, devitg said: Please upload a sample dwg . with a before and after Thanks, I have uploaded the file!!! Fulanji-before and after.dwg Quote
devitg Posted December 25, 2019 Posted December 25, 2019 18 hours ago, Lee Mac said: For example - _$ (setq lst1 '((1 "a" "b" "c") (2 "d" "e" "f") (3 "g" "h" "i"))) ((1 "a" "b" "c") (2 "d" "e" "f") (3 "g" "h" "i")) _$ (setq lst2 '((1 . "a") (2 . "b") (3 . "c"))) ((1 . "a") (2 . "b") (3 . "c")) _$ (assoc 1 lst1) (1 "a" "b" "c") _$ (assoc 1 lst2) (1 . "a") Hi Lee Mac , thanks . It is clear as tap water . I learn a new thing today , I can go asleep satisfied . 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.