Converting line to rectangle

Converting line to rectangle

Anonymous
Not applicable
9,455 Views
18 Replies
Message 1 of 19

Converting line to rectangle

Anonymous
Not applicable

Hello everyone!

 

I have a problem.

 

I need to convert several lines (different lengths) into rectangles. The rectangles needs to be the same length as the lines and 0.2m wide. It needs to be centered on the line and in the same angle as the line. 

 

Is there a simple way or a command to do this? Maybe there is an existing lisp for this?

0 Likes
9,456 Views
18 Replies
Replies (18)
Message 2 of 19

ВeekeeCZ
Consultant
Consultant

Select all the lines, use PEDIT to set width, then convert it to rectangles using THIS  routine.

Message 3 of 19

maratovich
Advisor
Advisor

Show an example of what you need.

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 4 of 19

latino_alireza
Explorer
Explorer

Thanks boys, it was great, just one more question about this procedure, the rectangle is still identified as a line because its 4 corners is not selectible in offset. is there any cure for that please?!

0 Likes
Message 5 of 19

Kent1Cooper
Consultant
Consultant

You can use OffsetBothSidesClose.lsp, >here<.

Kent Cooper, AIA
0 Likes
Message 6 of 19

latino_alireza
Explorer
Explorer

it makes just two lines at both sides, and still I need to make two more lines at both sides and delete the main one in the middle to make it become a rectangle.

0 Likes
Message 7 of 19

pendean
Community Legend
Community Legend

@latino_alireza wrote:

Thanks boys, it was great, just one more question about this procedure, the rectangle is still identified as a line because its 4 corners is not selectible in offset. is there any cure for that please?!


4 unconnected non-touching lines will not become a closed rectangle if your intent is to never ever alter any length.

Perhaps you means something else using the words "line" and 'rectangle'?

 

You'll need to share your DWG file here: do so soon please.

0 Likes
Message 8 of 19

latino_alireza
Explorer
Explorer

I use PEDIT and choose the width of 1mm and everything is fine so far, but the only problem is that the outcome here looks like a real rectangle but technically CAD does now recognize it as a rectangle and sounds like it still is recognized as a line. Because the corners is not recognizable and Snap also does not recognize the corners as intersections the way it recognizes the corners of a simple rectangle. I need the PEDITED created rectangle to be like a normal rectangle and the corners be selectable by snap. I have attached a few screenshots to show what I mean. I would really appreciate it if you could help me solve this out.the primary linesthe primary linesPedited with a width of 1mmPedited with a width of 1mmthe outcome looks like a rectangle but still like a line only the start and ending point of the line is recognized by snapthe outcome looks like a rectangle but still like a line only the start and ending point of the line is recognized by snap

0 Likes
Message 9 of 19

pendean
Community Legend
Community Legend

@latino_alireza Giving a line a WIDTH and masking the fact that it is a solid wide line does not make it a rectangle, is is simply a hollow-display of a thick line.

 

As I noted before, there is NOTHING in AutoCAD to convert a single line to a rectangle, it will always be a single line.

 

You want to use RECTANG command to create and draw a 1mm wide, or customize a LISP to offset your single LINE object, then find the four ends to close with two other lines, then merge them altogether to create a closed polyline aka a rectangle.

 

Share your DWG file here, I'll show you how you misrepresented a thick filled line with an outline of a single thick line so you no longer think of is a a 'rectangle'.

 

TIA

0 Likes
Message 10 of 19

latino_alireza
Explorer
Explorer

Thank you

I really do not know how to make a customized lisp and if I none of the techniques and lisps mentioned above work, I'm gonna have to do all the lines one by one. I would be thankful of any help.
Here is my DWG

0 Likes
Message 11 of 19

Kent1Cooper
Consultant
Consultant

@latino_alireza wrote:

it makes just two lines at both sides, and still I need to make two more lines at both sides and delete the main one in the middle to make it become a rectangle.


It works to make a rectangle for me -- that's what the "Close" at the end of the file name is about -- in your sample drawing at Message 10 as well as in new drawings.  If it doesn't do that for you, I'm at a loss....  Show us your command-line history when you use it and it doesn't work.

Kent Cooper, AIA
0 Likes
Message 12 of 19

pendean
Community Legend
Community Legend

@latino_alireza wrote:

...Here is my DWG


