I am using the EModelViewControl in excel VBA as I have for the last several versions of the eDrawings control. Unfortunately, with the version 2009 control, the printing does not work without showing the print dialog box. I was able to do this with the 2008 and previous controls. Simplified and stripped down to the bare essentials, this is the code I am using. I have tried using the control embedded on a worksheet and with the control on a windows form. Both times, if the first parameter after Print3 is False, nothing happens and a "FailedPrinting" event is triggered. If I change it to True, the print dialog pops up and the user click ok and everything prints normally. This always worked great before without user intervention as a batch print tool, but now not so much. Is anyone using "EModelViewControl1.Print3 False,..." successfully?
Private Sub CommandButton1_Click()
EModelViewControl1.OpenDoc "C:\\TestPrint.slddrw", False, False, True, ""
End Sub
Private Sub EModelViewControl1_OnFinishedLoadingDocument(ByVal FileName As String)
EModelViewControl1.SetPageSetupOptions EMVPrintOrientation.eLandscape, 1, 1, 1, 1, 7, "\\\\OurPrintServer\\OurPrinterName", 0, 0, 0, 0
EModelViewControl1.Print3 False, EModelViewControl1.FileName, False, False, False, EMVPrintType.eScaleToFit, 1, 0, 0
End Sub
Private Sub EModelViewControl1_OnFinishedPrintingDocument(ByVal PrintJobName As String)
EModelViewControl1.CloseActiveDoc ("")
End Sub
Private Sub EModelViewControl1_OnFailedPrintingDocument(ByVal PrintJobName As String)
MsgBox "Trapped failed print event"
End Sub

