Community
AutoCAD LT Forum
Welcome to Autodesk’s AutoCAD LT Forums. Share your knowledge, ask questions, and explore popular AutoCAD LT topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert block based on an Excel sheet

27 REPLIES 27
SOLVED
Reply
Message 1 of 28
Anonymous
15123 Views, 27 Replies

Insert block based on an Excel sheet

Hi,

In a drawing I have made a handfull of blocks with the names block1, block2 etc. each with one attribute.

 

I have an Excel document and for each line I want to insert a block, based on the block name(column A), fill in the attribute info(column B), and place it based on column C.

 

Can it be achieved in LT through scripts or do I have to use LISP for such things?

 

sleenshatt.PNG

 

27 REPLIES 27
Message 2 of 28
pendean
in reply to: Anonymous
Message 3 of 28
Anonymous
in reply to: pendean

Looks good, except it seems like it requires LISP, I`m hoping not to upgrade AutoCAD.

Message 4 of 28
sthompson1021
in reply to: Anonymous

Try the attached spread sheet. It should do what you need. Make sure that ATTREQ is set to 1 and ATTDIA is set to 0.

Just copy column F from F2 down to F9 and paste on the command line. If your blocks are not actually name block 1, block 2, ect. you will have to change to the correct names

Message 5 of 28
Anonymous
in reply to: sthompson1021

This actually works pretty good, I would have to make shure that when I paste the list of blocks and attributes it puts them into every other row in Excel since the formula-part consists of two lines.

I tried having the formula in two sepparate cells next to each other, but it wont execute in AutoCad as it reads everything as one command, while the way you put it up, every line seems like one command.

Is there any symbol that would tell AutoCAD that "This is the end of this command" after "-insert BLOCK 1" ? Just so that I can have it all on one line.

Message 6 of 28
sthompson1021
in reply to: Anonymous


@Anonymous wrote:

Is there any symbol that would tell AutoCAD that "This is the end of this command" after "-insert BLOCK 1" ? Just so that I can have it all on one line.

 

If there is, I haven't found it yet. Same with Scripts, you need a hard return. Just make sure you pay attention to where the spaces are when you enter info into  the cells.


 

Message 7 of 28
Paul_Gander
in reply to: Anonymous

Hi,

I've created an excel sheet with a macro button that will take a selected list of command strings and convert any | (pipe) characters into the equivalent of an enter keypress. The result is copied to the clipboard so it is then just a case of pasting it directly to the AutoCAD/LT command line. See the images below for an example. The first image shows the list of commands generated from a table of data. (Type and Height are attributes in this example.) 

 Sheet1.PNG

 

The second image shows the list that gets created and copied to the clipboard by the macro.

Sheet2.PNG

 

 

 

Message 8 of 28
Anonymous
in reply to: sthompson1021

This only works if you copy the "- (Block Name)" and then the reference numbers and paste them separately, respectively. Is there a way where you can copy and paste the entire thing?

Message 9 of 28
steven-g
in reply to: Anonymous

This should work as just a continuous script, you need to make sure that the command line is active (you have to see the cursor blinking in the command line) otherwise it will only work for individual lines one at a time.

Message 10 of 28
Anonymous
in reply to: steven-g

I find that it does work, sometimes but only intermittently. And it only inserts some of the blocks.
Does the attribute number you assign to have to be new?
Brandon L. Sobjack, CET, AASEET
Brandonsobjack@yahoo.com
Message 11 of 28
steven-g
in reply to: Anonymous

You would need to post a copy of your drawing with the blocks and the excel file so we can see what is happening. Or possibly just a copy of your command history (F2) if you can highlight where it is going wrong, someone might be able to see what the problem is.

Message 12 of 28
Anonymous
in reply to: steven-g

Yes. Here is an example of what I am trying to do. This drawing contains 3 blocks. a square, a circle and a triangle.

 

The code (in the attached spreadsheet) only works, in AutoCAD, for me, if you first enter "-insert" into the command line. It does not work by just copying and pasting column F.  Furthermore, if you first enter "-insert" into the command line, it doesn't TRULY work because it defaults to inserting whatever the last thing it inserted was, first, in place of the first item that was supposed to be inserted (in this case it is a Square).

 

Please do me a favor and open this drawing and paste the contents of column F (F2-F11) into the drawing command line and tell me if you get different results.

 

Thanks in advance!

Message 13 of 28
Anonymous
in reply to: steven-g

It may also be helpful to give you this screen shot of the resulting messages AFTER I attempted to paste the formula and run it in the command line. See Attached.

Message 14 of 28
steven-g
in reply to: Anonymous

It works just fine here. But what program are you using? AutoCAD reports that the program last used to save the file was not an Autodesk product, and the content in your screenshots from the command history does look a bit odd.

Message 15 of 28
Anonymous
in reply to: steven-g

I got the insertion of this working well, but I cant get the  three attributes that I have to update from the spread sheet to update. 

 

can you help me with that?

 

Message 16 of 28
steven-g
in reply to: Anonymous

Can you post the .dwg and .xls so we can see what is happening?

 

Message 17 of 28
Anonymous
in reply to: steven-g

Please see attached.

 

the test file is what i was inserting  into 

Message 18 of 28
steven-g
in reply to: Anonymous

Looking good.

You are on the right track. Your problem is how a macro/script deals with text, everything is fine up until you start entering attribute values, when it comes to attributes AutoCAD is expecting a value that could be text, and for text, AutoCAD will accept spaces as a textual space so anything that you try to enter will be entered literally (you should see that in your drawing when the first attribute value is shown as HP= "0 1 2.1A 1000") after that your macro is broken and it all goes wrong with instructions coming in at the wrong order.

You need to break down your excel file even more, at the moment each insert command is taking up two lines, you will need to add more lines so each attribute value has it's own line (a linefeed in the macro is seen as being the <enter> key).

One more thing to watch in a macro the insertion scale is generally only a single value and this counts as both x and y so you also have an extra '1' in your macro to confuse things. When checking macros always look at the command line history to see how the prompts are been replied too by the macro.  When entering _insert from the command line ,the insert command does indeed ask for scale x and y but in a macro you do have to tell the command when you want to use individual x and y scale factors otherwise it just expects one scale factor.

Hopefully this will get you going again.

Message 19 of 28
Anonymous
in reply to: steven-g

tried that and it seems to be treating each command as a separate insert 

could you look again?

 

Message 20 of 28
Anonymous
in reply to: steven-g

here is my output  it does not even add the HP= "0 1 2.1A 1000

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report