Jump to content

Lisp for delete duplicate 3D Solids


pizarro

Recommended Posts

When there aren't many elements, it's fine, but when you have a large number of overlapping elements and you don't know what they are, the situation is complicated.

Link to comment
Share on other sites

6 hours ago, Dadgad said:

I'm not sure, but Overkill might do it?   :beard:

 

Unfortunately I think overkill only works on 2D objects.

I think you would have to

  • make  a selection set of all solids
  • compare them to each other by volume and geo center point
  • if their is a match delete one

 

--edit

Could have false positive. so adding other tests would be better.

Edited by mhupp
Link to comment
Share on other sites

1 hour ago, mhupp said:

 

Unfortunately I think overkill only works on 2D objects.

I think you would have to

  • make  a selection set of all solids
  • compare them to each other by volume and geo center point
  • if their is a match delete one

 

--edit

Could have false positive. so adding other tests would be better.

Agree ... here is a quick one. Definitely test it as it can be fooled by solids with 'equal' volume at different locations.  Changed algorithm to be more reliable albeit slower.

(defun c:foo (/ a b o r s)
  (cond	((setq s (ssget "_X" '((0 . "3DSOLID"))))
	 (foreach e (mapcar 'cadr (ssnamex s))
	   (setq r
		  (cons	(list (vla-get-volume (setq o (vlax-ename->vla-object e))) (vlax-get o 'centroid) e)
			r
		  )
	   )
	 )
	 (setq r (vl-sort r '(lambda (r j) (< (car r) (car j)))))
	 (while	(setq a (car r))
	   (setq r (cdr r))
	   ;; Slower but more reliable
	   (setq b (vl-remove-if-not
		     '(lambda (x) (and (equal (car a) (car x) 1e-4) (equal (cadr a) (cadr x) 1e-4)))
		     r
		   )
	   )
	   (foreach x b (entdel (last x)) (setq r (vl-remove x r)))
;;;       (while (and (setq b (car r)) (equal (car a) (car b) 1e-4) (equal (cadr a) (cadr b) 1e-4))
;;;	 (entdel (last b))
;;;	 (setq r (cdr r))
;;;       )
	 )
	)
  )
  (princ)
)

 

Edited by ronjonp
  • Like 1
Link to comment
Share on other sites

  • 1 month later...
On 9/15/2022 at 7:47 PM, ronjonp said:

Agree ... here is a quick one. Definitely test it as it can be fooled by solids with 'equal' volume at different locations.  Changed algorithm to be more reliable albeit slower.

(defun c:foo (/ a b o r s)
  (cond	((setq s (ssget "_X" '((0 . "3DSOLID"))))
	 (foreach e (mapcar 'cadr (ssnamex s))
	   (setq r
		  (cons	(list (vla-get-volume (setq o (vlax-ename->vla-object e))) (vlax-get o 'centroid) e)
			r
		  )
	   )
	 )
	 (setq r (vl-sort r '(lambda (r j) (< (car r) (car j)))))
	 (while	(setq a (car r))
	   (setq r (cdr r))
	   ;; Slower but more reliable
	   (setq b (vl-remove-if-not
		     '(lambda (x) (and (equal (car a) (car x) 1e-4) (equal (cadr a) (cadr x) 1e-4)))
		     r
		   )
	   )
	   (foreach x b (entdel (last x)) (setq r (vl-remove x r)))
;;;       (while (and (setq b (car r)) (equal (car a) (car b) 1e-4) (equal (cadr a) (cadr b) 1e-4))
;;;	 (entdel (last b))
;;;	 (setq r (cdr r))
;;;       )
	 )
	)
  )
  (princ)
)

 

How can i move the duplicate object in to new layer instead of deleting??

Link to comment
Share on other sites

10 minutes ago, rax said:

Can you bit adjust the lisp to delete duplicate object into a new layer instead of deleting??

;; Change this
(foreach x b (entdel (last x)) (setq r (vl-remove x r)))
;; to this
(foreach x b (append (entget (last x)) '((8 . "Duplicate"))) (setq r (vl-remove x r)))

 

  • Like 2
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...