Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to offset a line and join end points ?

28 REPLIES 28
SOLVED
Reply
Message 1 of 29
gokulgupta1997
5824 Views, 28 Replies

how to offset a line and join end points ?

I have a line, is there a way to offset it and join the respective end points of the line to create a rectangle or a closed shape.

 

say for example I want to make a wall or a column, so I create a line for the length of the wall and then I offset it 300mm and it offsets the line and automatically joins the end points of the lines together in a single command. to make sort of a box. 

 

making a rectangle with the rectangle tool takes a lot of time as you have to make a rotated rectangle, and either specify diagonal or length. Also rectangle tool cant create curved walls .There is a wall tool in autocad architecture-but that makes a complete wall (with height and all ) so it cant be used for other purposes other than creating walls. 

 

basically what I am asking is there like a extrude command that works with a line or a curve(any 2d curve) to form a closed shape 

or you start with a line or a curve you offset it a particular distance and it automatically joins the respective end points to create a closed shape (for example if you start with a line it offsets it and automatically joins the end points to make a rectangle, or if you start with a curve it makes like a bent pipe or something)

 

28 REPLIES 28
Message 2 of 29

Hi @gokulgupta1997,

 

There is not such a feature in vanilla AutoCAD.

 

You might consider using the Rectangle command and perhaps also the Multiline feature.

 

You can explore the Autodesk App Store to see if there are any utilities that can do this for you.

 

If you like, I could move this thread to the customization forum for you too where you might get some more responses.

 

 

Please select the Accept as Solution button if my post solves your issue or answers your question.


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
Message 3 of 29
Patchy
in reply to: gokulgupta1997

Ask the Autolisp Group maybe they can help.

The closest command to do a ton of offset is SHRINKWRAP, but it's not that useful for what you're doing.

 

Capture.JPG

Message 4 of 29

is there maybe a command that connects the start point with start point and end point with end point of 2 selected lines or polylines 

Message 5 of 29
Patchy
in reply to: gokulgupta1997

If you use autolisp, it can be done with 2 lines.

 

 

 

Message 6 of 29


@gokulgupta1997 wrote:

... is there a way to offset it and join the respective end points of the line to create a rectangle or a closed shape.....


 

There's one called OffsetBothSidesJoin.lsp, available >here<, that does it from a center -of-path original, Offsetting [as the name implies] to both  sides and joining their ends [if the original is not a closed shape].  It could be modified quite easily to go to one side only instead.  [If also have one that's the same but also erases the center-of-path original, if you're interested, but that wouldn't be relevant to a go-only-to-one-side approach.]  See also Message 14 there to do it to multiple paths at once.

Kent Cooper, AIA
Message 7 of 29

If you are using autocad architecture, you can explode a 3D wall object and it makes it a 2D block at a Z elevation of zero. If you explode it again it makes it all separate lines. So you can easily ditch the 3D if you don't need it.



Nick DiPietro
Cad Manager/Monkey

Message 8 of 29

Yes, I too would like AutoCAD to offset and join the ends of a line. I would also like AutoCAD to have coffee ready for me when I arrive at work in the morning. Unfortunately, neither of those wishes are likely to come true so in their absence, I would use either the STRETCH command or a move called the grab-the-midpoint.

 

If your rectangle lines running left and right as well as top to bottom, then select two vertices using a crossing window and stretch the rectangle by dragging your mouse. If you don't want to drag because you need precision, you can type in a distance, such as 12.3501, to stretch, or even compress, the rectangle. Hint 1: Turning ON ortho helps you to drag straight and not at an angle. Hint 2: Turning OFF snaps helps too because it prevents you from accidently getting 'sucked' into an adjacent snap point.

 

Crossing window to select two vertices.Crossing window to select two vertices.

If your rectangle is at an angle, you can grab the midpoint grip, then drag it. If you turn on polar tracking, the drag procedure will display 'perpendicular' in a tooltip during the dragging process.

 

Tooltip displays perpendicular dragging of midpoint.Tooltip displays perpendicular dragging of midpoint.

 

