Select to view content in your preferred language

Export to Image by VBA from outside ArcMap fails

1238
11
09-29-2011 08:53 AM
DanielFuchs
Emerging Contributor
I know a rather similar topic has been around before, but without a really satisfying answer, so I'll try again.

I wrote a short export routine in VBA that simply exports the current PageLayout to a PDF file, and if run from within ArcMap it works fine. But if I put the same function in a module in MSAccess and run it from there it produces a blank page (of the right dimensions, however). All other ArcMap automation run from MSAccess works ok, e. g. if I set the layout zoom factor to 100 or refresh the page layout, that's done. Only the export itself produces a blank page.

The actual code is attached although as I said it's working in ArcMap. I very much hope someone out there has a solution - thanks in advance.

Daniel
0 Kudos
11 Replies
DubravkoAntonic
Occasional Contributor
Neil is right factories are right way to use ArcObjects when outside ArcMap thread.
You can not acquire valid IApplication if ArcMap is not running which is not a problem in this case.

I  didn't experimented much with inter process communication but for clear  approach in using ArcObjects I suggest for you to create tool within ArcMap that will do the job for you and return you result.

But anyway, this piece of code will acquire for you IApplication reference

Type t = Type.GetTypeFromProgID("esriFramework.AppRef");
System.Object obj = Activator.CreateInstance(t);
ESRI.ArcGIS.Framework.IApplication pApp = obj as  ESRI.ArcGIS.Framework.IApplication;


Regards Dubravko
0 Kudos
JacelyneJanoka
New Contributor
I know a rather similar topic has been around before, but without a really satisfying answer, so I'll try again.

I wrote a short export routine in VBA that simply exports the current PageLayout to a PDF file, and if run from within ArcMap it works fine. But if I put the same function in a module in MSAccess and run it from there it produces a blank page (of the right dimensions, however). All other ArcMap automation run from MSAccess works ok, e. g. if I set the layout zoom factor to 100 or refresh the page layout, that's done. Only the export itself produces a blank page.

The actual code is attached although as I said it's working in ArcMap. I very much hope someone out there has a solution - thanks in advance.

Daniel


When you export to a PDF in ArcMap the program uses the drivers from your default printer to "print" to the PDF.  If you have your default printer set to an XPS document writer or anything other than a physical printer, it will produce a blank document of the right dimensions exactly like you've described.  Try setting your default printer in MSAccess to the printer or plotter you use for ArcMap.  It may go through the same process as ArcMap.
0 Kudos