Jump to content

Lisp to make cuts along a line


Recommended Posts

Posted (edited)

I need a LISP to make a number of cuts of a particular length along the selected line. 

The first cut will be at the start point of the selected line, the second cut will be at the end point of the line, and the rest of the cuts will be distributed equally along the line.

It will be better if the LISP allows multi-selection and entering the number & length of cut.

The attached picture indicates the drawing required.

Capture.JPG

Edited by Mohamed_Essam_2000
Posted

You could look at chainage LISPs to put a circle at the correct interval, and use these to trim the line?

Posted
(defun c:pp()
  (setq lines (ssget '((0 . "LINE"))) n (sslength lines))
  (setq gaps (getint "how many gaps? ") gap (getdist "\ngap length? "))
  (repeat n
    (setq line1 (ssname lines (setq n (1- n)))
	  l1 (entget line1)
	  pa (cdr (assoc 10 l1))
	  pb (cdr (assoc 11 l1))
	  lay (assoc 8 l1)
	  len (distance pa pb)
	  len1 (/ (- len (* gaps gap)) (1- gaps))
	  pd pb
	  )
    (repeat (1- gaps)
      (setq pc (mapcar '(lambda (b a c) (+ c (* (- b a) (/ gap len)))) pa pb pd))
      (setq pd (mapcar '(lambda (b a c) (+ c (* (- b a) (/ len1 len)))) pa pb pc))
      (entmake (list (cons 0 "LINE") (cons 10 pc) (cons 11 pd) lay))
      )
    (entdel line1)
    )
   (setq lines nil)
  )

@Mohamed_Essam_2000

Please post your question *only* in the public area of the Forum.

Are you sure you don't wish to learn coding?

 

  • Thanks 1
Posted

Some fun with colors :)

(defun c:ii()
  (setq lines (ssget '((0 . "LINE"))) n (sslength lines))
  (setq gaps (getint "how many gaps? ") gap (getdist "\ngap length? "))
  (repeat n
    (setq line1 (ssname lines (setq n (1- n)))
	  l1 (entget line1)
	  pa (cdr (assoc 10 l1))
	  pb (cdr (assoc 11 l1))
	  lay (assoc 8 l1)
	  len (distance pa pb)
	  len1 (/ (- len (* gaps gap)) (1- gaps))
	  pd pb cl 0
	  )
    (repeat (1- gaps)
      (setq pc (mapcar '(lambda (b a c) (+ c (* (- b a) (/ gap len)))) pa pb pd))
      (setq pd (mapcar '(lambda (b a c) (+ c (* (- b a) (/ len1 len)))) pa pb pc))
      (entmake (list (cons 0 "LINE") (cons 10 pc) (cons 11 pd) lay (cons 62 (setq cl (rem (1+ cl) 10)))))
      )
    (entdel line1)
    )
  )
  • Thanks 1
Posted (edited)

Very nice.

Thank you, bro.

But I need all the lines yellow colored.

Edited by Mohamed_Essam_2000
Posted (edited)

Your home work and good time to start learning look into DXF code 62 which is color, and a hint yellow is 2. Look at what 1+ is doing also. Just use Google "dxf code 62 color Autocad"

 

(cons 62 (setq cl (rem (1+ cl) 10)))

 

Look at entmake examples here they should give you the answer.

Edited by BIGAL
  • Thanks 1
Posted
7 minutes ago, BIGAL said:

Your home work and good time to start learning look into DXF code 62 which is color, and a hint yellow is 2. Look at what 1+ is doing also. Just use Google "dxf code 62 color Autocad"

 

(cons 62 (setq cl (rem (1+ cl) 10)))

 

Look at entmake examples here they should give you the answer.

Ok, I will try to do it.

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...