Rectangles in excel to autocad

Rectangles in excel to autocad

Anonymous
Not applicable
9,585 Views
23 Replies
Message 1 of 24

Rectangles in excel to autocad

Anonymous
Not applicable

I have a list of excel start and stops. I would like to auto populate them into AutoCAD. 

0 Likes
Accepted solutions (2)
9,586 Views
23 Replies
Replies (23)
Message 2 of 24

pendean
Community Legend
Community Legend
0 Likes
Message 3 of 24

steven-g
Mentor
Mentor
Accepted solution

Small alteration to your formula in Excel, add a space after the word rectangle before the closing quote and your second comma should also be a space (not a comma) this separates the first coordinate from the second. Now just copy that whole list in column K Ctrl+c in Autocad make sure the command line is active (the cursor should be blinking inside the command line) then press Ctrl+v, you might need to zoom extents, but you should have a row of rectangles drawn in Autocad.

0 Likes
Message 4 of 24

steven-g
Mentor
Mentor

To be a bit clearer you should only copy the cells that have the formulas in them, so the cells colored yellow in the attached file.

0 Likes
Message 5 of 24

Anonymous
Not applicable

Thank you. Is there a way to get them spread out against the x direction by the same amount. As well to have a layer or id number attached to them?

 

 

book 1.jpg

0 Likes
Message 6 of 24

steven-g
Mentor
Mentor

The coordinates are there in your Excel file, it is those numbers you would need to adjust (fairly easy with a formula I would have thought).

As for the label, sure just tag on a 'text' command into the Excel formula, just try out the chain of commands first in LT to see what you need to enter at the keyboard, the text position could just be again coordinates that you can work out in Excel. BUT you will find one problem when running the text command from a 'script' like this as AutoCAD LT has a hard time figuring out when you are trying to simulate the enter key at the end of the text because in this situation it reads a space as a literal space (and not as the enter key) so the text/ label has to be the very last item in the Excel cell, Autocad sees the 'end of the formula' as a return or enter but only as the equivalent of the enter key ending the text item so you need to place space before the word '#rectangle' (the '#' key represents a space here) starting on the second formula which is the same as pressing the enter key to end the previous text command. It's a bit difficult to explain but try it and see if you can work that out.

0 Likes
Message 7 of 24

Anonymous
Not applicable

I haven't started the layer yet but I was looking more into my excel the rectangles don't come into the right size from the formula. The numbers that are in the formula are correct but when they get export to AutoCADbook 2.jpg they don't match up. any idea why?

0 Likes
Message 8 of 24

steven-g
Mentor
Mentor

Without looking too closely, the one thing that can cause problems is osnaps, this is dependant on your zoom level, but even using a script if the point you give in a script is somewhere close to an existing point then AutoCAD will still automatically snap to other geometry, you should turn off osnaps 'F3' before running a script, try that and see if it improves (and also turn off grid snaps).

0 Likes
Message 9 of 24

Anonymous
Not applicable

I turn those off and it still a) doesn't put it at 0,0 b) doesn't make the dimension I am trying to make.book3.jpg

0 Likes
Message 10 of 24

steven-g
Mentor
Mentor

I can't work out from just an image what you are trying to achieve? When I run the script Autocad produces a row of rectangles that are wider than their height, which is exactly what the numbers in the Excel sheet tell me is the correct information. Are your formulas correct? Or do you expect a different result, which might mean your formulas need to be altered? Can you post a dwg file using the first few sets of coordinates shown in the Excel sheet but actually draw the rectangles manually so I can see how it should be appearing in AutoCAD.

0 Likes
Message 11 of 24

Anonymous
Not applicable

I have attached both excel and AUTOCAD files.  I want the rectangles to be next to each other and have a layer id number. please let me know if I need to add more. thank you for your help on this.

0 Likes
Message 12 of 24

steven-g
Mentor
Mentor

The rectangles I have colored yellow in the attached file make sense with the values you have in columns D and E in Excel but the formulas used to create the values for X1, Y1, X2 and Y2 don't make any sense why do you need 250 in cell J6 followed by 550 in J7, it is these numbers that the script is using? Do you just need to correct the formulas to use the correct numbers?

What is also confusing is where do the red rectangles come from in your drawing (I changed the colors) what are they supposed to represent.

0 Likes
Message 13 of 24

Anonymous
Not applicable

The yellow box are the ones I drew with polylines. The red boxes are what I got with the formulas. I dont think the excel file updated when I sent the last one. I can re send the excel sheet.

0 Likes
Message 14 of 24

steven-g
Mentor
Mentor
Accepted solution

Does this work for you, I've attached the Excel and also a dwg showing what I get as the result of running the script (just watch where you place the space and the comma's in the formula).

 

Message 15 of 24

Anonymous
Not applicable

Perfect that is what I was trying to do thank you very much!!

0 Likes
Message 16 of 24

steven-g
Mentor
Mentor

You are welcome.

0 Likes
Message 17 of 24

m_angel_lopez94
Contributor
Contributor

Can someone give me a quick run down as to how to use this?

0 Likes
Message 18 of 24

tdentAAC7E
Explorer
Explorer

Super useful @steven-g thanks a bunch.
I am going to use this to add in some random details (not related to general band parameters) onto my profile view bands.

0 Likes
Message 19 of 24

tdentAAC7E
Explorer
Explorer

Hi @m_angel_lopez94,

I think you are asking just in general - if not apologies for the overexplaining.

This is a script that will generate a rectangle at given coordinates, then place a piece of text in the middle (rotated at 100deg), then draw another rectangle with text 1 unit to the right of the first... and so on


If you are new to scripts and want to try it out

  • Download/open the "rectangle.xlsx
  • copy cells K6 through to cell k73 (using [ctrl+c])
  • go to CAD and click into command prompt ready to type,
  • then paste (using [ctrl+v]) the copied cells.

You should hopefully find a group of rectangles that have autogenerated
Basically the data you have entered works as if you are typing it directly into the command prompt
If you are new to scripts, you can get a good understanding of the concept by typing in the first line in (respecting all spaces and punctuation)
This helps for when you want to modify the script to suit any other needs. For example I am going to use it as a way to add a band row under my profile view containing data that is not accessible via general band parameters. This way my engineers can fill in their own data, and the script will autopopulate the 'band' rectangles with the respective text.

Hope that helps, and again if I have over explained - apologies.

 

Message 20 of 24

msanagy81
Community Visitor
Community Visitor

I am using AutoCAD 2017 and copy-paste does not work.

0 Likes