Jump to content
BrianTFC

Offset rectangle into separate lines ?

Recommended Posts

BrianTFC

Lee, I tried using the routine that you wrote but it didn't work some of the routines that i use it with, that's why i was using jsowinski routine.

Share this post


Link to post
Share on other sites
Lee Mac

You should've said - what error do you receive?

Share this post


Link to post
Share on other sites
jsowinski

BrianTFC-

One of the things that happens with using vla-explode is that it can make a copy from the original. I think that's what happened when you found lines on top of the selected rectangle. You can try and delete the rectangle by adding something like this.

 

(vl-catch-all-apply 'vla-delete (list VlaObj))

 

I placed it into your program. (see below)

 

 
(defun c:Offsetpline (/ *error* OffsetDist VlaObj sset num Ang Ptdist StartPt EndPt)
(vl-load-com)
(defun *error* (msg)
(princ)
); _end defun
(setq OffsetDist (getreal "\nEnter an offset distance: "))
(while (setq VlaObj (vlax-ename->vla-object (car (entsel "Select a Rectangle: "))))
(setq Startpt (vlax-curve-getPointAtParam VlaObj 1))
(setq Ang (+ (angle (vlax-curve-getStartPoint VlaObj)(vlax-curve-getPointAtParam VlaObj 1))(* (/ pi 180) 90)))
(setq PtDist (distance Startpt (vlax-curve-getPointAtParam VlaObj 2)))
(vlax-put-property vlaobj 'layer "Router - Green-V groove")
(vl-catch-all-apply 'vlax-invoke-method (list VlaObj 'explode))
(if (equal (polar Startpt Ang PtDist)(vlax-curve-getPointAtParam VlaObj 2) 1.0)
(vl-catch-all-apply 'vlax-invoke-method (list VlaObj 'Offset OffsetDist))
(vl-catch-all-apply 'vlax-invoke-method (list VlaObj 'Offset (- OffsetDist)))
); _end if
[color=red](vl-catch-all-apply 'vla-delete (list VlaObj))[/color]
(setq VlaObj (vlax-ename->vla-object (entlast)))
(vl-catch-all-apply 'vlax-put (list VlaObj 'Layer "Router - Blue - Cuts"))
(vl-cmdf "explode" (entlast))
(setq sset (ssget "_P"))
(setq num -1)
(repeat (sslength sset)
(setq VlaObj (vlax-ename->vla-object (ssname sset (setq num (1+ num)))))
(setq StartPt (polar (vlax-get VlaObj 'StartPoint)(vlax-get VlaObj 'Angle) OffsetDist))
(vl-catch-all-apply 'vlax-put (list VlaObj 'StartPoint StartPt))
(setq EndPt (polar (vlax-get VlaObj 'EndPoint)(- (vlax-get VlaObj 'Angle) pi) OffsetDist))
(vl-catch-all-apply 'vlax-put (list VlaObj 'EndPoint EndPt))
); _end repeat
); _end while
(princ)
); _end defun

 

Otherwise, since you want to explode the selected rectangle I took another shot at writing the program. I cleaned it up a little. I also put in the layer names you used in your code. I guessed at the order you placed them in. Give it a try and let me know if that works for you. Thanks.

 

 
(defun c:offsetpline (/ *error* OffsetDist VlaObj)
(vl-load-com)
(defun *error* (msg)
(princ)
); _end defun
(setq OffsetDist (getreal "\nEnter an offset distance: "))
(while (setq VlaObj (vlax-ename->vla-object (car (entsel "\nSelect a Rectangle: "))))
(vl-catch-all-apply 'vlax-put (list VlaObj 'Layer "Router - Green-V groove"))
(setq Startpt (vlax-curve-getPointAtParam VlaObj 1))
(setq Ang (+ (angle (vlax-curve-getStartPoint VlaObj)(vlax-curve-getPointAtParam VlaObj 1))(* (/ pi 180) 90)))
(setq PtDist (distance Startpt (vlax-curve-getPointAtParam VlaObj 2)))
(if (equal (polar Startpt Ang PtDist)(vlax-curve-getPointAtParam VlaObj 2) 1.0)
(foreach Obj (vl-catch-all-apply 'vlax-invoke (list VlaObj 'explode))
 (vl-catch-all-apply 'vla-offset (list Obj (- OffsetDist)))
 (vl-catch-all-apply 'vlax-put (list (vlax-ename->vla-object (entlast)) 'Layer "Router - Blue - Cuts"))
); _end foreach
(foreach Obj (vl-catch-all-apply 'vlax-invoke (list VlaObj 'explode))
 (vl-catch-all-apply 'vla-offset (list Obj OffsetDist))
 (vl-catch-all-apply 'vlax-put (list (vlax-ename->vla-object (entlast)) 'Layer "Router - Blue - Cuts"))
); _end foreach
); _end if
(vl-catch-all-apply 'vla-delete (list VlaObj))
); _end while
); _end defun

 

jsowinski

Share this post


Link to post
Share on other sites
BrianTFC

That works good...on ? is there a way to make so i can select multiple rectangles at once?

Share this post


Link to post
Share on other sites
jsowinski

Give this a try. Just hit enter when you're done selecting rectangles.

 

 
(defun c:offsetpline (/ *error* OffsetDist num Rset VlaObj)
(vl-load-com)
(defun *error* (msg)
(princ)
); _end defun
(setq OffsetDist (getreal "\nEnter an offset distance: "))
(princ "\nSelect the rectangle(s) you want to offset: ")
(setq num -1)
(if (setq Rset (ssget '((0 . "LWPOLYLINE"))))
(repeat (sslength Rset)
 (setq VlaObj (vlax-ename->vla-object (ssname Rset (setq num (1+ num)))))
 (vl-catch-all-apply 'vlax-put (list VlaObj 'Layer "Router - Green-V groove"))
 (setq Startpt (vlax-curve-getPointAtParam VlaObj 1))
 (setq Ang (+ (angle (vlax-curve-getStartPoint VlaObj)(vlax-curve-getPointAtParam VlaObj 1))(* (/ pi 180) 90)))
 (setq PtDist (distance Startpt (vlax-curve-getPointAtParam VlaObj 2)))
 (if (equal (polar Startpt Ang PtDist)(vlax-curve-getPointAtParam VlaObj 2) 1.0)
  (foreach Obj (vl-catch-all-apply 'vlax-invoke (list VlaObj 'explode))
   (vl-catch-all-apply 'vla-offset (list Obj (- OffsetDist)))
   (vl-catch-all-apply 'vlax-put (list (vlax-ename->vla-object (entlast)) 'Layer "Router - Blue - Cuts"))
  ); _end foreach
  (foreach Obj (vl-catch-all-apply 'vlax-invoke (list VlaObj 'explode))
   (vl-catch-all-apply 'vla-offset (list Obj OffsetDist))
   (vl-catch-all-apply 'vlax-put (list (vlax-ename->vla-object (entlast)) 'Layer "Router - Blue - Cuts"))
  ); _end foreach
 ); _end if
 (vl-catch-all-apply 'vla-delete (list VlaObj))
); _end repeat
); _end if
(princ)
); _end defun

Share this post


Link to post
Share on other sites
BrianTFC

That worked Great thanks.....:D

Share this post


Link to post
Share on other sites
jsowinski

You're welcome.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×