sofiane Posted August 8, 2023 Posted August 8, 2023 (edited) RESOLVE !! I found a lisp in another website, thanks Hello everyone, I'm currently working on an AutoCAD project and I need help in creating an AutoLISP code. My aim is to count the number of hoses in my drawing based on their length. In my drawing, the hoses are represented by arcs. The hoses are supplied by my provider in fixed sizes: 1.2m, 1.5m, 2m, 2.5m, 3m, up to 12m. If an arc has an intermediate length, I will order a hose of the nearest greater length. For example, if an arc measures 0.8m, I will order a 1.2m hose. I'd like to create an AutoLISP code that allows me to: Select all the arcs in my drawing. Calculate the length of each arc. Compare this length with the lengths provided by my supplier. Round up to the nearest greater length. Count the number of hoses required of each length. In the end, I would like to get an output in the form of a table like this: I would appreciate any help you could provide in creating this code. I should note, I know absolutely nothing about this haha. Have a good day everyone. Edited August 8, 2023 by sofiane Quote
ReMark Posted August 8, 2023 Posted August 8, 2023 You have posted in the wrong forum. There is a forum where questions regarding lisp routines should be posted. Quote
ronjonp Posted August 8, 2023 Posted August 8, 2023 (edited) 16 hours ago, sofiane said: No one to help me? I thought you already got an answer from another forum? Here's a quick one for fun .. prints results to the command line: (defun c:foo (/ a l n r s) (cond ((setq s (ssget '((0 . "ARC")))) ;; Add lengths to this list sorted smallest to largest (setq l (vl-sort '(1.2 1.5 2.0 2.5) '<)) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (setq n (vla-get-arclength (vlax-ename->vla-object e))) (if (setq n (vl-some '(lambda (x) (if (<= n x) x)) l)) (if (setq a (assoc n r)) (setq r (subst (list n (1+ (cadr a))) a r)) (setq r (cons (list n 1) r)) ) (print "NO CABLE LENGTH FOUND!") ) ) (print (vl-sort r '(lambda (r j) (< (car r) (car j))))) ) ) (princ) ) Edited August 9, 2023 by ronjonp 5 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.