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!

Controlling AutoCAD from Excel 1

Status
Not open for further replies.

AcousticalConsultant

Technical User
Sep 20, 2001
45
CA
Hello,

I've created a VBA program within AutoCAD which creates a graph based on user input values. The program contains a class for the graph itself and a class for each curve that is plotted. It works great within AutoCAD, but I would like to extend the functionality to within Excel. That is, I would like to have a macro in Excel that allows the user to highlight the cells which he would like graphed and then the macro creates a graph in AutoCAD using my program.

As I see it, there are two ways of doing this and I can't seem to get either of them to work. The first (preferred) way is to be able to use my user-defined classes inside Excel so that when I instantiate a class, it would perform the work within AutoCAD. I've already linked a reference to AutoCAD and I can define AutoCAD types, but it doesn't see my own classes. How can I reference user-defined classes?

The other way would be to simply gather all the values inside Excel and pass them all into AutoCAD. However, I seem to only be able to "Run" an AutoCAD macro from within Excel. It doesn't let me pass any values or parameters.

I guess a final way would be for Excel to create a text file, dump all the data in there and then have AutoCAD retrieve it. But if possible, I would like the first method to work. It just seems like the most elegant solution.

Any ideas?

Oh, while I'm at it, about the part of letting the user highlight cells in Excel, when a user form is loaded, the user can't do anything other than interact with the form. Is there any way to have a user-form write "Select the desired cells" and allow the user the control to select them, like when creating a graph in Excel, you can click the little "select values" icon and as you drag and select cells, it automatically enters the formula into the textbox.

Any help is appreciated!
Thanks!
 
Hi AcousticalConsultant,

Adding a reference to AutoCAD won't let you see user defined classes in VBA. You'll need to have AutoCAD load your VBA project containing your classes and then access them just like you would another macro from outside AutoCAD.

To pass your values to an AutoCAD macro, just use the Command function (in VB not AutoCAD).

HTH
Todd
 
What I did was actually just make a few minor changes to my classes and I copied them directly into Excel. That way I can create objects of type "Graph" inside Excel, but it will actually create the graph inside AutoCAD.

Works well! Thanks for the info though.

However, while I'm at it, I have another question. How do I alternate the active window between Excel and AutoCAD? I want to bring up the appropriate window so that the user can see what's happening without having to click the taskbar himself.

Thanks again!
 
Hi AcousticalConsultant,

ThisDrawing.Application.WindowState = acMin (or acMax) for AutoCAD - Excel is similar - look under the application object in Excel.

HTH
Todd
 
Hi TCarpenter,

I already tried the .WindowState property. While it does minimize and maximize the window, it still doesn't make it the window active. It simply minimizes or maximizes the window in the background, but if another window is on top of it, the user never even knows. Same sort of thing as making the .Visible property FALSE and then TRUE again... it doesn't change the active window that the user sees.

If you know of another method, please let me know!

Thanks!
Pascal
 
Hi AcousticalConsultant,

In addtion to the min max stuff, add this into your Excel side of things:

Code:
...
  Dim AutoCADAppID
  Dim AcadApp As AcadApplication
  
  Set AcadApp = GetObject(, "AutoCAD.Application")
     
  AutoCADAppID = AcadApp.Caption
  
  AppActivate AutoCADAppID

HTH
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top