Jump to content

Recommended Posts

Posted

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

Posted (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)

2023-06-08_16-10-55.thumb.gif.29d0663ed7d46d0723d12dab0cc55c55.gif

Edited by ronjonp
  • Like 2
Posted
3 hours ago, Trap3d said:

@ronjonp

 

Thanks a lot for your code. It's literally what i needed.

 

🍻

  • 2 weeks later...
Posted
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.

 

Posted

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

  • Like 1
Posted
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

Posted

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

  • Agree 1

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