Well, I tried using the name of a couple other printers on the network and a pdf printer driver on my system, but there was no difference. It still won't print anymore without opening the print window. I tried many combinations of formatting the printer name in ways that the function might have been changed to ask for, but nothing worked. Unless somebody can verify that this control function still works, I have to beleive that it is broken.
Thanks for the suggestions and if you have any others, I would definately give them a try.
Mark
I am trying to write a program progaram for this also. I am getting my list of documents from an Excel sheet. If there is one file on the sheet it works fine, if there is more than one it only prints the last file. My program does not seem to be waiting for the EModelViewControl1_OnFinishedPrintingDocument sub, it just keeps looping through the list without pausing so it dosent close the active doc before opening the next doc.
Dan Miel
Sorry, should have included my setup in the original post.
I am using 32 bit Windows XP SP3 on an HP xw4400 workstation with Intel Core2 6700 @ 2.67 Ghz and 4MB Ram. Video is nVidia Quadro FX 1500 w/ version 182.46 drivers. SolidWorks version 2009 SP 4.0, eDrawings version 9.4.0.129 (2009 SP4).
Well, in my case using the value "False" in the PrintDialog parameter of the Print2 or Print3 function causes a "FailedPrint" event, so the "FinishedPrinting" event is never triggered so the loop stops. If I set the value to "True", the print dialog pops up and the user clicks ok and then the next document is opened. It is slower, but it works with user intervention.
What I do if all of the sheets that I want to print have been printed is close the existing doc and open the next document inside of the "FinishedPrinting" event. I also close the existing document and open the next one immediately on a "FailedPrinting" event. The "FinishedLoading" event triggers the print function, so the next document won't be loaded until either the print finishes on the previous document or it fails.
SW 2009 SP 9.4 32bit.
Sub PrintDocs()
Dim FileName As String
Dim TL As Long
'LOOP THROUGH COLLECTION OF DOCUMENTS
For TL = 1 To cAlldocs.Count
FileName = cAlldocs(TL)
Me.EModelViewControl1.OpenDoc Fold & FileName, False, False, False, ""
Next TL
End Sub
Private Sub EModelViewControl1_OnFinishedPrintingDocument(ByVal PrintJobName As String)
MsgBox PrintJobName & " is printed OnFinishedPrintingDoc"
End Sub
Private Sub EModelViewControl1_OnFailedPrintingDocument(ByVal PrintJobName As String)
MsgBox "Trapped failed print event"
End Sub
Private Sub EModelViewControl1_OnFinishedLoadingDocument(ByVal FileName As String)
'After loading doc should print and close doc
Me.EModelViewControl1.SetPageSetupOptions eLandscape, 1, 0, 0, 1, 7, "\\ps1\Engineering - bw", 0, 0, 0, 0
Me.EModelViewControl1.Print4 False, Me.EModelViewControl1.Name, False, False, False, eScaleToFit, 0, 2, 2, True, 1, 1
MsgBox FileName & " is finished loading."
EModelViewControl1.CloseActiveDoc ("")
End Sub
Try this, but keep in mind that I have not tried it out. I created a new sub named OpenNextDoc to call for opening all docs after the first one. It will close the active doc, increment the counter then load the next one causing it to be printed until the list is exhausted. PrintDocs starts the process by loading the document. No For...Next loop is needed. The triggered events take care of the rest...
Dim TL As Long
Sub PrintDocs()
Dim FileName As String
TL = 1
FileName = cAlldocs(TL)
Me.EModelViewControl1.OpenDoc Fold & FileName, False, False, False, ""
End Sub
Sub OpenNextDoc()
Dim FileName As String
EModelViewControl1.CloseActiveDoc ("")
TL = TL +1
If TL < cAlldocs.Count +1 then
FileName = cAlldocs(TL)
Me.EModelViewControl1.OpenDoc Fold & FileName, False, False, False, ""
End If
End Sub
Private Sub EModelViewControl1_OnFinishedPrintingDocument(ByVal PrintJobName As String)
MsgBox PrintJobName & " is printed OnFinishedPrintingDoc"
OpenNextDoc
End Sub
Private Sub EModelViewControl1_OnFailedPrintingDocument(ByVal PrintJobName As String)
MsgBox PrintJobName & " failed to print"
OpenNextDoc
End Sub
Private Sub EModelViewControl1_OnFinishedLoadingDocument(ByVal FileName As String)
'After loading doc should print and close doc
MsgBox FileName & " is finished loading."
Me.EModelViewControl1.SetPageSetupOptions eLandscape, 1, 0, 0, 1, 7, "\\ps1\Engineering - bw", 0, 0, 0, 0
Me.EModelViewControl1.Print4 False, Me.EModelViewControl1.FileName, False, False, False, eScaleToFit, 0, 2, 2, True, 1, 1
End Sub
Dan
Dan,
Where are you getting the Print4 method for the EmodelViewControl?
It is in the 2009 IEModelViewControl - Methods.
Dan
This worked Mark. Looping back through the OpenNextDoc sub at the end of the OnFInishedPrint Sub seems to be working.
Thanks for the input.
Dan
Hi Luke
It looks like just the program flow is fixed. I replaced my Print4 with the Print3 and recieved a "failed to print" error. I put the Print4 back in and it worked fine. This is the second program I've written using print4, I have not written any with Print3.
Dan Miel
SW2009 SP4.1
The undocumented Print4 method is the solution. I received an email reply from SolidWorks apisupport confirming the need for using the Print4 method for 2009 SP4 and later versions eDrawings.
I believe it is a VBA issue. What I have found is that if I place the control directly on an Excel worksheet, I only have Print2 and Print3 available, but if I place the control on a form inside the Excel document, I have Print4 available. I have changed my program to load the control in a form instead of the worksheet and it is now working well.
This discrepancy is easily verifiable using the example provided in the eDrawings SDK using the eDrawings_Excel.xls example. Create an “eDrawings 2009 Control” on Sheet1 and look at what methods are available in the code window. Compare this to what is available to the control in the UserForm1 code.
The availability of Print4 also depends on what version of eDrawings the user has installed on their system. If they have 2009 SP4 or later, you must use the Print4 method. Otherwise, you must use the Print3 method. So, I added a piece of code provided by apisupport to my program.
If EModelViewControl1.Version = "eDrawings 2009 sp04" Then
Me.EModelViewControl1.Print4 False, FileName, False, False, False, eScaleToFit, 1, 0, 0, False, 1, 1
Else
Me.EModelViewControl1.Print3 False, FileName, False, False, False, eScaleToFit, 1, 0, 0
End If