Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Excel Data in AutoCAD 2002

Status
Not open for further replies.

tommcmaster

Technical User
Feb 7, 2005
16
GB
Hi,
I'm a newbie to AutoCAD and have been given a job to do for work. Basically, we have an Excel table which is full of information about automation cabinets and pumps and devices. It is the intention of my boss to take this information from Excel and put it into AutoCAD but this is, as far as I can tell, the problem. It isn't a simple case of "copy and paste the Spreadsheet into the drawing." What my boss would like is to take some of the information from this Excel Spreadsheet and use it as text in various text areas around the drawing. This process would then be used for several drawings, all of which are the same, save for the text fields in them, which change for each drawing. The text areas aren't blocks though. They're simply areas of Multiline text.
I've been using VBA for about 2 years now so I know the ins and outs but I'm not an expert. Any help would be greatly appreciated.
Thanks,
Tom.
 
Hi Tom,

Check out this thread and see if that gets you what you need. If doesn't or you need more detailed help, post back and we'll get you what you need!

HTH
Todd
 
Hi Todd,
Don't know if you remember but I talked to you about another problem in AutoCAD a couple of weeks ago. It related to Access...I was from Scotland and you were 1 million hours behind in Detroit. Anywho, that's by the by.
Thanks for the reply again. I'm going to try the code from the post and see what it does. The only question that I have would be, is it possible through VB, to reference the content property of a Multiline Text object, a bit like you'd reference the caption in a label in Access using the form.object.property notation. I had thought of using the x and y coordinates to identify text objects uniquely if there was more than one but perhaps that's only exposing my rookie status.
Any help is much appreciated.
Tom.
 
Hi Tom,

I do remember that, how did your project turn out?

To answer your questions, yes you can access the mtext contents:

Code:
...

Dim objMText as AcadMText

AcadMText.TextString

...

And you could use X and Y coordinates but a more reliable approach might be to gather all the mtext objects and then parse the context searching for key words, (you can't always depend on operators placing objects where they should be), but if you have key words that must appear either for a bill of materials, specs etc., you have a better chance of building a reliable routine.

HTH
Todd
 
Hi Todd,
To be honest, it's kind of the same project although my boss has done a beastly amount of work on it. This is one of the final parts to it I think.
Thanks for the stuff on the Mtext. One thing I have trouble getting my head around is how to distinguish between different Mtext objects as they all seem to have no unique id.
What we're actually trying to do is take all the MTexts in a drawing and replace their content with specific items of data held in the Excel table. It could be for example, that we have a drawing with 8 or 9 MText objects, each holding a different word. I'd need to try and group these together or distinguish between them in some way to enter the new words.
Thanks,
Tom.
 
Hi Tom,

So I'm guessing the MText in the drawing is a place holder of some sort? Or are you updating older/existing drawings to some new format? In any case, the hurdle you'll have to clear will be finding some sort of commonality between the mtext objects so you can find not only the proverbial "needle in a haystack" but the "right needle in the haystack." In the past when I've had to do this, if it's been really really bad, meaning the "needle" was never in the same place, or they had nothing in common I could search for, I had to run the routine, and physically select what I needed to change. Now, after doing this once, I replaced what I was changing with either a block, or added some flag so I could find it blinfolded again later on. This IMHO is worst case senario - if this is your case, make sure you "fix it" so you don't have to go through it again.

Other strategies, build a list (array) of known words, and associate them with the proper change (routine, variable etc.), or use a database and a recordset to build your associations. Another possibility, open each and every drawing, and write all the Mtext objects to a text file and then open the text file with either Excel, Word, Notepad etc., make the associations here, and then with another routine, read in the changes - so this might look like this:

DWG=SOMEDRAWING.DWG
MTEXTOLD=all mtext goes here
MTEXTNEW=all changes go here - manually, then read this portion in.

Hopefully this will give you some ideas. If not shoot me a couple of your drawings and maybe some of the code you have and I can take a closer look and maybe offer some better suggestions. If you need it, send them to edgi3[AT]juno[DOT]com.

HTH
Todd
 
Hi Todd,
I took your advice and combined it with some google searching and personal thoughts. What transpired was 6 pages of code from Google Groups...in French. Dim, Public and Private are the same across the globe apparently :) In all seriousness, we have managed to find a program written in lisp that looks at the value held in an mtext object (say the value B1). It then looks at the Excel spreadsheet that is currently active and fills this object with the contents of the cell B1. So your idea of adding a flag is more or less what we're doing. My job today is to decode 12 pages of lisp I think. I'll let you know how it goes.
Once again, thanks so much for all your help. You seem overworked in here.
Tom.
 
Hi Tom,

Glad I could help and I look forward to hearing how you make out!

Todd
 
Hi Todd,
Have been beavering away on this project for the last day or so and thought that we had it cracked. We came across a program in Lisp that does what we want it to do.
On a slightly different note, do you know if it is possible to link VB to AutoCAD? That is to say, actual VB and not VBA.
Thanks,
Tom.
 
Hi Tom,

Of course! Here's a module I use from VB6:

Code:
Public AcadApp As AcadApplication
Public AcadDoc As AcadDocument

Public Sub InitializeAutoCAD()
  '
  ' *** InitializeAutoCAD ***
  '
  ' This routine is used to connect or start and then
  ' connect with AutoCAD.
  '
  On Error Resume Next
    
  Set AcadApp = GetObject(, "AutoCAD.Application")
  AcadApp.Visible = True
  If Err Then

    ' Won't be able to continue, notify user and get out.
    '
    MsgBox "AutoCAD must be running before using this program."
    
    End
  
  Else
    Set AcadDoc = AcadApp.ActiveDocument
  End If
        
End Sub

HTH
Todd
 
Hi Todd,
Just tried to make use of that code but it says that the AcadApplication and AcadDocument variables are "user defined types not defined."
Any ideas?
Thanks,
Tom.
 
Hi Tom,

Sorry, I forgot to mention you'll need to add a reference in your application to AutoCAD. In the pull down list, it should look something like "AutoCAD 2000 Type Library".

HTH
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top