I tried to make a code to save a dwg file in pdf form. help please

I tried to make a code to save a dwg file in pdf form. help please

Anonymous
Not applicable
1,760 Views
7 Replies
Message 1 of 8

I tried to make a code to save a dwg file in pdf form. help please

Anonymous
Not applicable

Hello,
Please help me to solve this problem. I tried to make a code to save a dwg file in pdf form.
These mesag of error belongs to me
AcadPlot: Not defined
AcadPlotConfigurations: type AcadPlotConfigurations no defined
AcPlotScale: AcPlotScale name not declared
Below the code:

 

 

Module Mdl_Print

Public Sub PDF_Print()
'Dim AutoCAD As Object
Dim AcadApp As Object
Dim AcadDoc As Object

Dim dirInfo As New DirectoryInfo(Frm_Main.LblFolder1.Text)
Dim fileInfo As FileInfo

Dim AcadApp As AcadApplication = New AcadApplication
AcadApp.Visible = True
AcadApp.WindowState = AcWindowState.acMax
Dim success As Boolean = False


For Each fileInfo In dirInfo.GetFiles("*.dwg") 'dwg for Autocad
AcadDoc = AcadApp.Documents.Open(fileInfo.FullName)


Dim oSS As AcadSelectionSet
oSS = AcadApp.ActiveDocument.SelectionSets.Add("oSS")
oSS.Clear()


Try
Dim ftype(0) As Int16
Dim fdata(0) As Object
ftype(0) = 410 'layout
fdata(0) = "A3 - ENGLISH"

oSS.Select(AcSelect.acSelectionSetAll, , , ftype, fdata)

Dim objPrefFiles As AcadPreferencesFiles
Dim PC3PathOld As String
Dim PC3PathNew As String
Dim PMPPathOld As String
Dim PMPPathNew As String

Dim PtConfigs As AcadPlotConfigurations
Dim PlotConfig As AcadPlotConfiguration
Dim PtObj As AcadPlot
Dim BackPlot As Object

'Set the preferences object
objPrefFiles = AcadDoc.Application.Preferences.Files

'Get the current Printer Config Path (pc3)
PC3PathOld = objPrefFiles.PrinterConfigPath
MessageBox.Show(PC3PathOld, "old Printer Config path (pc3)")
objPrefFiles.PrinterConfigPath = "C:\Users\ROBERT\Documents\Deb + Herve + Will\B - Herve\Technip\Autocad\1st project\OpenExcel\PC3 Files"
PC3PathNew = objPrefFiles.PrinterConfigPath
MessageBox.Show(PC3PathNew, "new Printer Config path (pc3)")

'Get the current Printer Desc Path (pmp)
PMPPathOld = objPrefFiles.PrinterDescPath
MessageBox.Show(PMPPathOld, "Printer Desc Path (pmp)")
objPrefFiles.PrinterDescPath = "C:\Users\ROBERT\Documents\Deb + Herve + Will\B - Herve\Technip\Autocad\1st project\OpenExcel\PMP Files"
PMPPathNew = objPrefFiles.PrinterDescPath
MessageBox.Show(PMPPathNew, "Printer Desc Path (pmp)")

 

PtObj = AcadDoc.Plot
AcadApp.ActiveDocument.AcPlotType.acExtents()

PtConfigs = AcadDoc.PlotConfigurations
''Add a new plot configuration
PtConfigs.Add("PDF", False)
'
''The plot config you created become active
PlotConfig = PtConfigs.Item("PDF")

''Use this method to set the scale
PlotConfig.StandardScale = AcPlotScale.acScaleToFit
''Updates the plot
PlotConfig.RefreshPlotDeviceInfo()

'Here you specify the pc3 file you want to use
PlotConfig.ConfigName = "Herve.pc3"

'You can select the plot style table here
PlotConfig.StyleSheet = "monochrome.ctb"

'You can select the Scale Line Weight
PlotConfig.ScaleLineweights = True

'Specifies Paper Size
PlotConfig.CanonicalMediaName = "ISO_A4_(210.00_x_297.00_MM)"

'Specifies whether or not to plot using the plot styles
PlotConfig.PlotWithPlotStyles = True

BackPlot = AcadDoc.GetVariable("BACKGROUNDPLOT")
AcadDoc.SetVariable("BACKGROUNDPLOT", 0)

