VB.Net Eample - Create Pdf File From Drawing (idw or dwg)

VB.Net Eample - Create Pdf File From Drawing (idw or dwg)

isocam
Collaborator Collaborator
514 Views
3 Replies
Message 1 of 4

VB.Net Eample - Create Pdf File From Drawing (idw or dwg)

isocam
Collaborator
Collaborator

Can anybody help?

 

Has anybody managed to create a VB.Net program that can automatically create a PDF file from an Inventor "idw" or "dwg" file?

 

If you have, please can you attach a sample in zip format?

 

Many thanks in advance!

 

Darren

0 Likes
Accepted solutions (1)
515 Views
3 Replies
Replies (3)
Message 2 of 4

BM_Ashraf
Advocate
Advocate

Hi, 

Check this Video 
https://www.youtube.com/watch?v=lZwvoapamgo&t=5s 

 

Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

 

Sub PDF()

 

Dim oDoc As DrawingDocument = g_inventorApplication.ActiveEditDocument

 

Dim oSuffix As String = System.IO.Path.GetExtension(oDoc.FullDocumentName)

 

Dim oPDF As String
oPDF = Replace(oDoc.FullDocumentName, oSuffix, ".pdf")

 

If System.IO.File.Exists(oPDF) Then
Dim Ask2 As Object
Ask2 = MsgBox("The document already exists in the selected path!" & vbLf & vbLf & oPDF & vbLf & vbLf & "Do you want to override it?", MsgBoxStyle.YesNo, "Existing Pdf Document")
If Ask2 = vbNo Then
 exit sub
End If

End If

 

On Error Resume Next
Call oDoc.SaveAs(oPDF, True)

 

 

End Sub

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!

0 Likes
Message 3 of 4

isocam
Collaborator
Collaborator

Hi,

 

I have tried your code but the following line creates an error

 

Dim oDoc As DrawingDocument = g_inventorApplication.ActiveEditDocument

 

Please can you tell me what is wrong?

 

Kind Regards

 

Darren

Message 4 of 4

BM_Ashraf
Advocate
Advocate
Accepted solution

Sorry , I missed this line 

Public g_inventorApplication As Inventor.Application
it's usually default in Inventor template in Visual studio 

____________________________________________________

Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

 

Public g_inventorApplication As Inventor.Application

 

Sub PDF()

 

Dim oDoc As DrawingDocument = g_inventorApplication.ActiveEditDocument

 

Dim oSuffix As String = System.IO.Path.GetExtension(oDoc.FullDocumentName)

 

Dim oPDF As String
oPDF = Replace(oDoc.FullDocumentName, oSuffix, ".pdf")

 

If System.IO.File.Exists(oPDF) Then
Dim Ask2 As Object
Ask2 = MsgBox("The document already exists in the selected path!" & vbLf & vbLf & oPDF & vbLf & vbLf & "Do you want to override it?", MsgBoxStyle.YesNo, "Existing Pdf Document")
If Ask2 = vbNo Then
 exit sub
End If

End If

 

On Error Resume Next
Call oDoc.SaveAs(oPDF, True)

 

 

End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.

Blue Mech

Add-ins for Inventor!

0 Likes