Use VBA to plot idw to pdf

Use VBA to plot idw to pdf

Anonymous
Not applicable
7,355 Views
47 Replies
Message 1 of 48

Use VBA to plot idw to pdf

Anonymous
Not applicable
Hi,



I've been looking into getting VBA to plot an idw to pdf automatically. From what I've found I can either have Adobe prompt for the save file location everytime, or never. Is there a way to have the file location specified within the macro code? There are two locations that I save pdf's and I'd like to have one macro save to one location, and another macro which saves to the second location. So it would be great if the file location was already specified by the marco. Currently I've been using the .SubmitPrint() method:




Public Sub PlotPDF()

If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then



Dim oDrgDoc As DrawingDocument

Set oDrgDoc = ThisApplication.ActiveDocument





' Set reference to drawing print manager

Dim oDrgPrintMgr As DrawingPrintManager

Set oDrgPrintMgr = oDrgDoc.PrintManager



' Set the printer name

oDrgPrintMgr.Printer = "Adobe PDF"



'Set the paper size , scale and orientation

oDrgPrintMgr.ScaleMode = kPrintBestFitScale

oDrgPrintMgr.PaperSize = kPaperSizeLetter

oDrgPrintMgr.PrintRange = kPrintAllSheets

oDrgPrintMgr.Orientation = kLandscapeOrientation

oDrgPrintMgr.AllColorsAsBlack = True

oDrgPrintMgr.SubmitPrint



End If

End Sub



============================



Any ideas?



Thanks!



-Andrew

Inventor 11 SP4

0 Likes
7,356 Views
47 Replies
Replies (47)
Message 2 of 48

Anonymous
Not applicable

I don't remember which version it was added, but I
think this is in Inventor 11.  Have you tried the PrintToFile method
instead of SubmitPrint?  Everything else is the same except with
PrintToFile you also specify the name of the output file.
--
Brian
Ekins
Autodesk Inventor API Product Designer

href="http://blogs.autodesk.com/modthemachine">http://blogs.autodesk.com/modthemachine
0 Likes
Message 3 of 48

Anonymous
Not applicable


Thanks for the reply!



This is my updated code:



====================================

Public Sub PlotPDF()

If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then



Dim oDrgDoc As DrawingDocument

Set oDrgDoc = ThisApplication.ActiveDocument





' Set reference to drawing print manager

Dim oDrgPrintMgr As DrawingPrintManager

Set oDrgPrintMgr = oDrgDoc.PrintManager



' Set the printer name

oDrgPrintMgr.Printer = "Adobe PDF"



'Set the paper size , scale and orientation

oDrgPrintMgr.ScaleMode = kPrintBestFitScale

oDrgPrintMgr.PaperSize = kPaperSizeLetter

oDrgPrintMgr.PrintRange = kPrintAllSheets

oDrgPrintMgr.Orientation = kLandscapeOrientation

oDrgPrintMgr.AllColorsAsBlack = True



'Set the file name

Dim sFullPDFName As String

sFullPDFName = "F:\VENDOR\" & Left$(oDrgDoc.DisplayName, Len(oDrgDoc.DisplayName) - 3) & "pdf"

oDrgPrintMgr.PrintToFile (sFullPDFName)



End If

End Sub



==================================



This creates the pdf file just fine but when I try to open it, Adobe gives me an error because the file is damaged. I guess the PrintToFile can't support a pdf extension...



any other ideas?

0 Likes
Message 4 of 48

Anonymous
Not applicable

That should work.  It's supposed to do exactly
the same thing as the SubmitPrint except it bypasses the dialog asking for the
filename and provides it directly.  I know other people have used it for
creating PDF files.  Maybe someone else reading this
newsgroup has used this and can provide some advice.  I don't have the
PDF printer available to do any testing myself.
--
Brian
Ekins
Autodesk Inventor API Product Designer

href="http://blogs.autodesk.com/modthemachine">http://blogs.autodesk.com/modthemachine
0 Likes
Message 5 of 48

