andy_06 Posted August 24, 2021 Posted August 24, 2021 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 Quote
ronjonp Posted August 24, 2021 Posted August 24, 2021 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) ) Quote
andy_06 Posted August 24, 2021 Author Posted August 24, 2021 Wow that is brilliant, thank you!! Quote
ronjonp Posted August 24, 2021 Posted August 24, 2021 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. Quote
BIGAL Posted August 25, 2021 Posted August 25, 2021 ronjonp maybe make the entmake a defun just pass pt, layer and ang. Will run a fraction faster. Quote
andy_06 Posted August 26, 2021 Author Posted August 26, 2021 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? Quote
ronjonp Posted August 26, 2021 Posted August 26, 2021 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")))) 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.