Message 1 of 15
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I try to write a lisp to create a closed polygon outside 4 endpoints of any 2 lines or polylines but it didn't work.
Attached is a screenshot and sample CAD file.
There are somthing wrong?
I found a similar Lee Mac autolisp but it doesn't work in my case
https://www.lee-mac.com/outlineobjects.html
Thanks for all the consideration.
(defun c:OuterPolygon (/ lines p1 p2 p3 p4 poly)
(setq lines (ssget '((0 . "LINE"))))
(if (= (sslength lines) 2)
(progn
(setq line1 (vlax-ename->vla-object (ssname lines 0)))
(setq line2 (vlax-ename->vla-object (ssname lines 1)))
(setq p1 (vlax-curve-getstartpoint line1))
(setq p2 (vlax-curve-getendpoint line1))
(setq p3 (vlax-curve-getstartpoint line2))
(setq p4 (vlax-curve-getendpoint line2))
;; Calculate the intersection point
(setq intpt (vlax-curve-getclosestpointto line1 (vlax-curve-getclosestpointto line2 p1)))
;; Calculate the distance between the intersection point and the start/end points of line1
(setq dist1 (distance intpt p1))
(setq dist2 (distance intpt p2))
;; Calculate the angle of line1
(setq ang1 (angle p1 p2))
;; Calculate the new points outside of line1
(setq newp1 (polar intpt (+ ang1 (/ pi 2.0)) (+ (abs dist1) 10.0)))
(setq newp2 (polar intpt (+ ang1 (/ pi 2.0)) (+ (abs dist2) 10.0)))
;; Create a closed polygon
(setq poly (vla-add (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-vla-object->variant (list p1 newp1 newp2 p2 p3 p4 p1))))
(vla-update poly)
(princ "\nOuter polygon created.")
)
(princ "\nPlease select exactly 2 lines.")
)
(princ)
)
Solved! Go to Solution.