Jump to content

Recommended Posts

Posted

Hi,

 

I haven't posted here for a long time but I am after an AutoLISP code if possible!

 

I design gas networks using polylines on 0gas layer.

At the end of each 0gas polyline I add an 'End Cap' block. I am after a code that automatically adds the 'End Cap' blocks to the end of each polyline (not at the intersections) & rotates them to the correct orientation.

The attached CAD file shows the before and after that I am looking for.

 

Any help would be greatly appreciated!

End Cap.dwg

Posted

Give this a try:

(defun c:foo (/ _ang a ep p r s sp)
  ;; RJP » 2021-08-24
  (defun _ang (e pt / a pa)
    (if	(and (setq pa (vlax-curve-getparamatpoint e pt))
	     (setq a (angle '(0 0 0) (vlax-curve-getfirstderiv e pa)))
	)
      a
    )
  )
  (cond	((null (tblobjname "block" "End Cap")) (alert "Block 'End Cap' needed!"))
	((setq s (ssget '((0 . "LWPOLYLINE"))))
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (setq r (cons (list (setq sp (vlax-curve-getstartpoint e)) (_ang e sp)) r))
	   (setq r (cons (list (setq ep (vlax-curve-getendpoint e)) (+ pi (_ang e ep))) r))
	 )
	 (while	(setq p (car r))
	   (or (vl-some	'(lambda (x) (and (equal (car p) (car x) 1e-1) (setq a (cons x a))))
			(append a (setq r (cdr r)))
	       )
	       (entmake	(list '(0 . "INSERT")
			      '(100 . "AcDbEntity")
			      '(67 . 0)
			      '(8 . "0gas")
			      '(48 . 0.0006)
			      '(100 . "AcDbBlockReference")
			      '(2 . "End Cap")
			      (cons 10 (car p))
			      '(41 . 1.)
			      '(42 . 1.)
			      '(43 . 1.)
			      (cons 50 (cadr p))
			      '(70 . 0)
			      '(71 . 0)
			      '(44 . 0.)
			      '(45 . 0.)
			      '(210 0. 0. 1.)
			)
	       )
	   )
	 )
	)
  )
  (princ)
)

 

Posted
5 minutes ago, andy_06 said:

Wow that is brilliant, thank you!!

Glad to help 🍻 .. it has some bugs that I found but don't have time to iron them out right now.

Posted

ronjonp maybe make the entmake a defun just pass pt, layer and ang. Will run a fraction faster.

Posted

This works great thanks. One minor tweak that I would like if possible but I can do a work around if not. Would it be possible for the code to automatically add the End Caps to polylines on the '0gas' layer instead of manually selecting the polylines that you want to add them to?

Posted
6 hours ago, andy_06 said:

This works great thanks. One minor tweak that I would like if possible but I can do a work around if not. Would it be possible for the code to automatically add the End Caps to polylines on the '0gas' layer instead of manually selecting the polylines that you want to add them to?

;; Change this
(setq s (ssget '((0 . "LWPOLYLINE"))))
;; To this
(setq s (ssget '((0 . "LWPOLYLINE") (8 . "0gas"))))

 

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