PEDIT command creates a wide PLINE of your LINE, this is what a 1mm wide PLINE looks like

pendean_0-1717677791611.png

 

It is still a "line"

pendean_1-1717677824678.png

 

Forcing the display to hide the line fill like you did does not turn it into a RECTANG, it is still a "line"

pendean_2-1717677870285.png

 

The LISP provided in message #5 above needs a fix to finish but almost gets you there, ask @Kent1Cooper to tweak it for you so it runs through the JOIN option automatically since you may have just ignored all the prompts at the command line asking you to finish, and see if he can also make it where you can select more than one object at a time too.

This is now a RECTANG, with corners that you can pick:

pendean_3-1717678290500.png

 

 

 

0 Likes
Message 13 of 19

Kent1Cooper
Consultant
Consultant

@pendean wrote:

....

The LISP provided in message #5 above needs a fix to finish but almost gets you there, ask @Kent1Cooper to tweak it for you so it runs through the JOIN option automatically since you may have just ignored all the prompts at the command line asking you to finish, and see if he can also make it where you can select more than one object at a time too.

.....


I don't understand.  What "fix" does it need?  What do you mean by "all the prompts at the command line asking you to finish"?  The one such thing in it could only be the completion of the selection of objects.  It already does finish, join, etc., and for multiple objects.  I did all these in the sample drawing with it in one running of the command, and yes, they're closed Polylines:

Kent1Cooper_0-1717679261831.png

 

Kent Cooper, AIA
0 Likes
Message 14 of 19

tramber
Advisor
Advisor

It was said that a polyline with a width can not be transformed into a rectangle.

But if you CONVTOSURFACE them you may obtain surfaces that you can explode. Then you get regions and .... you can explode them too 😁

(always using P like Previous to select the after explosion objects)

And then a big and multiple PEDIT. (with M and P, still)

It works even if it is not crazily practical !


EESignature

0 Likes
Message 15 of 19

Kent1Cooper
Consultant
Consultant

@tramber wrote:

It was said that a polyline with a width can not be transformed into a rectangle. .....


Certainly it can, if it's single-linear, but any Polyline with constant width can be converted to its outline.  If you want to go the route of turning the Lines into Polylines and giving them width, you can use the PLWO command in PLWtoOutline.lsp, >here<, to turn them into the outlining rectangles.  [I've tried it in the sample drawing, and it works for me.  But the OBSC command is faster, without the intermediary conversion of Lines to Polylines with width.]

 

And I think there are routines out there that can do the same even for Polylines of varying width, though PLWO is limited to those with global non-zero width.

Kent Cooper, AIA
0 Likes
Message 16 of 19

tramber
Advisor
Advisor

For sure, if you employ lisp, you can contradict all the time 😉

And I would like you to contradict the one who originaly said the axiom, not me.

It is more elegant.

Although I a m myself a lisper, since 2000 at quite a high level, my pleasure is always to find solutions wihtout !

This is why you will never see me here with too many lisps. I got none in my computer except a huge project for internal use.

 


EESignature

0 Likes
Message 17 of 19

latino_alireza
Explorer
Explorer

Anyways I had to do all the process one by one with simple Line command. 🤧😅

0 Likes
Message 18 of 19

dbroad
Mentor
Mentor

@Kent1Cooper It didn't work for me either.  Kept asking to close repeatedly.

 

You might try the attached but you should use -dwgunits first to convert your drawing to meters IMO. The program adds a rectangle for each line and moves the lines to layer defpoints in case you need them also. There is no prompt for rectangle height. It's built in at 0.2.

 

Instead of manipulating coordinate systems, the program uses rotation and translation transforms.  Takes a bit of time to complete the whole task (lots of lines).

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 19 of 19

Kent1Cooper
Consultant
Consultant

@dbroad wrote:

@Kent1Cooper It didn't work for me either.  Kept asking to close repeatedly.

.....


Looking into it, the only thing I can think of is that it doesn't account for the PEDITACCEPT System Variable setting.  I always have that set to 1, and didn't have that in mind when I wrote that routine.  If I set it to 0, the routine doesn't work right, but asking to close repeatedly is not the symptom, so I'm not sure that can be it.  But if you have PEDITACCEPT = 1, does it work?  If that solves it, see the attached update which accounts for that regardless of your current setting, and restores your current setting if it changed it.

Kent Cooper, AIA