That's a great thread. I'll have to take a close look, though as at first
pass it's over my head. Below I've pasted the portion of the code that
handles the looping. It's probably a mess, and I apologize for that... I'd
be thrilled to send you the entire project, but woulnd't want to impose.
As always, any help is appreciated!
Private Sub Plot_Only()
ResetProgress()
frmDLPlot.frmProgressForm.Show()
ReDim strDwgs(UBound(frmDLP.ardwgs2) - 1)
ReDim Preserve frmDLP.FinFileName(UBound(frmDLP.ardwgs2) - 1)
ReDim Preserve strDwgNumber(frmDLP.lstDrawings.Items.Count - 1)
Dim i As Integer = 0
Dim itemChecked As Object
'dwg.SetVariable("SDI", 1)
For i = 0 To UBound(frmDLP.ardwgs2) - 1
System.Windows.Forms.Application.DoEvents() 'check for outside event - ie.
CANCEL button click
If blnProgressCancel = True Then 'If the Cancel button is clicked then goto
EOF2
GoTo EOF2
Else
If InStrLast(frmDLP.FinFileName(i), "_") > 1 _
And loadini.blnDullesSpecial Then
loadini.blnDullesSpecialAutoCreate = True
Else : loadini.blnDullesSpecialAutoCreate = False
End If
' If Len(strFileName) > 0 Then
' otherwise process the drawing fro plotting
'PlotScale = loadini.strPlotScaleList(i) 'get the plot scale from the
loadini subr
'strFileName = loadini.strDrawingNameList(i) 'get the file name from the
loadini subr
PlotScale = frmDLP.FinPlotScale(i)
strFileName = frmDLP.FinFileName(i)
frmDLPlot.frmProgressForm.lblStatusDwgName.Text = strFileName
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Opening"
frmDLPlot.frmProgressForm.Update()
strDwgs(i) = loadini.strFilePath & strFileName & ".dwg" 'add the path and
".dwg"
If InStrLast(frmDLP.FinFileName(i), "_") = 1 _
And loadini.blnDullesSpecial Then
strDwgs(i) = loadini.strCompositeFilePath & strFileName & ".dwg"
End If
' If frmDLP.lstDrawings.GetItemChecked(i) = True Then 'See if the item is
checked and if so
If System.IO.File.Exists(strDwgs(i)) Then 'verify the drawing exists
If loadini.blnDullesSpecialAutoCreate = True Then
'If the file name has an underscore not in the first position
'"_" AND it is a dulles autocreate file then
Try
System.IO.File.Delete(strDwgs(i)) 'try to delete the file
Catch 'if it's open,
blnShowErrMessage = True 'add a line to the error message to be displayed at
the end
strFileErrorMsg = strFileErrorMsg & vbCr & frmDLP.FinFileName(i) & "
*OPENFILE*"
GoTo PLOTNEXT 'then move on to he next file
End Try 'end check for open dulles file
dwg = acad.Documents.Add(strDwgs(i)) 'if the file was deleted, create a new
file with the same name
acad.WindowState = AcWindowState.acMax 'maximize autocad
acad.ActiveDocument.WindowState = AcWindowState.acMax 'maximize the document
Else
AutoCADcommandRunning:
Try
dwg = acad.Documents.Open(strDwgs(i), False)
Catch ex As Exception
' Check for error message...
If ex.Message = "Call was rejected by callee." Then
acad.Visible() = True
MsgBox("**There is an active command in AutoCAD**" & vbCr & vbCr & _
"Click into AutoCAD and cancel the current AutoCAD command." & vbCr & vbCr &
_
"THEN return here press OK to continue the Batch Process",
MsgBoxStyle.Exclamation, "AutoCAD Busy")
GoTo AutoCADcommandRunning
End If
End Try
'if it is not a dulles SHEET drawing, just open it
acad.WindowState = AcWindowState.acMax 'maximize autocad
acad.ActiveDocument.WindowState = AcWindowState.acMax 'maximize the document
End If 'END IF loadini.blnDullesSpecial
ElseIf System.IO.File.Exists(strDwgs(i)) = False And
loadini.blnDullesSpecial Then 'otherwise if the file does not exist and is a
dulles sheet file
'MsgBox(strDwgs(i))
dwg = acad.Documents.Add(strDwgs(i)) 'just create it
acad.WindowState = AcWindowState.acMax 'maximize autocad
acad.ActiveDocument.WindowState = AcWindowState.acMax 'maximize the document
ElseIf System.IO.File.Exists(strDwgs(i)) = False And
loadini.blnDullesSpecial = False Then 'and finally, if the drawing does not
exist and it is not a dulles drawing, skip it,
blnShowErrMessage = True 'adding a line to the error message
strFileErrorMsg = strFileErrorMsg & vbCr & frmDLP.FinFileName(i) & " *NOT
FOUND*"
GoTo PLOTNEXT 'and goto the next drawing
End If 'END If System.IO.File.Exists(strDwgs(i))
'NEW DULLES DRAWING PROCESSING
If loadini.blnDullesSpecialAutoCreate = True And loadini.blnDullesSpecial
Then
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Creating Dulles Sheet"
frmDLPlot.frmProgressForm.Update()
dwg.SendCommand("(load ""NewDullesDwgCheck"")" & vbCr & "(NewDullesDwgCheck
" & """" & _
loadini.strCommission & """" & " " & """" & frmDLP.FinFileName(i) & """" & "
" & _
"""" & loadini.strDwgDirectory & """" & ")" & vbCr)
End If 'END InStrLast(loadini.strDrawingNameList(i), "_") > 1 And
loadini.blnDullesSpecial Then
'RUN MISC SCRIPTS
If frmDLP.chkDwup.Checked = True And loadini.blnDullesSpecialAutoCreate =
False Then 'Send DwuP command
dwg.SendCommand("dwup" & vbCr)
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Updating Border"
frmDLPlot.frmProgressForm.Update()
End If
If frmDLP.chkSpanner.Checked = True Then 'Send Spanner Update command
dwg.SendCommand("sheetall" & vbCr)
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Updating Spanner"
frmDLPlot.frmProgressForm.Update()
End If
If frmDLP.chkPurge.Checked = True Then 'Send PUA command
dwg.SendCommand("pua" & vbCr)
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Purging"
frmDLPlot.frmProgressForm.Update()
End If
If frmDLP.chkChgco.Checked = True Then 'Send Chgco command
dwg.SendCommand("chgco" & vbCr)
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Color BYLAYER"
frmDLPlot.frmProgressForm.Update()
End If
If frmDLP.chkZoomExt.Checked = True Then 'Send Zoom Extents
dwg.SendCommand("ze" & vbCr)
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Zooming"
frmDLPlot.frmProgressForm.Update()
End If
If frmDLP.chkAudit.Checked = True Then 'Send Audit Command
dwg.SendCommand("audit" & vbCr & "yes" & vbCr)
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Auditing"
frmDLPlot.frmProgressForm.Update()
End If
If Len(frmDLP.txtRevNum.Text) > 0 Then
If frmDLP.chkShowAllTri.Checked = True Then
strShowAllTri = "Y"
Else : strShowAllTri = "N"
End If
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Handling Revisions"
frmDLPlot.frmProgressForm.Update()
dwg.SendCommand("(revdisplay " & """" & frmDLP.txtRevNum.Text & """" & " " &
"""" & strShowAllTri & """)" & vbCr)
End If
If frmDLP.chkShowAllRev.Checked = True Then
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Handling Revisions"
frmDLPlot.frmProgressForm.Update()
dwg.SendCommand("(ALLREV_T)" & vbCr)
End If
If frmDLP.chkShowNoRev.Checked = True Then
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Handling Revisions"
frmDLPlot.frmProgressForm.Update()
dwg.SendCommand("(ALLREV_F)" & vbCr)
End If
' If Not frmDLP.cboStamps.Text = "No Stamp" Then
strPEStamp = frmDLP.FinPEStamp(i)
PlotWithStamp()
dwg.Regen(AcRegenType.acActiveViewport)
' End If
Dim USERI5 As String = "0"
If frmDLP.chkXrefLog.Checked = True Then
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Logging Xrefs"
frmDLPlot.frmProgressForm.Update()
dwg.Application.LoadDVB("G:\CAD Standards\HCYU
Standards\__HCYU\Lisp\XrefLog.dvb")
dwg.Application.RunMacro("G:\CAD Standards\HCYU
Standards\__HCYU\LISP\XrefLog.dvb!ThisDrawing.MakeXrefLog")
End If
If Not frmDLPlot.strProcess = "OPEN" Then
If frmDLPlot.strProcess = "PLOT" Or frmDLPlot.strProcess = "BOTH" Then
'frmProgress.Update()
DwgPlot(dwg, i) 'Plot this drawing
If frmDLPlot.strProcess = "PLOT" Then
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Closing"
frmDLPlot.frmProgressForm.Update()
dwg.Close(False)
End If
End If
If frmDLPlot.strProcess = "SAVE" Or frmDLPlot.strProcess = "BOTH" Then
'frmProgress.Update()
Dwgsave(dwg, i)
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Closing"
frmDLPlot.frmProgressForm.Update()
dwg.Close(False)
End If
End If
Dim intProgressCount As Integer =
frmDLPlot.frmProgressForm.prgProgress.Value
If Not intProgressCount >= frmDLPlot.frmProgressForm.prgProgress.Maximum
Then
intProgressCount += 1 ' add 1 to progress count
frmDLPlot.frmProgressForm.prgProgress.Value = intProgressCount
frmDLPlot.frmProgressForm.lblDwgProcessed.Text = intProgressCount.ToString
End If
PLOTNEXT:
End If
Next 'i
EOF2:
blnProgressCancel = False
If frmDLPlot.strSaveDest = "ARCHIVE" Then
frmDLPlot.frmProgressForm.lblStatusProcess.Text = "Archiving"
Dim objWriter As New System.IO.StreamWriter(frmArch.strArchiveList, True)
frmArch.strArchLog = loadini.strCommission & " , " & frmArch.strArchDesc & "
, " & loadini.strDiscipline & " , " & modBatchProcess.strDate & " , " &
Environ$("username")
objWriter.WriteLine(frmArch.strArchLog)
objWriter.Close()
End If
blnAcState = False
frmDLPlot.frmProgressForm.Hide()
'dwg.SetVariable("SDI", 0)
If blnAcadExist = False And frmDLP.radOpenOnly.Checked = False Then
If frmDLP.blnLeaveOpen = False Then
acad.Quit()
End If
End If
For i = 0 To UBound(frmDLP.arFinDwgList) - 1
frmDLP.arFinDwgList(i) = ""
Next
For i = 0 To UBound(frmDLP.FinPlotScale) - 1
frmDLP.FinPlotScale(i) = ""
Next
For i = 0 To UBound(frmDLP.FinFileNumber) - 1
frmDLP.FinFileNumber(i) = ""
Next
For i = 0 To UBound(frmDLP.FinFileName) - 1
frmDLP.FinFileName(i) = ""
Next
End Sub