'Updates the plot
PlotConfig.RefreshPlotDeviceInfo()
MessageBox.Show("scale" & PlotConfig.StandardScale)
MessageBox.Show("canonical media name" & PlotConfig.CanonicalMediaName)
MessageBox.Show("config name" & PlotConfig.ConfigName)
MessageBox.Show("plot type" & PlotConfig.PlotType)
MessageBox.Show("scale line weight" & PlotConfig.ScaleLineweights)

'Now you can use the PlotTofile method
If PtObj.PlotToFile(Replace(AcadDoc.FullName, "dwg", "pdf"), PlotConfig.ConfigName) Then
AcadDoc.Utility.Prompt(vbLf + "PDF Was Created")
Else
AcadDoc.Utility.Prompt(vbLf + "PDF Creation Unsuccessful")
End If

'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()
PlotConfig = Nothing
AcadDoc.SetVariable("BACKGROUNDPLOT", BackPlot)

objPrefFiles.PrinterConfigPath = "C:\Users\ROBERT\AppData\Roaming\Autodesk\AutoCAD 2014\R19.1\enu\Plotters"
objPrefFiles.PrinterDescPath = "C:\Users\ROBERT\AppData\Roaming\Autodesk\AutoCAD 2014\R19.1\enu\Plotters\PMP File"

oSS.Clear()

If AcadDoc.Saved Then
AcadDoc.Close(False)
End If
AcadDoc = Nothing
AcadApp.Quit()

AcadApp = Nothing
success = True
Catch ex As Exception
MsgBox(ex.Message + vbLf + ex.StackTrace)
success = False
End Try
' AcadDoc.Close()
AcadDoc = Nothing
' AcadApp.Quit()
Next
AcadApp.Quit()
End Sub
End Module

0 Likes
1,761 Views
7 Replies
Replies (7)
Message 2 of 8

norman.yuan
Mentor
Mentor

Firstly, when your post includes big chunk of code, the code should be inserted using the "Insert Code" toolbar button, shown in the picture below, so that the code would not be so hard to read and people would not be discouraged from your question.

 

Untitled.png

 

Secondly, it would be better for you to be more specific on the error you have, such as when you get the error? Does it from code compiling, or from running?

 

My guess is that your code does not compile. That is, when building the code, you get the said error. Because you use AutoCAD COM API, you need to set references to 2 COM libraries: AutoCAD 20xx Type Library and AutoCAD/ObjectDBX Common xx Type Library. You probably missed one of them.

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 8

Anonymous
Not applicable

Hello ,
The reference acmgd.dll and acdmMgd and Autocad 2014 type library are well add .

but when I add the ACcoreMgd or  autodesk.autocas.interop.common the following message appears at the path part: the system can not find the specified reference
Note: Visual Basic 2005 and Autocad 2014

thank you for your reply

0 Likes
Message 4 of 8

norman.yuan
Mentor
Mentor

No offence. It looks like you might not have enough knowledge on AutoCAD and AutoCAD programming. The code you posted USES AutoCAD COM API, not AutoCAD .NET API, as you just mentioned (acmgd.dll/acdbmgd.dll and accoremgd.dll), which CANNOT be used in EXE application.

 

You only need to set references to the 2 COM type libraries for the code you showed. If you want to use AutoCAD .NET API, I'd suggest you study it from basic AutoCAD .NET topics (plus very well understanding how AutoCAD works) before doing advanced programming, such as plotting drawing to PDF.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 8

Anonymous
Not applicable

If you allow me you can tell me what is the reference to add and how
thank you in advance

0 Likes
Message 6 of 8

norman.yuan
Mentor
Mentor

I did mention the 2 COM type libraries you need to reference, didn't I?

 

AutoCAD 20xx Type Library and AutoCAD/ObjectDBX Common xx Type Library

 

If you use Visual Studio, right-click the project in Solution Explorer and select "Add -> Reference...", in the dialog box, select "COM" tab, and then find these 2 type libraries (you may want to select the correct language version, if multiple of these libraries are listed.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 7 of 8

Anonymous
Not applicable

AutoCAD 20xx Library type is well add but AutoCAD / ObjectDBX Common xx I have not found it

0 Likes
Message 8 of 8

norman.yuan
Mentor
Mentor

Do you have AutoCAD installed? If yes, they should be there. If you cannot find they, then your computer does not have AutoCAD installed. No AutoCAD installed, you CANNOT develop application for it.

Norman Yuan

Drive CAD With Code

EESignature