Jump to content

Offset rectangle into separate lines ?


BrianTFC

Recommended Posts

Hi ALL,

 

You know how when you offset a rectangle it it stay as a polyline? i need a lisp routine that i can use to offset the rectangle, set the new lines to current layer, and substract the offset distance from both end of the line. i know thats asking alot but has anyone seen a routine like this?

 

Thanks,

Brian

:?

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

Hi ALL,

 

You know how when you offset a rectangle it it stay as a polyline? i need a lisp routine that i can use to offset the rectangle, set the new lines to current layer, and substract the offset distance from both end of the line. i know thats asking alot but has anyone seen a routine like this?

 

Thanks,

Brian

:?

 

If you are trying to automate drawing a steel beam you might look at....

http://www.draftsperson.net/index.php?title=Wisey's_Steel_Shapes_LISP_program

 

If not, tell us what you are trying to draw, maybe a lisp already exists.

Link to comment
Share on other sites

Basic lisp pick two pts look up help about the polar command not very hard

 

(setq pt1 (getpoint))
(setq pt2 (getpoint))
(setq offs (getreal))
(setq x1 (car pt1))
(setq y1 (cadr pt1))

now look up polar, distance (hint x1-x2, y1-y2)
work out the 8 points.

Link to comment
Share on other sites

It's actually a fairly involved process:

 

