Jump to content

Offset rectangle into separate lines ?


BrianTFC

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • BrianTFC

    8

  • jsowinski

    6

  • Lee Mac

    4

  • ReMark

    2

Top Posters In This Topic

Posted Images

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

Link to comment
Share on other sites

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

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