Anonymous
Not applicable
I had tried using the PrintToFile method before when I was writing
my plot2pdf macro sometime ago. I remember that it did not work
(couldn't open the files). Found another pdf printer that I could
pass it the filename to print to without using the printtofile
method. It's called win2pdf. My macro also then runs a ghostscript
command to also create a monochrome tiff file from the pdf.

Bob S.

Brian Ekins (Autodesk) wrote:
> That should work. It's supposed to do exactly the same thing as the
> SubmitPrint except it bypasses the dialog asking for the filename and
> provides it directly. I know other people have used it for creating PDF
> files. Maybe someone else reading this newsgroup has used this and can
> provide some advice. I don't have the PDF printer available to do any
> testing myself.
> --
> Brian Ekins
> Autodesk Inventor API Product Designer
> http://blogs.autodesk.com/modthemachine
0 Likes
Message 6 of 48

Anonymous
Not applicable
Hello Andrew

> This creates the pdf file just fine but when I try to open it, Adobe
> gives me an error because the file is damaged.

I have seen that using the Adobe PDF print driver from a program (or
VBA) produces a PostScript file and not a PDF file.

I usually set my programs to produce PostScript files (one per sheet)
and then collect the pages in one PDF file using the Adobe Distiller.

An alternative is to make PostScript files using some Windows PostScript
driver setup and then use GhostScript to collect the PostScript files
into one PDF file.

With Regards
0 Likes
Message 7 of 48

Anonymous
Not applicable
Thanks for the replies!

Is there a way to have all of this programed into VBA? Generally speaking, I see two options:
1) Use the .SubmitPrint method and fill in the file location dialog box
2) Use the .PlotFile method and have a different program turn the PostScript into a PDF

The reason that option (1) is not favorable is because it wastes lots of time filling in the dialog box. But if option (2) requires me to use another program in addition to Inventor, it could only take longer than option (1)... making it less favorable.

So if option (2) can be controlled from within Inventor VBA so that with one click of a button the PostScript and PDF files are created and located in the correct location, then it would be faster than option (1). Otherwise there's no reason to spend the same amount of time doing a more complicated process.

Any ideas on how to automate everything together?
0 Likes
Message 8 of 48

Anonymous
Not applicable
Hello Andrew

>2) Use the .PlotFile method and have a different program turn the
PostScript into a PDF

Search for gsapi_vb on google.

There are a zip-archive with a VB6/VBA and VB.NET definitions for using
the GhostScript dll from a VB program (Copyright (c) 2002 Dan Mount and
Ghostgum Software Pty Ltd).

Using the gsapi_vb you can control GhostScript from VB and use that to
convert one or more PostScript files to PDF.

With regards,
Jens Bejer Pedersen
0 Likes
Message 9 of 48

Anonymous
Not applicable
Great!

Thank you all!
0 Likes
Message 10 of 48

