@Alfred.NESWADBA wrote:
Hi,
>> PlotToFile, it works but it takes 25 sec. for each drawing
It depends on file content, on amount of text (and how it is handled) and the settings in "DWG to PDF.PC3" (or whatever driver you use), can you show a drawing and it's settings (run _ETRANSMIT so we get your PC3 and PMP if there is one assigned).
BTW: what time do you expect?
>> when I do it manually on AutoCad but it doesn't work via VBA
What means "does not work"? Crash? Error message? Incorrect PDF content? Anything else ...?
And what code "does not work", I guess you have to show it so we can look into it and try it on our systems.
- alfred -
Hi Alfred,
Sorry if I left not enough informations about my issue.
- About the PlotToFile method duration, I didn't expect too much but if every of my 100 drawing takes so long it will take 25 minutes to have a PDF. I know that I can make a Publish with every of them to earn a lot of time but the point is to make PDF from various documents (including DWG) from a list at the same time so I must use something that plot each DWG separately to keep the order. Furthermore, the export method is almost immediate so I'm a bit frustrated by the 25 sec. of the PlotToFile method. Ah and I tried with a DWG with only 4 blocs inserted, it took 25 sec too.
I use "DWG to PDF.PC3" indeed, here is the code I have :
Sub DWGtoPDF(dwg As AcadDocument, Ligne As String)
Dim PtConfigs As AcadPlotConfigurations
Dim PlotConfig As AcadPlotConfiguration
Dim PtObj As AcadPlot
Dim BackPlot As Variant
Dim NomComplet As String
Dim NomPDFenDWG As String
'Create a new plot configuration with all needed parameters
Set PtObj = dwg.Plot
Set PtConfigs = dwg.PlotConfigurations
'Add a new plot configuration
PtConfigs.Add "PDF", False
'The plot config you created become active
Set PlotConfig = PtConfigs.Item("PDF")
'Use this method to set the scale
PlotConfig.ConfigName = "DWG To PDF.pc3" ' "PDFCreator" ne fonctionne pas
PlotConfig.UseStandardScale = False
PlotConfig.StandardScale = acScaleToFit
'PlotConfig.ModelType = True
PlotConfig.PlotRotation = ac0degrees
PlotConfig.PlotType = acExtents
'Updates the plot
PlotConfig.RefreshPlotDeviceInfo
PlotConfig.CanonicalMediaName = "ISO_expand_A3_(297.00_x_420.00_MM)"
PlotConfig.CenterPlot = True
'Specifies whether or not to plot using the plot styles
PlotConfig.PlotWithPlotStyles = False
BackPlot = dwg.GetVariable("BACKGROUNDPLOT")
dwg.SetVariable "BACKGROUNDPLOT", 1
'Updates the plot
PlotConfig.RefreshPlotDeviceInfo
'Now you can use the PlotTofile method
NomPDFenDWG = Replace(dwg.FullName, Left(dwg.name, Len(dwg.name) - 4), Ligne)
a = PtObj.PlotToFile(Replace(NomPDFenDWG, "dwg", "pdf"), PlotConfig.ConfigName)
' Faire patienter le code 25 secondes le temps que le PDF soit créé (eh oui avec ce code ça prend 25 secondes)
Application.Wait Now + TimeValue("0:0:25")
'If you wish you can delete the plot configuration you created
'programmatically, and set the 'BACKGROUNDPLOT' system variable
'to its original status.
PtConfigs.Item("PDF").Delete
Set PlotConfig = Nothing
dwg.SetVariable "BACKGROUNDPLOT", BackPlot
dwg.Close
End Sub
I could get along with the 25 sec. but the fact is that this code's result is not the same as the manually performed Plot : manual PDF is centered and VBA's PDF is larger and thus go a little outside of the paper. I tried to move every setting int he code above but nothing changed. I even changed PlotRotation to see what would happen and the result was the same with every angle ! (strange isn't it ?)