Trap3d Posted June 8, 2023 Posted June 8, 2023 Hello everyone. Imagine this scenario. I selected a bunch of objects in a drawing. I want to create a code that does an offset considering the closest point of the selected objects. It is possible to create the offset polygon in a different layer also? The attached file has an example of what is pretended. Thanks in advance. LISP OFFSET.dwg Quote
ronjonp Posted June 8, 2023 Posted June 8, 2023 (edited) Give this a try. If your offset distance is smaller than your block spacing it will not complete the union. (defun c:foo (/ d l ll p1 p2 pl pl2 r s sp ur) ;; RJP » 2023-06-08 (cond ((and (setq d (getdist "\nSpecify offset distance: ")) (setq s (ssget '((0 . "INSERT") (2 . "RECTANGLE_ROUNDED_706")))) (setq sp (vlax-ename->vla-object (cdr (assoc 330 (entget (ssname s 0)))))) ) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (vla-getboundingbox (vlax-ename->vla-object e) 'll 'ur) (mapcar 'set '(p1 p2) (mapcar 'vlax-safearray->list (list ll ur))) (setq l (list (car p1) (cadr p1) (car p2) (cadr p1) (car p2) (cadr p2) (car p1) (cadr p2))) (setq pl (vlax-invoke sp 'addlightweightpolyline l)) (vlax-put pl 'closed -1) (setq r (cons (car (vlax-invoke sp 'addregion (setq pl2 (vlax-invoke pl 'offset d)))) r)) (mapcar 'vla-delete (list pl (car pl2))) ) ) ) (setq pl (car r)) (while (setq r (cdr r)) (vla-boolean pl acunion (car r))) (princ) ) (vl-load-com) Edited June 8, 2023 by ronjonp 2 Quote
Trap3d Posted June 8, 2023 Author Posted June 8, 2023 @ronjonp Thanks a lot for your code. It's literally what i needed. Quote
ronjonp Posted June 9, 2023 Posted June 9, 2023 3 hours ago, Trap3d said: @ronjonp Thanks a lot for your code. It's literally what i needed. Quote
Trap3d Posted June 17, 2023 Author Posted June 17, 2023 On 6/9/2023 at 3:58 AM, ronjonp said: Hey ron again. After using your code quite a lot of times I found 2 limitations that are required to be solved. 1 - I need the code to only draw on the outside of the elements selected. Sometimes if there is enough space, the code will draw on the inside of the elements selected. 2- Sometimes the distance between edges of the polygon drawn by the code is too short. in that case i want the lines to join and make part of the union. Use 0.5mm of distance as an example. Thanks in advance. Quote
ronjonp Posted June 18, 2023 Posted June 18, 2023 @Trap3d Post some examples and I'll take a look when I get some time. The code above was not intended to be foolproof, just a concept because there are too many scenarios. 1 Quote
Trap3d Posted June 18, 2023 Author Posted June 18, 2023 2 hours ago, ronjonp said: @Trap3d Post some examples and I'll take a look when I get some time. The code above was not intended to be foolproof, just a concept because there are too many scenarios. @ronjonp There you have an example for each scenario I mentioned. Hopefully you can understand what i need. Thanks again for your time. example.dwg Quote
ronjonp Posted June 19, 2023 Posted June 19, 2023 @Trap3d For your top example explode the region then join and remove the island. Your second scenario will need manual cleanup. In your third scenario I mentioned this shortcoming when I posted the code. Oversize your offset by X so they join, then explode, join and finally offset inward the difference. 1 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.