AlexFielder
Advisor
Advisor
Hi all, I have cobbled together the following code (based on the previous posts in this thread and some code supplied by Brian Ekins here: http://discussion.autodesk.com/forums/message.jspa?messageID=6079079

(see attached)

I used pdfcreator: http://sourceforge.net/projects/pdfcreator/ as my pdf printer, and yet the code doesn't print anything.

I installed the pdfcreator and have successfully printed a pdf file using the supplied com example that creates an add-in for excel.

Is there something I've missed in the code below?
{code}
Public tmpstr As String
Public revisions(8, 3) As String ' 10 is the maximum number of revisions the border can have
' Add a reference to PDFCreator
Public PDFCreator1 As PDFCreator.clsPDFCreator
Public ReadyState As Boolean
Public DefaultPrinter As String

Public Sub PlotPdf()

If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
Set PDFCreator1 = New clsPDFCreator
With PDFCreator1
If .cStart("/NoProcessingAtStartup") = False Then
' CommandButton1.Enabled = False
Debug.Print "Can't initialize PDFCreator."
Exit Sub
End If
End With
Debug.Print "PDFCreator initialized."

Dim oDrgDoc As DrawingDocument

Set oDrgDoc = ThisApplication.ActiveDocument

' Set reference to drawing print manager
Dim oDrgPrintMgr As DrawingPrintManager
Set oDrgPrintMgr = oDrgDoc.PrintManager

' Set the printer name
oDrgPrintMgr.Printer = "PDFCreator"


Dim shts As sheets
Dim sht As sheet
Dim outName As String
Dim i As Integer
Dim j As Integer

' shts = oDrgDoc.sheets

For Each sht In oDrgDoc.sheets
sht.Activate
'Set the paper size , scale and orientation
oDrgPrintMgr.ScaleMode = kPrintFullScale ' kPrintBestFitScale
oDrgPrintMgr.PaperSize = sht.Size
oDrgPrintMgr.PrintRange = kPrintCurrentSheet
oDrgPrintMgr.Orientation = kLandscapeOrientation
oDrgPrintMgr.AllColorsAsBlack = False

Latestrev = RetrieveRev

outName = RetrievePE("", sht) & " REV " & Latestrev & ".pdf"
With PDFCreator1
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = "\\bas059\Aliquot\test\"
.cOption("AutosaveFilename") = outName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
oDrgPrintMgr.SubmitPrint
For i = 1 To 8
For j = 1 To 3
revisions(i, j) = ""
Next j
Next i
Next
End If
PDFCreator1.cClose
End Sub

Public Function RetrievePE(searchstring As String, oSheet As sheet) As String
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
' Dim oSheet As sheet
' Set oSheet = oDrawDoc.ActiveSheet

' Get the prompted text value from the title block.
' This is done by first getting the text box in the title
' block definition that defines the prompted text. Then
' you can use this to get the value specified for this
' particular title block instance.

Dim oBorderDef As BorderDefinition

Set oBorderDef = oSheet.Border.Definition

Dim oTextBox As TextBox
Dim bFound As Boolean
bFound = False
For Each oTextBox In oBorderDef.Sketch.TextBoxes
If GetPromptField(oTextBox.FormattedText) = searchstring Then
bFound = True
Exit For
End If
Next
If bFound Then

' oSheet.Name = oSheet.Border.GetResultText(oTextBox)
RetrievePE = oSheet.Border.GetResultText(oTextBox)
Else
MsgBox "Specified formatted text was not found in the title block."
End If

End Function
Public Function RetrieveRev() As Integer ' will only work whilst the revision is numeric!
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
Dim oSheet As sheet
Set oSheet = oDrawDoc.ActiveSheet
' Get all the (prompted) revision values from the title block.
' and add them to an array so we can sort them.

Dim oBorderDef As BorderDefinition

Set oBorderDef = oSheet.Border.Definition

Dim oTextBox As TextBox
Dim bFound As Boolean
bFound = False
Dim Revision As String
Dim cnt As Integer

Dim i As Integer
Dim j As Integer
i = 1
cnt = 0
For Each oTextBox In oBorderDef.Sketch.TextBoxes
Revision = GetPromptField(oTextBox.FormattedText)
If Revision Like "*REV*" Then
If Revision Like "*REV*Change*" Then
' add the entry to the array?
' bFound = True
' Exit For
' Debug.Print Revision
revisions(i, 1) = oSheet.Border.GetResultText(oTextBox) ' Change
cnt = cnt + 1
ElseIf Revision Like "*REV*Date*" Then
revisions(i, 3) = oSheet.Border.GetResultText(oTextBox) ' Date
cnt = cnt + 1
ElseIf Revision Like "*REV*" And Len(Revision) < 13 Then
revisions(i, 2) = oSheet.Border.GetResultText(oTextBox) ' Rev
cnt = cnt + 1
End If
If cnt = 3 Then
cnt = 0
i = i + 1
End If
End If
Next

For i = LBound(revisions) To UBound(revisions)
If revisions(i, 1) <> "" Then
Debug.Print revisions(i, 1) & "|" & revisions(i, 2) & "|" & revisions(i, 3)
End If
Next i
Bubblesort
For i = LBound(revisions) To UBound(revisions)
If revisions(i, 1) <> "" Then
Debug.Print revisions(i, 1) & "|" & revisions(i, 2) & "|" & revisions(i, 3)
End If
Next i
For i = LBound(revisions) To UBound(revisions)
If revisions(i, 2) <> "" Then
RetrieveRev = revisions(i, 2)
If revisions(i + 1, 2) = "" Then ' we reached the highest revision.
Exit For
End If
End If
Next i

End Function

' Get the text value of the prompted text. It extracts this from the' formatted text. If there's a failure then an empty string is =returned.

Private Function GetPromptField(ByVal FormattedText As String) As String

On Error GoTo ErrorFound

' Verify that this is a prompt field.
If Left$(FormattedText, 7) <> " GetPromptField = ""
Exit Function
End If
' Get the text that is to the right of the first ">" symbol
' and to the left of the last "<" symbol.
Debug.Print FormattedText
GetPromptField = Right$(FormattedText, Len(FormattedText) - InStr(FormattedText, ">"))
GetPromptField = Left$(GetPromptField, InStr(GetPromptField, "<") - 1)
' Replace any < or > with < and > symbols.
GetPromptField = Replace(GetPromptField, "<", "<")
GetPromptField = Replace(GetPromptField, ">", ">")
Exit Function
ErrorFound: GetPromptField = ""

End Function


Public Sub Bubblesort()
Dim i As Integer
Dim j As Integer
Dim temp As String
Dim iOuter As Long
Dim iInner As Long
Dim iLbound As Long
Dim iUbound As Long
Dim iTemp As String

iLbound = LBound(revisions)
For i = iLbound To UBound(revisions) ' - 1
If revisions(i, 2) <> "" Then
iUbound = i
End If
Next i

For iOuter = iLbound To iUbound ' - 1
'Which comparison
For iInner = iLbound To iUbound - iOuter - 1
'Compare this item to the next item
If revisions(iInner, 2) <> "" Then ' Continue
If revisions(iInner, 2) > revisions(iInner + 1, 2) Then
'Swap
iTemp = revisions(iInner, 1)
revisions(iInner, 1) = revisions(iInner + 1, 1)
revisions(iInner + 1, 1) = iTemp
iTemp = revisions(iInner, 2)
revisions(iInner, 2) = revisions(iInner + 1, 2)
revisions(iInner + 1, 2) = iTemp
iTemp = revisions(iInner, 3)
revisions(iInner, 3) = revisions(iInner + 1, 3)
revisions(iInner + 1, 3) = iTemp
End If
End If
Next iInner
Next iOuter

' MsgBox ("Done Sorting!")
End Sub


Private Sub PrintPage(PageNumber As Integer)
Dim cPages As Long
cPages = Selection.Information(wdNumberOfPagesInDocument)
If PageNumber > cPages Then
MsgBox "This document has only " & cPages & " pages!", vbExclamation
End If
DoEvents
ActiveDocument.PrintOut Background:=False, Range:=wdPrintFromTo, From:=CStr(PageNumber), To:=CStr(PageNumber)
DoEvents
End Sub

Private Sub PDFCreator1_eError()
AddStatus "ERROR [" & PDFCreator1.cErrorDetail("Number") & "]: " & PDFCreator1.cErrorDetail("Description")
End Sub

Private Sub PDFCreator1_eReady()
AddStatus "File'" & PDFCreator1.cOutputFilename & "' was saved."
PDFCreator1.cPrinterStop = True
CommandButton1.Enabled = True
End Sub

Private Sub AddStatus(Str1 As String)
If Len(.Text) = 0 Then
Debug.Print Now & ": " & Str1
Else
Debug.Print vbCrLf & Now & ": " & Str1
End If
End Sub
{code}
Edited by: Edgcrusher on Feb 13, 2009 10:18 AM Edited by: Edgcrusher on Feb 13, 2009 10:30 AM
0 Likes
Message 11 of 48

Anonymous
Not applicable
I am struggling with this convertion from postscript to PDF.

I am using 'Adobe PDF' as my PDF printer and getting a postscript file from that.

I downloaded gsapi_vb but I am confused by how to use it properly to be honest. My VB skills aren't the greatest. How do I use that file to go from PS to PDF. Whenever I try to run anything I get an error saying gsdll32.dll can not be found, but I know I have it on my system. Do ihave to set a search path, and if so how.

Thanks all.
0 Likes
Message 12 of 48

AlexFielder
Advisor
Advisor
Turns out I had to add a sleep into the code to get it to wait for the printer software to kick in.

The following code will print all sheets in an Inventor drawing file to pdf. Each sheet is a separate named file in a pre-assigned location.

I plan to make this into an add-in so that I can install on as many machines as I like.

Watch this space for the updated file.

In the meantime, here's the code: -

{code}Option Explicit

Public Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

Public tmpstr As String
Public revisions(8, 4) As String ' 10 is the maximum number of revisions the border can have
' Add a reference to PDFCreator
Public PDFCreator1 As PDFCreator.clsPDFCreator
Public ReadyState As Boolean
Public DefaultPrinter As String

Public Sub PlotPdf()
Dim killit
Dim numsheets As Integer

numsheets = 0
If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
Set PDFCreator1 = New clsPDFCreator
With PDFCreator1
If .cStart("/NoProcessingAtStartup") = False Then
' CommandButton1.Enabled = False
killit = Shell("taskkill /f /im PDFCreator.exe", VbAppWinStyle.vbHide)
MsgBox ("There was an error starting the pdf printer, please try (click) again!")
Debug.Print "Can't initialize PDFCreator."
Exit Sub
End If
End With
Debug.Print "PDFCreator initialized."

Dim oDrgDoc As DrawingDocument

Set oDrgDoc = ThisApplication.ActiveDocument

' Set reference to drawing print manager
Dim oDrgPrintMgr As DrawingPrintManager
Set oDrgPrintMgr = oDrgDoc.PrintManager

' Set the printer name
oDrgPrintMgr.Printer = "PDFCreator"


Dim shts As sheets
Dim sht As sheet
Dim outName As String
Dim i As Integer
Dim j As Integer
Dim Latestrev As Integer
Dim sheetsize As PaperSizeEnum
sheetsize = kPaperSizeA0
sheetsize = kPaperSizeA1
' shts = oDrgDoc.sheets

For Each sht In oDrgDoc.sheets
sht.Activate
'Set the paper size , scale and orientation
oDrgPrintMgr.ScaleMode = kPrintFullScale ' kPrintBestFitScale
' Change the paper size to a custom size. The units are in centimeters.
Dim shtsize As Long
shtsize = sht.Size
oDrgPrintMgr.PaperSize = kPaperSizeCustom
If shtsize = 9993 Then ' A0
oDrgPrintMgr.PaperHeight = 84.1
oDrgPrintMgr.PaperWidth = 118.9
ElseIf shtsize = 9994 Then ' A1
oDrgPrintMgr.PaperHeight = 59.4
oDrgPrintMgr.PaperWidth = 84.1
ElseIf shtsize = 9995 Then ' A2
oDrgPrintMgr.PaperHeight = 42
oDrgPrintMgr.PaperWidth = 59.4
ElseIf shtsize = 9996 Then ' A3
oDrgPrintMgr.PaperHeight = 29.7
oDrgPrintMgr.PaperWidth = 42
End If
oDrgPrintMgr.PrintRange = kPrintCurrentSheet
oDrgPrintMgr.Orientation = kLandscapeOrientation
oDrgPrintMgr.AllColorsAsBlack = False
oDrgPrintMgr.Rotate90Degrees = True

Latestrev = RetrieveRev

outName = RetrievePE("", sht) & " REV " & Latestrev & ".pdf"
With PDFCreator1
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = "\\bas059\Aliquot\pdfs\"
.cOption("AutosaveFilename") = outName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With

oDrgPrintMgr.SubmitPrint
Do Until PDFCreator1.cCountOfPrintjobs = 1
DoEvents
Sleep 1000
Loop
Sleep 1000
PDFCreator1.cPrinterStop = False
For i = 1 To 8
For j = 1 To 4
revisions(i, j) = ""
Next j
Next i
numsheets = numsheets + 1
Next
Else
MsgBox ("You aren't using an Inventor drawing!")
Exit Sub
End If
MsgBox ("Done Printing " & numsheets & " sheets!")
PDFCreator1.cClose
killit = Shell("taskkill /f /im PDFCreator.exe", VbAppWinStyle.vbHide)
End Sub
Public Function Setsheetsize(shtsize As PaperSizeEnum) As PaperSizeEnum
If shtsize = 9993 Then
Setsheetsize = kPaperSizeA0
ElseIf shtsize = 9994 Then
Setsheetsize = kPaperSizeA1
ElseIf shtsize = 9995 Then
Setsheetsize = kPaperSizeA2
ElseIf shtsize = 9996 Then
Setsheetsize = kPaperSizeA3
End If
End Function
Public Function RetrievePE(searchstring As String, oSheet As sheet) As String
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
' Dim oSheet As sheet
' Set oSheet = oDrawDoc.ActiveSheet

' Get the prompted text value from the title block.
' This is done by first getting the text box in the title
' block definition that defines the prompted text. Then
' you can use this to get the value specified for this
' particular title block instance.

Dim oBorderDef As BorderDefinition

Set oBorderDef = oSheet.Border.Definition

Dim oTextBox As TextBox
Dim bFound As Boolean
bFound = False
For Each oTextBox In oBorderDef.Sketch.TextBoxes
If GetPromptField(oTextBox.FormattedText) = searchstring Then
bFound = True
Exit For
End If
Next
If bFound Then

' oSheet.Name = oSheet.Border.GetResultText(oTextBox)
RetrievePE = oSheet.Border.GetResultText(oTextBox)
Else
MsgBox "Specified formatted text was not found in the title block."
End If

End Function
Public Function RetrieveRev() As Integer ' will only work whilst the revision is numeric!
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
Dim oSheet As sheet
Set oSheet = oDrawDoc.ActiveSheet
' Get all the (prompted) revision values from the title block.
' and add them to an array so we can sort them.
' Debug.Print "Retrieving revision from " & oSheet.Name
Dim oBorderDef As BorderDefinition

Set oBorderDef = oSheet.Border.Definition

Dim oTextBox As TextBox
Dim bFound As Boolean
bFound = False
Dim Revision As String
Dim cnt As Integer

Dim i As Integer
Dim j As Integer
i = 1
cnt = 0
For Each oTextBox In oBorderDef.Sketch.TextBoxes
Revision = GetPromptField(oTextBox.FormattedText)
If Revision Like "*REV*" Then
If Revision Like "*REV*Change*" Or Revision Like "*REV*CHANGE*" Then
revisions(i, 1) = oSheet.Border.GetResultText(oTextBox) ' Change
cnt = cnt + 1
ElseIf Revision Like "*REV*Date*" Or Revision Like "*REV*DATE*" Then
revisions(i, 3) = oSheet.Border.GetResultText(oTextBox) ' Date
cnt = cnt + 1
ElseIf Revision Like "*REV*" And Len(Revision) < 13 Then
revisions(i, 2) = oSheet.Border.GetResultText(oTextBox) ' Rev
cnt = cnt + 1
End If
revisions(i, 4) = oSheet.Name
If cnt = 3 Then
cnt = 0
i = i + 1
End If
End If
Next

For i = LBound(revisions) To UBound(revisions)
If revisions(i, 1) <> "" Then
' Debug.Print revisions(i, 1) & "|" & revisions(i, 2) & "|" & revisions(i, 3)
End If
Next i
Bubblesort
For i = LBound(revisions) To UBound(revisions)
If revisions(i, 1) <> "" Then
' Debug.Print revisions(i, 1) & "|" & revisions(i, 2) & "|" & revisions(i, 3)
End If
Next i
For i = LBound(revisions) To UBound(revisions)
If revisions(i, 2) <> "" Then
RetrieveRev = revisions(i, 2)
If revisions(i + 1, 2) = "" Then ' we reached the highest revision.
Exit For
End If
End If
Next i

End Function

' Get the text value of the prompted text. It extracts this from the' formatted text. If there's a failure then an empty string is =returned.

Private Function GetPromptField(ByVal FormattedText As String) As String

On Error GoTo ErrorFound

' Verify that this is a prompt field.
If Left$(FormattedText, 7) <> " GetPromptField = ""
Exit Function
End If
' Get the text that is to the right of the first ">" symbol
' and to the left of the last "<" symbol.
' Debug.Print FormattedText
GetPromptField = Right$(FormattedText, Len(FormattedText) - InStr(FormattedText, ">"))
GetPromptField = Left$(GetPromptField, InStr(GetPromptField, "<") - 1)
' Replace any < or > with < and > symbols.
GetPromptField = Replace(GetPromptField, "<", "<")
GetPromptField = Replace(GetPromptField, ">", ">")
Exit Function
ErrorFound: GetPromptField = ""

End Function


Public Sub Bubblesort()
Dim i As Integer
Dim j As Integer
Dim temp As String
Dim iOuter As Long
Dim iInner As Long
Dim iLbound As Long
Dim iUbound As Long
Dim iTemp As String

iLbound = LBound(revisions)
For i = iLbound To UBound(revisions) ' - 1
If revisions(i, 2) <> "" Then
iUbound = i
End If
Next i

For iOuter = iLbound To iUbound ' - 1
'Which comparison
For iInner = iLbound To iUbound - iOuter - 1
'Compare this item to the next item
If revisions(iInner, 2) <> "" Then ' Continue
' Debug.Print "About to sort " & revisions(iInner, 4)
If CInt(revisions(iInner, 2)) > CInt(revisions(iInner + 1, 2)) Then
'Swap
iTemp = revisions(iInner, 1)
revisions(iInner, 1) = revisions(iInner + 1, 1)
revisions(iInner + 1, 1) = iTemp
iTemp = revisions(iInner, 2)
revisions(iInner, 2) = revisions(iInner + 1, 2)
revisions(iInner + 1, 2) = iTemp
iTemp = revisions(iInner, 3)
revisions(iInner, 3) = revisions(iInner + 1, 3)
revisions(iInner + 1, 3) = iTemp
iTemp = revisions(iInner, 4)
revisions(iInner, 4) = revisions(iInner + 1, 4)
revisions(iInner + 1, 4) = iTemp
End If
End If
Next iInner
Next iOuter

' MsgBox ("Done Sorting!")
End Sub


Private Sub PrintPage(PageNumber As Integer)
Dim cPages As Long
cPages = Selection.Information(wdNumberOfPagesInDocument)
If PageNumber > cPages Then
MsgBox "This document has only " & cPages & " pages!", vbExclamation
End If
DoEvents
ActiveDocument.PrintOut Background:=False, Range:=wdPrintFromTo, From:=CStr(PageNumber), To:=CStr(PageNumber)
DoEvents
End Sub

Private Sub PDFCreator1_eError()
AddStatus "ERROR [" & PDFCreator1.cErrorDetail("Number") & "]: " & PDFCreator1.cErrorDetail("Description")
End Sub

Private Sub PDFCreator1_eReady()
AddStatus "File'" & PDFCreator1.cOutputFilename & "' was saved."
PDFCreator1.cPrinterStop = True
' CommandButton1.Enabled = True
End Sub

Private Sub AddStatus(Str1 As String)
Debug.Print vbCrLf & Now & ": " & Str1
End Sub
{code}
0 Likes
Message 13 of 48

Anonymous
Not applicable
Hi,

How do you access to PDFCreator.clsPDFCreator? I can't figure how to declare it in VB...

Thank you for your help!

Thomas
0 Likes
Message 14 of 48

Anonymous
Not applicable
Ok, I got it, "Option" > References

Thomas
0 Likes
Message 15 of 48

karthur1
Mentor
Mentor
Andrew,

Did you ever get your code to print a valid PDF? I tried what you had posted and got the same error when I tried to open the PDF that was created.



Thanks

Kirk
0 Likes
Message 16 of 48

Anonymous
Not applicable
I still haven't convinced my system administrator of the value of installing the ghostscript software. So I'm still stuck filling in the dialoge boxes, but it looks like Edgecrusher got the code below to work.

Thanks again, all
Andrew
0 Likes
Message 17 of 48

Anonymous
Not applicable
Hi,

FYI, it seems that with Inventor 2009 SP2, the pdf export is working quite well. May be you can use it.

Before SP2, the fonts were buggy, but it seems to be fixed now.

Thomas
0 Likes
Message 18 of 48

karthur1
Mentor
Mentor
Andrew,



I tried the code that he had posted, but there are errors in this that I don't know how to fix. See the attached image. The errors are shown in red.

Can anyone tell me what to do to fix these errors?

BTW, I did get a "Save Copy as PDF" routine to work in 2009. It saves a pdf as the same name as the original file from inside Inventor. No additional software needed. I am still working on it for to work for 2010. If you like, I can post it.

Thanks Edited by: karthur1 on May 13, 2009 8:58 AM
0 Likes
Message 19 of 48

AlexFielder
Advisor
Advisor
> {quote:title=karthur1 wrote:}{quote}
> Andrew,

I tried the code that he had posted, but there are errors in this that I don't know how to fix. See the attached image. The errors are shown in red.



Can anyone tell me what to do to fix these errors?



BTW, I did get a "Save Copy as PDF" routine to work in 2009. It saves a pdf as the same name as the original file. I am still working on it for to work for 2010. If you like, I can post it.



Thanks
Hi karthur, on looking at the screenshot, the errors can be corrected by inserting the following code and replacing the GetPromptField function: -

(see attached as the forum software nerfs the code for some reason)

Ah, I spotted the reason the code wasn't working. When I made my original posts, I used the {code} tags that this forum software can use; it turns out that this breaks the code. Edited by: vegbruiser on May 13, 2009 3:03 PM
0 Likes
Message 20 of 48

karthur1
Mentor
Mentor
I got the code replaced. No errors are shown in the Visual Basic editor... Thanks



Now I am trying to run this from Inventor. I loaded the macro, but when I try to run it, the "Run" button is not available.



What do I need to do to run this from Inventor?



Thanks
0 Likes