[b][color=BLACK]([/color][/b]defun c:offlin [b][color=FUCHSIA]([/color][/b]/ fs fe fd el cf le en ed pl fl mp hd l10 l11[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]defun mid_pt [b][color=NAVY]([/color][/b]s e[b][color=NAVY])[/color][/b]
    [b][color=NAVY]([/color][/b]mapcar '[b][color=MAROON]([/color][/b]lambda [b][color=GREEN]([/color][/b]a b[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]* [b][color=BLUE]([/color][/b]+ a b[b][color=BLUE])[/color][/b] 0.5[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] s e[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]

 [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]princ [color=#2f4f4f]"\nSelect PLINE To Offset"[/color][b][color=MAROON])[/color][/b]
          [b][color=MAROON]([/color][/b]setq fs [b][color=GREEN]([/color][/b]ssget '[b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]0 . [color=#2f4f4f]"LWPOLYLINE"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
          [b][color=MAROON]([/color][/b]= [b][color=GREEN]([/color][/b]sslength fs[b][color=GREEN])[/color][/b] 1[b][color=MAROON])[/color][/b]
          [b][color=MAROON]([/color][/b]setq fe [b][color=GREEN]([/color][/b]ssname fs 0[b][color=GREEN])[/color][/b]
                fd [b][color=GREEN]([/color][/b]entget fe[b][color=GREEN])[/color][/b]
                el [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 38 fd[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
                cf [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]= [b][color=RED]([/color][/b]logand [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 70 fd[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] 1[b][color=RED])[/color][/b] 1[b][color=BLUE])[/color][/b] T nil[b][color=GREEN])[/color][/b]
                le [b][color=GREEN]([/color][/b]entlast[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
     [b][color=NAVY]([/color][/b]progn
       [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]eq le [b][color=BLUE]([/color][/b]entlast[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
              [b][color=GREEN]([/color][/b]command [color=#2f4f4f]"_.CMDECHO"[/color] 1
                       [color=#2f4f4f]"_.OFFSET"[/color] pause fe pause[b][color=GREEN])[/color][/b]
              [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]not [b][color=RED]([/color][/b]eq le [b][color=PURPLE]([/color][/b]entlast[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
                  [b][color=BLUE]([/color][/b]command[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
              [b][color=GREEN]([/color][/b]command [color=#2f4f4f]"_.CMDECHO"[/color] 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
       [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]entlast[b][color=GREEN])[/color][/b]
             ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
       [b][color=MAROON]([/color][/b]entdel en[b][color=MAROON])[/color][/b]
       [b][color=MAROON]([/color][/b]foreach p ed
         [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]= 10 [b][color=RED]([/color][/b]car p[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
             [b][color=BLUE]([/color][/b]setq pl [b][color=RED]([/color][/b]cons [b][color=PURPLE]([/color][/b]cdr p[b][color=PURPLE])[/color][/b] pl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
       [b][color=MAROON]([/color][/b]foreach p fd
         [b][color=GREEN]([/color][/b]if [b][color=BLUE]([/color][/b]= 10 [b][color=RED]([/color][/b]car p[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b]
             [b][color=BLUE]([/color][/b]setq fl [b][color=RED]([/color][/b]cons [b][color=PURPLE]([/color][/b]cdr p[b][color=PURPLE])[/color][/b] fl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
       [b][color=MAROON]([/color][/b]and cf [b][color=GREEN]([/color][/b]setq pl [b][color=BLUE]([/color][/b]cons [b][color=RED]([/color][/b]last pl[b][color=RED])[/color][/b] pl[b][color=BLUE])[/color][/b]
                     fl [b][color=BLUE]([/color][/b]cons [b][color=RED]([/color][/b]last fl[b][color=RED])[/color][/b] fl[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
       [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]= [b][color=BLUE]([/color][/b]length pl[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]length fl[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]
           [b][color=GREEN]([/color][/b]progn
             [b][color=BLUE]([/color][/b]while [b][color=RED]([/color][/b]> [b][color=PURPLE]([/color][/b]length pl[b][color=PURPLE])[/color][/b] 1[b][color=RED])[/color][/b]
                    [b][color=RED]([/color][/b]setq mp [b][color=PURPLE]([/color][/b]mid_pt [b][color=TEAL]([/color][/b]car pl[b][color=TEAL])[/color][/b] [b][color=TEAL]([/color][/b]cadr pl[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b]
                          hd [b][color=PURPLE]([/color][/b]* [b][color=TEAL]([/color][/b]distance [b][color=OLIVE]([/color][/b]car fl[b][color=OLIVE])[/color][/b] [b][color=OLIVE]([/color][/b]cadr fl[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b] 0.5[b][color=PURPLE])[/color][/b]
                         l10 [b][color=PURPLE]([/color][/b]polar mp [b][color=TEAL]([/color][/b]angle [b][color=OLIVE]([/color][/b]car pl[b][color=OLIVE])[/color][/b] [b][color=OLIVE]([/color][/b]cadr pl[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b] hd[b][color=PURPLE])[/color][/b]
                         l11 [b][color=PURPLE]([/color][/b]polar mp [b][color=TEAL]([/color][/b]angle [b][color=OLIVE]([/color][/b]cadr pl[b][color=OLIVE])[/color][/b] [b][color=OLIVE]([/color][/b]car pl[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b] hd[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                    [b][color=RED]([/color][/b]entmake [b][color=PURPLE]([/color][/b]list [b][color=TEAL]([/color][/b]cons 0 [color=#2f4f4f]"LINE"[/color][b][color=TEAL])[/color][/b]
                                   [b][color=TEAL]([/color][/b]cons 10 [b][color=OLIVE]([/color][/b]append l10 [b][color=GRAY]([/color][/b]list el[b][color=GRAY])[/color][/b][b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b]
                                   [b][color=TEAL]([/color][/b]cons 11 [b][color=OLIVE]([/color][/b]append l11 [b][color=GRAY]([/color][/b]list el[b][color=GRAY])[/color][/b][b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b]
                    [b][color=RED]([/color][/b]setq pl [b][color=PURPLE]([/color][/b]cdr pl[b][color=PURPLE])[/color][/b]
                          fl [b][color=PURPLE]([/color][/b]cdr fl[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

error trapping with OFFSET type commands are NOT always accurate.

 

This makes the line segments the same length as original PLINE regardless if the offset side is to the inside or outside.

 

Have fun! -David

Edited by David Bethel
Link to comment
Share on other sites

Hi-

This is what I thought of from reading your post. (see picture below) Let me know if I misunderstood you.

 

 

Offset Rectangle.jpg

 

This will work on rectangles only. They can be horizontal or rotated.

You need to enter an offset distance and select a rectangle. The routine stays open to allow you to select more than one rectangle. I hope that helps.

 

 

(defun c:offsetpline (/ CurLayer OffsetDist VlaObj sset num Ang Ptdist StartPt EndPt)
(vl-load-com)

(defun *error* (msg)
(princ)
); _end defun

(setq CurLayer (getvar "clayer"))
(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)))

(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

(setq VlaObj (vlax-ename->vla-object (entlast)))
(vl-catch-all-apply 'vlax-put (list VlaObj 'Layer CurLayer))
(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

Edited by SLW210
code tags!!!!
Link to comment
Share on other sites

You're welcome.

 

I did notice a couple of things that I missed when I posted the code.

 

The first thing is to update this line:

(vl-cmdf "explode" (entlast) [color=red]""[/color])

 

You shouldn't need the quote marks at the end of the line. Just delete them. Let me know if that doesn't work for you.

 

The other thing you could do is add *error* to the local variables

(/ [color=red]*error*[/color] CurLayer OffsetDist VlaObj sset num Ang Ptdist StartPt EndPt)

 

Otherwise I hope that works for you.

Edited by SLW210
CODE TAGS!!!
Link to comment
Share on other sites

Quick one:

 

(defun c:MyOffset ( / ent obj )
   (if
       (setq *dist*
           (cond
               (   (getdist
                       (strcat "\nSpecify Offset Distance"
                           (if *dist* (strcat " <" (rtos *dist*) ">: ") ": ")
                       )
                   )
               )
               (   *dist*   )
           )
       )
       (while
           (progn (setvar 'ERRNO 0) (setq ent (car (entsel "\nSelect LWPolyline: ")))
               (cond
                   (   (= 7 (getvar 'ERRNO))
                       (princ "\nMissed, try again.")
                   )
                   (   (eq 'ENAME (type ent))
                       (cond
                           (   (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (cdr (assoc 8 (entget ent))))))))
                               (princ "\nObject is on Locked Layer.")
                           )
                           (   (eq "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
                               (foreach obj (vlax-invoke (setq obj (vlax-ename->vla-object ent)) 'explode)
                                   (vla-offset obj *dist*)
                               )
                               (vla-delete obj)
                               t
                           )
                           (   (princ "\nObject is not an LWPolyline.")   )
                       )
                   )
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

Link to comment
Share on other sites

  • 3 weeks later...

I need some help, this routine was written by jsowinski i've added a a line to change the layer of rectangle and explode it but it leaves the original rectangle underneath the line new lines. i need the original rectangle to be exploded. any help would be appreciated.

 

 
(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

(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  

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