Jump to content

Create polygons at intersections


Shablab

Recommended Posts

I have two polygons. One is my corridor (see white), and my other are disturbances (see red). I'm looking for a lisp that creates polygons everywhere where there is an overlap between the two (see green hatch). I currently have a lisp that gives me the area of the intersecting hatch but it is only a single use.

 

I want to be able to click the white boundary layer and then the red intersecting layer and have it make intersecting polygons between those two. 

image.png

Link to comment
Share on other sites

2 hours ago, Lee Mac said:

Thank you Lee, the enclosed polygons is what I was looking for.  I am wondering now if there is a way to remove the other portion of the polygon that is outside of the "corridor".  What would be the best way to go about adding that to Stefan's lisp. 

I think the best bet would probably be just to use the "Maptrim" command subsequently and select the corridor.

EP - Enclosed polylines.lsp

Edited by Shablab
Link to comment
Share on other sites

Here's a simple process that does not use LISP but relies on the Booleans and regions.

1. Select all the objects and convert them to regions then select all the red regions and union them together.  Note, to simplify the selection of the red regions just select all then type R (remove) and click on the white region.

2. Use the Boolean intersect on the two regions resulting in the shapes you want.

3. Use explode twice to get the outlines of the shapes.

 

shapes.JPG.9be2454ba0d190c42c2280986625b51c.JPG

 

  • Like 1
Link to comment
Share on other sites

Based on code here this should do what you want:

(defun c:foo (/ r o n s)
  ;; RJP » 2019-04-03
  (cond	((and (setq s (ssget ":L" '((0 . "circle,ellipse,lwpolyline,spline"))))
	      (setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
	      (setq s (vl-remove-if-not '(lambda (x) (vlax-curve-isclosed x)) s))
	      (setq n (vlax-ename->vla-object (cdr (assoc 330 (entget (car s))))))
	      (setq s (vl-sort (mapcar 'vlax-ename->vla-object s)
			       '(lambda (a b) (> (vlax-curve-getarea a) (vlax-curve-getarea b)))
		      )
	      )
	 )
	 (setq r (car (vlax-invoke n 'addregion (list (car s)))))
	 (setq o (vlax-invoke n 'addregion (cdr s)))
	 (mapcar (function (lambda (x) (vla-boolean (vla-copy r) acintersection x))) o)
	 (mapcar 'vla-delete s)
	 (vla-delete r)
	)
  )
  (princ)
)
(vl-load-com)

 

Edited by ronjonp
updated code to include splines, ellipses, circles
  • Like 1
Link to comment
Share on other sites

1 hour ago, ronjonp said:

Based on code here this should do what you want:


(defun c:foo (/ r o n s)
  ;; RJP » 2019-04-03
  (cond	((and (setq s (ssget ":L" '((0 . "lwpolyline"))))
	      (setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
	      (setq n (vlax-ename->vla-object (cdr (assoc 330 (entget (car s))))))
	      (setq s (vl-sort (mapcar 'vlax-ename->vla-object s)
			       '(lambda (a b) (> (vla-get-area a) (vla-get-area b)))
		      )
	      )
	 )
	 (setq r (car (vlax-invoke n 'addregion (list (car s)))))
	 (setq o (vlax-invoke n 'addregion (cdr s)))
	 (mapcar (function (lambda (x) (vla-boolean (vla-copy r) acintersection x))) o)
	 (mapcar 'vla-delete s)
	 (vla-delete r)
	)
  )
  (princ)
)
(vl-load-com)

 

Thank you Ron, that is exactly what I was in search of.

Link to comment
Share on other sites

12 hours ago, BIGAL said:

ronjonp If you have a circle does not do anything to it. Nicely done though circle may never exist.

You are correct .. updated the code above to do a few more objects :)

 

2019-04-04_9-16-23.gif

  • Like 1
Link to comment
Share on other sites

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