Use VBA to plot idw to pdf

Use VBA to plot idw to pdf

Anonymous
Not applicable
7,362 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,363 Views
47 Replies
Replies (47)
Message 41 of 48

AlexFielder
Advisor
Advisor
Hi again Claus,

It seems that the following line: -

{code}'Wait until the PDF file shows up then release the objects
Do Until Dir(sPDFPath & sPDFName) <> ""
DoEvents
Loop{code}

is still causing me a few issues - I tried changing it to the following: -

{code}'Wait until the PDFCreator queue is clear
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop{code}
as recommended by the previous link you posted, but either PDFCreator isn't functioning correctly, or I'm doing it wrong (most likely) so I reverted to checking for a completed file before moving onto the next one. I suppose I could combine the two of them but at the moment I'm happy as it seems to work correctly and produce the correct number of .pdf files per .idw file 99% of the time.

One thing I hadn't properly considered were drawings that (for our purposes) have more than 1 item and/or drawing list, and hence would end up overwriting the subsequent sheets of the same drawing. I suppose I could simply create a method of combining files if they meet the "multiple sheet" criteria.
0 Likes
Message 42 of 48

Anonymous
Not applicable
Hi Veg

As for the first part, I haven´t had same problems. I use:

{code}
'Wait until job done
Do Until PDFCreator1.cCountOfPrintjobs = 0
DoEvents
Sleep 1000
Loop
{code}

That is, also after the queue is empty, waiting 1 sec. to be sure.
By the way I use PDFCreator version 0.9.3

For the second part, I'm not sure what you mean with: "...drawings that (for our purposes) have more than 1 item and/or drawing list". In my world I have idw's with 1, 2, 3 or more sheets, producing one pdf with 1, 2, 3 or more pages using the combine call. As I have understood your code, you produce 1, 2, 3 or more pdf*s from same idw.

I use Inventor 2009

Regards Claus
0 Likes
Message 43 of 48

BenjP
Advocate
Advocate

Hi there,

 

how can I get this going on my Inv 2011?

Could you give me a step by step?

 

Thx

Ben

0 Likes
Message 44 of 48

Anonymous
Not applicable

 

I only know a liitle bit of EXCEL VBA. now i want to use excel to plot a list of dwg file (alreay listed in one xls file),   leaned a lot from this topic, i made my own code and run in my laptop. it is going well.
but when i run in my office, I got some problems. it seems all print manger setting failed. (such i only get one sheet of a 4sheets dwg file, and the paper size is wrong) 
the difference of my laptop and the computer in my office is we had installed AUTODESK VAULT in my office computer.
it will be very helpful of any advice.
here is part of the code:
Sub printfile() '
Dim wordDoc As Object
 On Error GoTo ErrorHandler
Set wordDoc = CreateObject("inventor.Application") 
With Application
        .ScreenUpdating = False
        
End With
With wordDoc
For i = 0 To n
mydoc = mpath + docfile(i)
 .Visible = False
 .Documents.Open mydoc
.ActiveDocument.PrintManager.Printer = "Adobe PDF"
.ActiveDocument.PrintManager.PaperSize = kPaperSizeA0
.ActiveDocument.PrintManager.PrintRange = kPrintAllSheets
.ActiveDocument.PrintManager.Orientation = kLandscapeOrientation
.ActiveDocument.PrintManager.AllColorsAsBlack = False
.ActiveDocument.PrintManager.ScaleMode = kPrintBestFitScale
.ActiveDocument.PrintManager.SubmitPrint
.ActiveDocument.Close
   
 Next i
End With
   
   wordDoc.Quit
   Set wordDoc = Nothing
   Exit Sub
ErrorHandler:
   wordDoc.Quit
   Set wordDoc = Nothing
   MsgBox Err.Description, vbCritical, "Error: " & Err.Number
End Sub

 

0 Likes
Message 45 of 48

Anonymous
Not applicable

 

I only know a liitle bit of EXCEL VBA. now i want to use excel to plot a list of dwg file (alreay listed in one xls file),   leaned a lot from this topic, i made my own code and run in my laptop. it is going well.
but when i run in my office, I got some problems. it seems all print manger setting failed. (such i only get one sheet of a 4sheets dwg file, and the paper size is wrong) 
the difference of my laptop and the computer in my office is we had installed AUTODESK VAULT in my office computer.
it will be very helpful of any advice.
here is part of the code:
Sub printfile() '
Dim wordDoc As Object
 On Error GoTo ErrorHandler
Set wordDoc = CreateObject("inventor.Application") 
With Application
        .ScreenUpdating = False
        
End With
With wordDoc
For i = 0 To n
mydoc = mpath + docfile(i)
 .Visible = False
 .Documents.Open mydoc
.ActiveDocument.PrintManager.Printer = "Adobe PDF"
.ActiveDocument.PrintManager.PaperSize = kPaperSizeA0
.ActiveDocument.PrintManager.PrintRange = kPrintAllSheets
.ActiveDocument.PrintManager.Orientation = kLandscapeOrientation
.ActiveDocument.PrintManager.AllColorsAsBlack = False
.ActiveDocument.PrintManager.ScaleMode = kPrintBestFitScale
.ActiveDocument.PrintManager.SubmitPrint
.ActiveDocument.Close
   
 Next i
End With
   
   wordDoc.Quit
   Set wordDoc = Nothing
   Exit Sub
ErrorHandler:
   wordDoc.Quit
   Set wordDoc = Nothing
   MsgBox Err.Description, vbCritical, "Error: " & Err.Number
End Sub

 

0 Likes
Message 46 of 48

AlexFielder
Advisor
Advisor

hi gumen.wang!

 

I think you're getting your wires crossed here - if it's .dwg files you want to print, you don't need Inventor for that; AutoCAD is what you should be using.

0 Likes
Message 47 of 48

Anonymous
Not applicable

Hi Alex

thanks for you reply.

these dwg files are created by inventor. my intention is to using inventor to plot it to pdf. so when "dwf" or some filetype else is needed, we can change the code easily.

just a miute ago, i tried defuctioned the "vault" addin, but the problems remains. I still got one sheet of pdf for a 4 sheet dwg file. and just  maby 10 file of all over 200 file have the problem.

could you give me more help wth it..........   thanks

 

0 Likes
Message 48 of 48

Anonymous
Not applicable

another thing is :

we have to enable the "vault" or some other addin. then how can i silent all "prompt" of these addin?  such as "check in" "check out" things

..............thanks for any advice

0 Likes