Saturday, November 20, 2010

He hates Autocad down by the sea shore...

Hate is probably too strong a word. Prefers to avoid might be better. He is an electrical person who organises motors to start, stop and so on. He will never read this, but just in case I will refer to him as "Fred" (not his real name).

This is done by means of PLC's (Programmable Logic Controllers). My knowledge of these is limited to the following:
They have cabinets, and in these cabinets are "racks" and in the racks are "cards".

The cards are where the wires from say a relay are connected to. It appears Fred is quite OK with Excel and happily puts all his stuff into a spreadsheet. If the electricians were happy with this, instead of a drawing, then life would be easy.

But no. They like drawings, done in Autocad because that has been the way of things for quite a while. Recently, he gave me some drawings to update, which involve me typing hundreds of times the same thing over and over again. Words like REMOTE and FAULT. I have now requested we get a program called "Active Words" which just stores up your keystrokes and you can allocate hot keys to them.

This all triggered an idea (no doubt not new!) to see if I could give Autocad an Excel connection.
The plan was to have a spreadsheet all set up with buttons on it to make filling it out a quick thing, then a button to generate an Autocad script file. I did this once years ago, and have no idea where all the files ended up, so thought it might be fun to do a new approach. It is summer here now in Auckland and maybe fun might be getting out to the beach.

Another wasted weekend later, I have a bare bones setup that works. It was a struggle with Microsoft Excel 2007, as I was used to the 1997 version. Little differences like: you have to have a macro enabled file type, the ribbon where things seem to be never where you think they might be. Plus, if you want VBA, you have to add the "Developer" tab to the ribbon.

Here is a screen shot of the spreadsheet:

This is a snippet of the VBA screen, showing part of the code:

This one is a shot of a typical autocad drawing of a PLC card:

This one here shows a line of script generated lines and text:

They have only got LT Autocad, so a script is the only way here. I have been down this rocky road before in a way: I tried to do the same thing, but using their existing blocks, which became a nightmare.
This time: no blocks, just lines and text, it is just simpler. Having said that, the line shown was hard coded-ie the coordinates of everything had to be specified. If this goes any further, there would have to be a lot of number adding and string converting.
That's if....