Message 1 of 9
batch plotting program
Not applicable
12-13-2006
08:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've had a lot of help from this forum and I have completed my batch plotting program. I originally did it in lisp, but that wasn't very good and didn't work some of the time, not to mention taking ages.
the program is in two modules:
'sub for getting each dwg in a directory and then using the plotdwf sub to plot them
Public Sub listfiles()
Dim MyFiles As String
Dim pathName As String
Dim expVar As Integer
Dim backplotVar As Integer
pathName = InputBox("Enter directory path")
'MsgBox pathName
If Dir(pathName & "\plot", vbDirectory) = "" Then
MkDir (pathName & "\plot")
End If
MyFiles = Dir(pathName & "\*.dwg")
If (MyFiles = "") Then
MsgBox "Not a valid directory or does not contain any .dwg files"
End
End If
'set expert mode to 1 (no regen popup message)
expVar = ThisDrawing.GetVariable("EXPERT")
ThisDrawing.SetVariable "EXPERT", 1
'set background plot to 0 (plots in foreground, else shits itself)
backplotVar = ThisDrawing.GetVariable("BACKGROUNDPLOT")
ThisDrawing.SetVariable "BACKGROUNDPLOT", 0
Do While (MyFiles <> "")
'MsgBox MyFiles
ThisDrawing.Application.Documents.Open (pathName & "\" & MyFiles)
plotdwf (pathName)
'If ThisDrawing.GetVariable("Diastat") = 1 Then
'MsgBox "Plot Sent", vbOKOnly
'End If
ThisDrawing.Close
MyFiles = Dir
Loop
'restore system variables
ThisDrawing.SetVariable "EXPERT", expVar
ThisDrawing.SetVariable "BACKGROUNDPLOT", backplotVar
End Sub
and
'plots a dwf with the set parameters to a folder called 'plot' within the file's directory (taken from the pathname2 variable)
Public Sub plotdwf(pathName2 As String)
Dim ACADLayout As ACADLayout
Dim lowleft(1) As Double
Dim upright(1) As Double
Dim originalValue As Boolean
Dim plottablestyles As String
Dim plotfile As Boolean
Dim fname As String
'define window
lowleft(0) = 0
lowleft(1) = 0
upright(0) = 840.1415
upright(1) = 593.6786
'set plot style to acad.ctb
Set ACADLayout = ThisDrawing.ActiveLayout
On Error Resume Next
ACADLayout.StyleSheet = "acad.ctb"
ACADLayout.SetWindowToPlot lowleft, upright
ACADLayout.PlotType = acWindow
ACADLayout.StandardScale = acScaleToFit
plottablestyles = ACADLayout.StyleSheet
'MsgBox "Plot style" & plottablestyles
originalValue = ACADLayout.PlotWithPlotStyles
'MsgBox "The PlotWithPlotStyles value is set to: " & originalValue
'plot file
fname = Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 4)
'MsgBox "plot file name " & fname
plotfile = ThisDrawing.Plot.PlotToFile(pathName2 & "\plot\" & fname, "DWF6 ePlot.pc3")
End Sub
The script asks for a directory to process, and then plots all the dwg files in that folder, and puts the plots in a folder called 'plot' within the directory.
at the moment it is plotting to a window with the specified dimensions (lowleft(0) = lower x, lowleft(1) = lower y, and same for upright), but i usually plot to extents, which only requires minor modification:
comment out the line ' ACADLayout.SetWindowToPlot lowleft, upright' and change the plot type to acExtents.
the other attributes (plot style, scale, etc) can be changed easily as well, and if someone feels like it, they can make it more user friendly so that options can be selected from a message box and the code does not need to be modified.
the program is in two modules:
'sub for getting each dwg in a directory and then using the plotdwf sub to plot them
Public Sub listfiles()
Dim MyFiles As String
Dim pathName As String
Dim expVar As Integer
Dim backplotVar As Integer
pathName = InputBox("Enter directory path")
'MsgBox pathName
If Dir(pathName & "\plot", vbDirectory) = "" Then
MkDir (pathName & "\plot")
End If
MyFiles = Dir(pathName & "\*.dwg")
If (MyFiles = "") Then
MsgBox "Not a valid directory or does not contain any .dwg files"
End
End If
'set expert mode to 1 (no regen popup message)
expVar = ThisDrawing.GetVariable("EXPERT")
ThisDrawing.SetVariable "EXPERT", 1
'set background plot to 0 (plots in foreground, else shits itself)
backplotVar = ThisDrawing.GetVariable("BACKGROUNDPLOT")
ThisDrawing.SetVariable "BACKGROUNDPLOT", 0
Do While (MyFiles <> "")
'MsgBox MyFiles
ThisDrawing.Application.Documents.Open (pathName & "\" & MyFiles)
plotdwf (pathName)
'If ThisDrawing.GetVariable("Diastat") = 1 Then
'MsgBox "Plot Sent", vbOKOnly
'End If
ThisDrawing.Close
MyFiles = Dir
Loop
'restore system variables
ThisDrawing.SetVariable "EXPERT", expVar
ThisDrawing.SetVariable "BACKGROUNDPLOT", backplotVar
End Sub
and
'plots a dwf with the set parameters to a folder called 'plot' within the file's directory (taken from the pathname2 variable)
Public Sub plotdwf(pathName2 As String)
Dim ACADLayout As ACADLayout
Dim lowleft(1) As Double
Dim upright(1) As Double
Dim originalValue As Boolean
Dim plottablestyles As String
Dim plotfile As Boolean
Dim fname As String
'define window
lowleft(0) = 0
lowleft(1) = 0
upright(0) = 840.1415
upright(1) = 593.6786
'set plot style to acad.ctb
Set ACADLayout = ThisDrawing.ActiveLayout
On Error Resume Next
ACADLayout.StyleSheet = "acad.ctb"
ACADLayout.SetWindowToPlot lowleft, upright
ACADLayout.PlotType = acWindow
ACADLayout.StandardScale = acScaleToFit
plottablestyles = ACADLayout.StyleSheet
'MsgBox "Plot style" & plottablestyles
originalValue = ACADLayout.PlotWithPlotStyles
'MsgBox "The PlotWithPlotStyles value is set to: " & originalValue
'plot file
fname = Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 4)
'MsgBox "plot file name " & fname
plotfile = ThisDrawing.Plot.PlotToFile(pathName2 & "\plot\" & fname, "DWF6 ePlot.pc3")
End Sub
The script asks for a directory to process, and then plots all the dwg files in that folder, and puts the plots in a folder called 'plot' within the directory.
at the moment it is plotting to a window with the specified dimensions (lowleft(0) = lower x, lowleft(1) = lower y, and same for upright), but i usually plot to extents, which only requires minor modification:
comment out the line ' ACADLayout.SetWindowToPlot lowleft, upright' and change the plot type to acExtents.
the other attributes (plot style, scale, etc) can be changed easily as well, and if someone feels like it, they can make it more user friendly so that options can be selected from a message box and the code does not need to be modified.