Can I automatically draw multiple rectangles with unique dimensions?

Can I automatically draw multiple rectangles with unique dimensions?

Anonymous
Not applicable
4,163 Views
8 Replies
Message 1 of 9

Can I automatically draw multiple rectangles with unique dimensions?

Anonymous
Not applicable

I need to draw many rectangles each with unique dimensions. I would like to create a spreadsheet that tables each rectangle and it's dimensions and somehow write a command which creates all the rectangles at once from the spreadsheet. Or something along those lines.

 

For example, I can create multiple points all at once by arranging location data (X,Y,Z) in a spreadsheet like below and pasting it straight into the command bar.

POINT 2331091.68,465560.52,715.12
POINT 2331413.19,465702.85,713.68
POINT 2330971.93,465729.63,716.5

 

Thanks in advance!

0 Likes
Accepted solutions (1)
4,164 Views
8 Replies
Replies (8)
Message 2 of 9

ChrisRS
Mentor
Mentor
Accepted solution

Try:

"RECTANG 100,100 110,110 "

"RECTANG 120,120 @Anonymous,10 "

the first line uses starting and ending points. Notice the points are separated by a space and that there's there is a trailing space

 

The second line uses starting point and x and y distances. Again these are separated by a space and there is a trailing space.

 

Good luck

Christopher Stevens
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 3 of 9

lynn_zhang
Alumni
Alumni

Hello @Anonymous ,

Just checking to see if your problem has been solved. Did the above response help answer your question? Have you tried the suggestion and did it work? If yes, please click on the "Accept as Solution" button in that reply so this helps other users in the community find the solution too. Thanks!





Lynn Zhang
Community Manager


0 Likes
Message 4 of 9

andrewpuller3811
Advisor
Advisor

Further to chris' reply - 

 

Have a look into script files. You can find the help here - https://help.autodesk.com/view/ACD/2021/ENU/?guid=GUID-95BB6824-0700-4019-9672-E6B502659E9E

 

A script file is just a text file that contains commands for autocad to run.

Using excel you can put together the commands how you want then save them to a script file and load it into autocad.

 

e.g. the rectangle command runs using the command rectang as chris showed.

then it asks for the first point then the second point.

 

so you can easily generate a very large group of random points and sizes in excel and then combine them to create a bunch of commands to put in a script file.

 

I put the below in notepad and saved it as rectang.scr. in autocad I typed the command script, loaded the rectang.scr file and autocad drew 2 rectangs with the corners as below. make sure to have a blank line at he end to get the last command to run.

 

rectang 10,10 20,20
rectang 30,35 50,65

 

 



If a post provides a fix for your issue, click on "Accept as Solution" to help other users find solutions to problems they might have that are similar to yours.

Andrew Puller
Maitland, NSW, Australia
Windows 11
Intel core i7 11800 @ 2.30 GHz with 32GB Ram
Civil 3d 2023
Message 5 of 9

Anonymous
Not applicable

That did it. Worked flawlessly. The second option was perfect for my needs. Thank you for your help.

Message 6 of 9

Anonymous
Not applicable

Okay. What I did was take the line format suggested by Chris paste it into excel and then populate a table consisting of "RECTANG" in column A, starting point X in column B, starting point Y in column C, X distance in column D, Y distance in column E. I populated a list of roughly 20 lines all with different Y starting points and X and Y distances. Then I combined each column Using CONCATENATE function or & function in column F to automatically combine the lines.

 

My first line looks like the table below but the last column is the result of this function, 

=A1&" "&B1&","&C1&" @"&D1&","&E1&" " 

As I said the function combines the values in each column into the correct format for autocad command line.

RECTANG100100315RECTANG 100,100 @3,15 

 

I then populate my table and drag the function down to automatically combine each line into the right format. Then it is simply a matter of copying and pasting my results from column F into the AutoCAD command line. No need to load a script.

 

@andrewpuller3811 Is there any benefit to using the script over this method?
0 Likes
Message 7 of 9

andrewpuller3811
Advisor
Advisor

I thought you were looking to generate a number of rectangles.

 

Using the method you described and pasting it down, you could easily generate, 10,000 randomly located and sized rectangle commands.

 

Copy and paste these into notepad, save as script file, load in Autocad and you are done. 

I don't know how copying and pasting multiple commands goes with Autocad.



If a post provides a fix for your issue, click on "Accept as Solution" to help other users find solutions to problems they might have that are similar to yours.

Andrew Puller
Maitland, NSW, Australia
Windows 11
Intel core i7 11800 @ 2.30 GHz with 32GB Ram
Civil 3d 2023
0 Likes
Message 8 of 9

ChrisRS
Mentor
Mentor

@Anonymous wrote:

Okay. What I did was take the line format suggested by Chris paste it into excel and then populate a table consisting of "RECTANG" in column A, starting point X in column B, starting point Y in column C, X distance in column D, Y distance in column E. I populated a list of roughly 20 lines all with different Y starting points and X and Y distances. Then I combined each column Using CONCATENATE function or & function in column F to automatically combine the lines.

 

My first line looks like the table below but the last column is the result of this function, 

=A1&" "&B1&","&C1&" @"&D1&","&E1&" " 

As I said the function combines the values in each column into the correct format for autocad command line.

RECTANG100100315RECTANG 100,100 @3,15 

 

I then populate my table and drag the function down to automatically combine each line into the right format. Then it is simply a matter of copying and pasting my results from column F into the AutoCAD command line. No need to load a script.

 

@andrewpuller3811 Is there any benefit to using the script over this method?

@Anonymous , you got it! If your data is in excel, concatenating as you did in column F is the way to go.
Depending on your data source, you may not need excel at all. Just type it into Notepad.  You can save as a script or or use copy paste.

 

As to the benefit of a script vs Copy/Paste:

I see no advantage to either in a one-off situation. Copy/Paste is a little simpler.

In a repetitive situation a reusable script would be advantageous.

 

Here is an old, but useful, article: learn-how-to-write-command-scripts-for-autocad-and-automate-your-plotting

The ideas of reviewing/copying from the text widow to a notepad file is insightful..

 

 

Christopher Stevens
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 9 of 9

jon.bellH88MN
Community Visitor
Community Visitor

Thank you

0 Likes