Chicagolooper

EESignature

Message 9 of 29

Hi @gokulgupta1997,

 

I am coming back to your thread to see if the  question you posed has been resolved by the many suggestions provided.  If so, please mark the post or posts as Solution(s) to help others find the answer quickly. If your issue persists, please give me a bit more detail on this issue so we can continue to work towards getting this solved.


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
Message 10 of 29

It sounds like to me something that should be easily fixed, but may not be worth the hassle.

 

If it works, your best bet is probably the "OffsetBothSidesJoin.lsp" that Kent suggested.

Message 11 of 29


@gokulgupta1997 wrote:

I have a line, is there a way to offset it and join the respective end points of the line to create a rectangle or a closed shape.....


In simplest terms, try this [minimally tested]:

 

(defun C:OCEJ (/ ss e1 e2); = Offset, Close Ends, Join
  (setq
    ss (ssadd); initially empty
    e1 (car (setq esel (entsel "\nObject to Offset and Close Ends/Join: ")))
  ); setq
  (command "_.offset" pause (cadr esel) pause "")
  (ssadd (setq e2 (entlast)) ss)
  (command "_.line" (vlax-curve-getStartPoint e1) (vlax-curve-getStartPoint e2) "")
  (ssadd (entlast) ss)
  (command "_.line" (vlax-curve-getEndPoint e1) (vlax-curve-getEndPoint e2) "")
  (ssadd (entlast) ss)
  (command "_.join" e1 ss "")
  (princ)
); defun

 

It doesn't yet control for various things [selection of valid entity type, Object Snap if ENDpoint isn't among running modes, etc.], or have other typical features [error handling, command-echo suppression].  But it works on anything Offsettable/Joinable [Line, Arc, Polyline, Spline].  It doesn't like Ellipses, though there may be a way around that -- later.

Kent Cooper, AIA
Message 12 of 29
mplamplou360
in reply to: Patchy

Hi Patchy,
That is an awesome lisp, thank you!
Could this perhaps be modified to work on polylines?
I would love to be able do it myself but so far I haven't gotten the grasp on lisps.
Thanks!
Message 13 of 29
Kent1Cooper
in reply to: mplamplou360


@mplamplou360 wrote:
.... Could this perhaps be modified to work on polylines? ....

Since @Patchy's offering is for Lines specifically, the question arises:  Are you talking about single-line-segment-only Polylines, that are geometrically like Lines, or Polylines of greater complexity?  If the former, it's not too difficult a code adjustment.  If the latter, the approach there is not appropriate, and a different approach would be needed, presumably drawing connecting pieces at the ends and joining things together.

 

[I also note that the routine draws a Polyline that replaces the initial Lines while connecting their ends, and on the current Layer, with no accounting for the Layer of the Lines it is replacing, or whether they are on the same Layer as each other.  That may not matter to some, but....]

Kent Cooper, AIA
Message 14 of 29
mplamplou360
in reply to: Kent1Cooper

Hi Kent,


Thank you for the quick reply, (and the countless other times you have helped with your replies!)

At the moment I'm interested in joining/closing polylines consisting of line segments, usually it's walls.

 

I stumble upon this problem when working on other peoples files, it's not about creating closed offset polylines but quickly fixing them. Otherwise I use your lifesaving lisp OCEJ (Offset, Close Ends, Join)

 

 

Creating the new pline on the current layer is fine.

 

Thank you again!

John

Message 15 of 29
Kent1Cooper
in reply to: mplamplou360


@mplamplou360 wrote:

.... I'm interested in joining/closing polylines consisting of line segments....


But apparently not of only single line segments, which was an essential part of my question.  If the L's in your image are what you want closed at their ends [though why, since they hit other walls, is another question], you can't use @Patchy's cn.lsp code.  I have a routine [just updated today in another Topic] that will close the ends of those, but it would need you to do it separately at each end.  Are you looking for something that will close off both ends of two open Polylines, with selection of them only once?  If so, that's different from the purpose of this Topic, is probably not very difficult, and there may well be routines out there already.

