BrianTFC Posted February 23, 2012 Author Posted February 23, 2012 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. Quote
Lee Mac Posted February 23, 2012 Posted February 23, 2012 You should've said - what error do you receive? Quote
jsowinski Posted February 24, 2012 Posted February 24, 2012 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 Quote
BrianTFC Posted February 24, 2012 Author Posted February 24, 2012 That works good...on ? is there a way to make so i can select multiple rectangles at once? Quote
jsowinski Posted February 24, 2012 Posted February 24, 2012 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 Quote
BrianTFC Posted February 24, 2012 Author Posted February 24, 2012 That worked Great thanks..... 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.