Jump to content

RESOLVE Need help creating an AutoLISP code to count hoses.


Recommended Posts

Posted (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:

 

  1. Select all the arcs in my drawing.
  2. Calculate the length of each arc.
  3. Compare this length with the lengths provided by my supplier.
  4. Round up to the nearest greater length.
  5. 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:

 

image.png.50885ec49d1de96117d7669a74bd5228.png

 

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 by sofiane
  • sofiane changed the title to RESOLVE Need help creating an AutoLISP code to count hoses.
Posted

You have posted in the wrong forum.  There is a forum where questions regarding lisp routines should be posted.

Posted (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 by ronjonp
  • Like 5

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...