VBA Plotting and the BACKGROUNDPLOT Variable

This Summer promises to be a busy one. I am in the final stages of an across the board upgrade to AutoCAD 2005 products. This involves 130+ PCs with different software packages including Architectural Desktop, Building Systems, Land Development Desktop, Revit and of course Civil3D. I was just about ready to sign off on this and begin prep for the 2006 upgrade (slated for September), when my phone and email started to get overloaded.

When I started receiving a slew of complaints from users who claimed the batch plot program was broken, I knew there was something amiss. These users have been successfully plotting multiple files in our VBA powered Batch Plot program since Release 14 without trouble, but now they would submit multiple plots only to discover that but a few actual plots were coming out of the plotters….

I scratched my head for a while and then reviewed the readme file from the installation cd.

I found the following information in the readme:

Publish. Background Plotting in Architectural Desktop has been set to 0 (Off for Plotting and Publishing) by default. Should you encounter problems plotting or publishing using Background mode, please try the operation using Foreground mode. Specific issues listed below.

When Publishing to a Plotter named in the page setup with Background Plotting ON, the drawing(s) are not properly regenerated for Plot. Please use Foreground Plotting to Publish the drawing(s).

Aha! A clue, but nothing directly mentioning VBA in any of the sections, so I continued searching. I finally saw a little mention in the help file about plotting in the foreground in VBA. The help file mentions “To plot in the foreground using VBA, you must set the BACKGROUNDPLOT system variable to 0. Otherwise, plotting occurs in the background.”

Background plotting? Sounds cool!…but something was breaking the program, so I began stepping through code and found, to my horror, that merely setting the correct CTB file in a layout object without FIRST forcing foreground plotting simply resulted in an error. Further testing confirmed this, so My recommendation is to ensure that the system variable “BACKGROUNDPLOT” is set to 0 prior to plotting in VBA. It’ll save you a few gray hairs!

Here are a couple of functions to assist you in toggling this variable:

Add a standard module to your VBA project or drop the following declarations and functions into an existing module.

Public var_BGPlot As Variant

‘——————————————————-
‘ Function : getBackPlot
‘ DateTime : 6/30/2005 09:05
‘ Author : Richard L Binning
‘ Purpose :
‘——————————————————-

Function getBackPlot(ByRef var_BGPlot As Variant) As Boolean

Dim bResult As Boolean

On Error GoTo getBackPlot_Error
var_BGPlot = ThisDrawing.GetVariable(“BACKGROUNDPLOT”)
ThisDrawing.SetVariable “BACKGROUNDPLOT”, 0
bResult = True
getBackPlot = bResult

On Error GoTo 0
Exit Function

getBackPlot_Error:

MsgBox “Error ” & Err.Number & ” (” & Err.Description & “) _
in procedure getBackPlot of Module Module1″

End Function

‘——————————————————
‘ Function : setBackPlot
‘ DateTime : 6/30/2005 09:06
‘ Author : Richard L Binning
‘ Purpose :
‘——————————————————

Function setBackPlot(ByRef var_BGPlot As Variant) As Boolean

Dim bResult As Boolean

On Error GoTo setBackPlot_Error
ThisDrawing.SetVariable “BACKGROUNDPLOT”, var_BGPlot
bResult = True
setBackPlot = bResult

On Error GoTo 0
Exit Function

setBackPlot_Error:

MsgBox “Error ” & Err.Number & ” (” & Err.Description & “) _
in procedure setBackPlot of Module Module1″

End Function

Now you can use these functions by calling getBackPlot as part of your initialization code like this:

Call getBackPlot(var_BGPlot)

or like this:

If getBackPlot(var_BGPlot) then
‘do something here
else
‘exit cleanly here or popup a warning
End If

When your plot routine is complete don’t forget to call setBackPlot to return the users BACKGROUNDPLOT variable to the original setting. You can use the above calling example for getBackPlot as the model for calling setBackPlot.

Happy plotting…

Do You See What I See? Video for Skype

Do you Skype? This voip favorite among geeks now has a video plugin from Dialcom.
Of course, you’re going to need a broadband connection, a 400mhz or better processor, and 128mb Ram minimum, but who doesn’t these days! Want to try it out? Visit Dialcom.

First link submitted via email from the Slashdot RSS feed by Dick Teller.