Kent Cooper, AIA
Message 16 of 29
mplamplou360
in reply to: Kent1Cooper

I have a routine [just updated today in another Topic] that will close the ends of those, but it would need you to do it separately at each end.  

Could you please link me to the topic? 


is probably not very difficult, and there may well be routines out there already.

I ended up in this thread by searching. The only other routine I could find online is this: https://blog.draftsperson.net/join-2-polylines-lisp-routine/  

But it doesn't seem to work (I get Error: bad argument type: lentityp nil).

 

 

Message 17 of 29
Kent1Cooper
in reply to: mplamplou360


@mplamplou360 wrote:
I have a routine ... that will close the ends of those, but it would need you to do it separately at each end.

Could you please link me to the topic? 
....


See CapEnd.lsp >here<.

Kent Cooper, AIA
Message 18 of 29
Kent1Cooper
in reply to: mplamplou360


@mplamplou360 wrote:
.... The only other routine I could find online is this: https://blog.draftsperson.net/join-2-polylines-lisp-routine/  

But it doesn't seem to work (I get Error: bad argument type: lentityp nil).


That is old enough that it was written for "heavy" 2D Polylines [probably before the advent of "lightweight" ones], whose vertices are actually separate entity names from the parent object, that need to be stepped through [that's what the (entnext) functions and the check for "SEQEND" are about].  In any case, it doesn't close both ends, so you would still need to do it separately at each end, just as you do with CapEnd in its Line closure option.

Kent Cooper, AIA
Message 19 of 29
mplamplou360
in reply to: Kent1Cooper

Thank you Kent for looking into it.
Your Cap End lisp does the work.
Have a good day!

John
Message 20 of 29
Kent1Cooper
in reply to: mplamplou360

Here's a version that does both ends for you with only one selection of the two Polylines, and only with Lines [so you don't need to choose the option].  It could use the usual enhancements, but it seems to work:

 

(vl-load-com)
(defun C:2OPCBE ; = 2 Open Polylines Close Both Ends
  (/ ss pl1 pl2 pl1S pl1E pl2S pl2E opp)
  (if
    (and
      (setq ss (ssget "_:L" '((0 . "*POLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 1) (-4 . "NOT>"))))
        ; either "heavy" or "lightweight" type, open only, on unlocked Layer(s)
      (= (sslength ss) 2)
    ); and
    (progn ; then
      (setq
        pl1S (vlax-curve-getStartPoint (setq pl1 (ssname ss 0)))
        pl1E (vlax-curve-getEndPoint pl1)
        pl2S (vlax-curve-getStartPoint (setq pl2 (ssname ss 1)))
        pl2E (vlax-curve-getEndPoint pl2)
        opp (> (distance pl1S pl2S) (distance pl1S pl2E))
          ; run in opposite directions [assuming roughly in parallel]
      ); setq
      (command "_.line" "_non" pl1S "_non" (if opp pl2E pl2S) "")
      (ssadd (entlast) ss)
      (command "_.line" "_non" pl1E "_non" (if opp pl2S pl2E) "")
      (ssadd (entlast) ss)
      (initcommandversion); [to make Join work even if PL's not co-planar]
      (command "_.join" pl1 ss ""); will be on pl1's Layer
    ); progn
    (prompt "\nDid not select 2 and only 2 open-ended Polylines on unlocked Layers.")
  ); if
  (prin1)
); defun

 

It works with either variety of Polyline, including if the two selected are different varieties.

It decides which ends to join by testing simply whether the start of one is closer to the start or end of the other.  If the two are not running roughly in parallel [even if in opposite directions], it could give unexpected results in some configurations.

If the two are not co-planar, it still joins them, though the end result will be a Spline, not a Polyline.  If either is a non-planar 3D Polyline, the result will also be, including converting any arc segments in the other one to line segments.  But if a planar 3D one is co-planar with the other one, it comes out as a "lightweight" Polyline.

It could be made to allow selection of those on locked Layers, and the closing Lines would be drawn across the ends, but the locked-Layer one(s) would not be joined to the rest.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report