gdoyen
November 8, 2018, 1:57pm
1
Hello
I'm trying to create a macro that allows you to print drawings automatically. That is to say that I want the macro to read the page size and depending on the format select the right printer with the right settings.
To read the format of the sheets of a drawing I don't have too much problem but to select the right printer with the right settings I stall.
Basically, the little bit of code should look like this:
Select Case format
Case "A4"
Print "imprimante_par_defaut"
With quelquechose
.Orientation = xlPortrait
.format = A4
.echelle = 100
.feuille_en_cours = true
Case "A3"
Print "imprimante_par_defaut"
With quelquechose
.Orientation = xlLandscape
.format = A3
.echelle = 100
.feuille_en_cours = true
Case "A2"
Print "traceur"
With quelquechose
.Orientation = xlLandscape
.format = A2
.echelle = 100
.feuille_en_cours = true
Has anyone ever done this?
Thank you in advance,
Kind regards
Gautier.
gdoyen
November 8, 2018, 5:17pm
2
It's okay I succeeded, with some difficulties but the macro works very well now.
For those who are interested, here is the code:
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swModelDocExt = swModel.Extension
swModelDocExt.UsePageSetup = swPageSetupInUse_e.swPageSetupInUse_Document
Set swPageSetup = swDraw.PageSetup
vSheetNames = swDraw.GetSheetNames
For i = 0 To UBound(vSheetNames)
swDraw.ActivateSheet (vSheetNames(i))
Set swSheet = swDraw.GetCurrentSheet
vProps = swSheet.GetProperties
FormatPapier = vProps(0)
Echelle_1 = vProps(2)
Echelle_2 = vProps(3)
Select Case FormatPapier
Case 7 'A4
swPageSetup.Orientation = 1
swPageSetup.PrinterPaperSize = 9
Set printSpec = swModelDocExt.GetPrintSpecification
printSpec.ConvertToHighQuality = True
printSpec.AddPrintRange 1, 1
printSpec.FromScale = Echelle_1
printSpec.ToScale = Echelle_2
printSpec.ScaleMethod = 1
printSpec.PrinterQueue = "Charges_Affaires"
printSpec.PrintToFile = False
swModelDocExt.PrintOut4 "", "", printSpec
Case 8 'A3
swPageSetup.Orientation = 2
swPageSetup.PrinterPaperSize = 8
Set printSpec = swModelDocExt.GetPrintSpecification
printSpec.ConvertToHighQuality = True
printSpec.AddPrintRange 1, 1
printSpec.FromScale = Echelle_1
printSpec.ToScale = Echelle_2
printSpec.ScaleMethod = 1
printSpec.PrinterQueue = "Charges_Affaires"
printSpec.PrintToFile = False
swModelDocExt.PrintOut4 "", "", printSpec
Case 9 'A2
swPageSetup.Orientation = 2
swPageSetup.PrinterPaperSize = 66
Set printSpec = swModelDocExt.GetPrintSpecification
printSpec.ConvertToHighQuality = True
printSpec.AddPrintRange 1, 1
printSpec.FromScale = Echelle_1
printSpec.ToScale = Echelle_2
printSpec.ScaleMethod = 1
printSpec.PrinterQueue = "Traceur_Canon"
printSpec.PrintToFile = False
swModelDocExt.PrintOut4 "", "", printSpec
Case 10 'A1
swPageSetup.Orientation = 2
swPageSetup.PrinterPaperSize = 4403
Set printSpec = swModelDocExt.GetPrintSpecification
printSpec.ConvertToHighQuality = True
printSpec.AddPrintRange 1, 1
printSpec.FromScale = Echelle_1
printSpec.ToScale = Echelle_2
printSpec.ScaleMethod = 1
printSpec.PrinterQueue = "Traceur_Canon"
printSpec.PrintToFile = False
swModelDocExt.PrintOut4 "", "", printSpec
Case 11 'A0
swPageSetup.Orientation = 2
swPageSetup.PrinterPaperSize = 4401
Set printSpec = swModelDocExt.GetPrintSpecification
printSpec.ConvertToHighQuality = True
printSpec.AddPrintRange 1, 1
printSpec.FromScale = Echelle_1
printSpec.ToScale = Echelle_2
printSpec.ScaleMethod = 1
printSpec.PrinterQueue = "Traceur_Canon"
printSpec.PrintToFile = False
swModelDocExt.PrintOut4 "", "", printSpec
End Select
Next i
MsgBox ("Impression terminée!")
printSpec.RestoreDefaults
printSpec.ResetPrintRange
End Sub
1 Like
gdoyen
November 9, 2018, 11:29am
3
I'm back to the charge for automatic printing.
I have an option on my plotter to orient the paper so that I have as little shedding as possible depending on the format. However, I can't find the option to activate this option in vba.
Has anyone ever used or manipulated this option?
Thank you in advance
Gautier D.
Hello
If you have the MyCad suite, you can use PowerPrint to do all of this!