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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access output to Autocad 1

Status
Not open for further replies.

HanKleppe

Programmer
Mar 17, 2005
50
0
0
NL
Dear Forummembers,

After Todd, helped me great with im/exporting Attributes to Access I'm in the next step of my little program.

I have a button in Access. When I click it, it opens Autocad and opens the primary key, what is a pathname.

Code:
Dim X, Y
Y = "C:\Program Files\AutoCAD 2004\acad.exe " & [Forms]![Formulier1]![Tekst31]
X = Shell(Y, 1)
End Sub

Now I want Access to print. /p is usually by office programs but doesn't work in autocad.

I have also a field in the table containing the number of printing files. I want Autocad use this number to his printnumber.

Who can give me a kick in the good way?

Thanks!
 
Hi Han,

Thanks for the kind words about the FAQ I wrote!

Do you want Access to print a report or datasheet or do you want to have AutoCAD plot the drawing it just opened?

Todd
 
Hi Todd,

No blaming (hope this is the good word :) You're help is for me very helpfull!

I open AutoCAD with this script:

Code:
Dim X, Y
Y = "C:\Program Files\AutoCAD 2004\acad.exe " & [Forms]![Formulier1]![Tekst31]
X = Shell(Y, 1)
End Sub

The field [Tekst31] is the primarykey (the complete fieldname)

I would send some parametres with the script, something like this:

Print, printing numbers: [fieldblabla]\
I place your import code in de acad.dvb file so it loads automatically.

I guess it's pretty simple to execude

HTH :)

Han
 
Hi Han,

AutoCAD doesn't make use of any command line switches for plotting but does for utilizing a script. If you have a plotting script you can just tell AutoCAD to utilize the script after it opens the drawing file:

Code:
Dim X, Y
Y = "C:\Program Files\AutoCAD 2004\acad.exe " & [Forms]![Formulier1]![Tekst31] & " /b "C:\Plot.scr"
X = Shell(Y, 1)
End Sub

If that's not a good solution, you can utilize VB/VBA to plot the file.

HTH
Todd
 
Hi Todd,

I can make this but i guess i can't set a link between Access and AutoCAD.
The most optimal situation would be, that AutoCAD checks the tabel for the number of copies.
Do you know how to make this?

Gr,
Han
 
Hi Han,

Sure, I would drop the script option, and then use VB to plot instead of the script routine, one of the plot objects properties is number of prints, which would obviously just come from your table.

HTH
Todd
 
Hi Todd,

Can you explain your text above :)
I'm terribly sorry :) Must give some script?

Thanks in forward!

Han
 
Hi Han,

After you start AutoCAD with your shell call, you'll then just want to connect to the running session of AutoCAD, and get a reference to the drawing it opened:
Code:
Dim AcadApp As AcadApplication
Dim AcadDoc As AcadDocument

Set AcadApp = GetObject(,"AutoCAD.Application")
Set AcadDoc = AcadApp.ActiveDocument
Now, set the number of plots you want:
Code:
intPlotCopies = [Forms]![Formulier1]![Copies]
AcadDoc.ActiveLayout.Plot.NumberOfCopies = intPlotCopies
Then, just tell AcadDoc to plot the drawing you opened with your shell command (in this case, AutoCAD will plot to the default system printer):
Code:
AcadDoc.Plot.PlotToDevice

HTH
Todd
 
Hi Todd,

I have the following code:

Code:
Private Sub Knop44_Click()
Dim X, Y

Y = "C:\Program Files\AutoCAD 2004\acad.exe print " & [Forms]![Formulier1]![Tekst31]
X = Shell(Y, 1)

Dim AcadApp As AcadApplication
Dim AcadDoc As AcadDocument

Set AcadApp = GetObject(, "AutoCAD.Application")
Set AcadDoc = AcadApp.ActiveDocument

intPlotCopies = [Forms]![Formulier1]![Copies]
AcadDoc.ActiveLayout.Plot.NumberOfCopies = intPlotCopies

AcadDoc.Plot.PlotToDevice

End Sub

When I run it I get the following failure:

Compilererror:
An user definition type is not definitioned, or something like that.

The following code is highlighted:

Code:
Dim AcadApp As AcadApplication

Is it possible, that after the printing, AutoCAD close automatically?

like: AcadDoc.Exit?

Greetz,
Han
 
Hi Han,

Since your code is residing in Access, you'll need to set a reference to AutoCAD (Should read something like "AutoCAD 2000 Type Library") in your references dialog box.

HTH
Todd
 
Hi Todd,

I select 3 of the relevant AutoCAD references:

AutoCAD/ObjectDBX Common 16.0 Type Library
AutoCAD 2004 Type Library
AutoCAD Focus Control for VBA Type Library
(in good priority)

I tried with several priorities. When I select one of the 2 down, (2004 and Focus Control) it gives an error that he can't find the right thing
When I tried van ObjectDBX, Access returns the following error:

429 ActiveX part can't make an object

With which programs do you run your applications?

Han
 
Hi Han,

Just use this one "AutoCAD 2004 Type Library" it should be all you need.

Todd
 
Hi Todd,

Strange strange strange. I removed the map DAO in the common files en reinstalled office, but no success.
After the new install access picks the Type library so that's also good...
Does the code work by you?

Gr,
Han
 
Hi Han,

I have to admit, I've had strange results trying to run AutoCAD from Access myself and finally gave up on it, but I was hoping you'd have better luck. The code I have, I never run from Access - I just use Access as the database.

You might consider reworking your code to run from AutoCAD?

HTH
Todd
 
Hi Todd,

Is it possible to make the code work? Or have I to look for another solution?
Maybe AutoCAD can contain such codes?

Gr,
Han
 
Hi Han,

Sorry for the late reply. I'm sure you could, I just don't know how. You could embed the print information in the drawing somewhere, but I think you'll have an easier time keeping that information in the database. I know you are trying to edit the data in Access and then have Access print/plot the drawings after updating (which makes sense) but what about building a form through AutoCAD VBA to edit the data? It's not quite the same but should get you there.

HTH
Todd
 
Hi Todd,

Is it possible to make an addition on the file i allready have? I setup the file runs everytime I startup AutoCAD.
The link is allready set, I think we need the right codes.

What is the command in AutoCAD for printing? (not the P in the mainscreen, but in vba?)
After that we can maybe to read the information of a tabel in access to print the numbers...

TIF (my new sign, Thanks in Forward :eek:))

Han
 
Hi Han,

Of course! Here's the syntax for plotting from VBA:

Code:
AcadDoc.Plot.PlotToDevice

HTH
Todd
 
Hi Todd,

Thanks! I'm gonna try it tommorow. Do you also know the code to exit AutoCAD with automatically save your drawing?

TIF

Han
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top