Paper print pdf

Paper print pdf

ChristianAndersenIsmyname
Advocate Advocate
1,589 Views
19 Replies
Message 1 of 20

Paper print pdf

ChristianAndersenIsmyname
Advocate
Advocate

Hi,

Is it possible to make iLogic paper print my newly created PDF?

 

I have a code that does following:

  1. Create temp location and file name
  2. Save as PDF
  3. Paper print idw
  4. Delete temp PDF.

Can I somehow make it print the PDF, instead of the idw?

 

Part of the code:

'PDF GENERATOR
'-------------------
' Lots of code that's not really important for this issue
oDataMedium.FileName = oFolder & "\" & oFileName & _
"-" & oRevNum & ".pdf"
'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 

'PRINT PDF
'-------------------

'ThisDoc.Launch(oDataMedium.FileName)
Dim oDrawDoc As Document
oDrawDoc = ThisApplication.ActiveDocument
 
Dim oPrintMgr As PrintManager
oPrintMgr = oDrawDoc.PrintManager

Dim sMyPrinter As String
sMyPrinter = "\\kumerafil1\SHARP MX-4060V .1etg"

oPrintMgr.Printer = sMyPrinter
oPrintMgr.ColorMode = kPrintDefaultColorMode
oPrintMgr.Orientation = kLandscapeOrientation
oPrintMgr.Scalemode = kCustomScale
oPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale
oPrintMgr.PaperSize = kPaperSizeA3 'A3 Size
oPrintMgr.SubmitPrint

'DELETE PDF AFTER 2000 MILLISECONDS
'-------------------
System.Threading.Thread.CurrentThread.Sleep(2000)
System.IO.File.Delete(oFolder & "\" & oFileName & _
		"-" & oRevNum & ".pdf"  )

Code works perfectly for what it says I tell it to do. I just want to add something like

PrintFile (oDataMedium.FileName)
0 Likes
1,590 Views
19 Replies
Replies (19)
Message 2 of 20

WCrihfield
Mentor
Mentor

That's a very good question.

Logically, it would think that you would have to access the application which your system uses to to display the PDF, like Adobe Reader DC, to be able to send the print command from that application.  But I haven't seen any code like that here on this forum.  There are plenty of examples of creating PDF's, but not specifically about printing one out to a paper copy through a physical printer.

I haven't fully explored this region of vb.net yet, but I think I may have a good place to start the exploration.

System.Drawing.Printing

Under this namespace is a ton of stuff relating to printing.

If you search the internet for "vb.net System.Drawing.Printing", you will find a lot of stuff to dig through.

I'm curious about this myself, but haven't had the opportunity to go down that 'rabbit hole' yet. 😉

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 20

ChristianAndersenIsmyname
Advocate
Advocate

Thanks for the reply. I’ll take a look at that when I get back to my workstation.

 

If I get it to work, I’ll make sure to post it here 🙂

 

I was also thinking; Is this easier to achieve in VBA instead of iLogic? Perhaps this is what you already meant by VB.net?

0 Likes
Message 4 of 20

WCrihfield
Mentor
Mentor

I'm not sure if it would be easier in VBA Editor than in iLogic rule editor.  Although both are similar and both descended from the same sources, they are different programming platforms.  The iLogic environment used vb.net (visual basic .NET) programming platform, while the VBA Editor uses VBA (Visual Basic for Applications).  VBA is said to be a sub-set of vb.net, but is limited to working within the applications it was designed for, while you can create external executable standalone apps with vb.net.  While VBA provides a programming environment that is tightly integrated with the application(s) it was designed to work within, vb.net has a broader reach.  There are many arguments to be made for the pros & cons of both.

 

I was talking about vb.net, though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 20

ernis
Advocate
Advocate

Hi  ChristianAndersenIsmyname

 

Tell me the secret of it all. I understand logically why it is necessary to save it in PDF format. but you create it for print only and then delete it 🤔. Why is printing from PDF better than direct printing from document?

0 Likes
Message 6 of 20

WCrihfield
Mentor
Mentor

I was a bit curious about that myself, but figured this was just a proof of concept type of example code.

@ChristianAndersenIsmyname  do you know about the "DrawingPrintManager"?  It has a lot more settings than the regular "PrintManager".

You can get it like this:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOK, "WRONG DOCUMENT TYPE")
	Return
End If

Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oDPrintMgr As DrawingPrintManager = oDDoc.PrintManager
Dim oSheet As Sheet = oDDoc.ActiveSheet
Dim oSheetSize As DrawingSheetSizeEnum = oSheet.Size
Dim oSheetHeight As Double = oSheet.Height
Dim oSheetWidth As Double = oSheet.Width

'Specify Printer to use.  If not specified, the system default printer is used.
oDPrintMgr.Printer = "full path & name of your printer"
oDPrintMgr.PrintRange = PrintRangeEnum.kPrintAllSheets
'oDPrintMgr.PrintRange = PrintRangeEnum.kPrintCurrentSheet
'oDPrintMgr.PrintRange = PrintRangeEnum.kPrintSheetRange
'oDPrintMgr.SetSheetRange(1,3)
oDPrintMgr.PrintExcludedSheets = False
oDPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale
'oDPrintMgr.Scale = 
'The following, if not specified, defaults to the Printer's default paper size
oDPrintMgr.PaperSize = PaperSizeEnum.kPaperSizeLetter
oDPrintMgr.Orientation = PageOrientationTypeEnum.kLandscapePageOrientation
oDPrintMgr.ColorMode = PrintColorModeEnum.kPrintDefaultColorMode
oDPrintMgr.NumberOfCopies = 1
oDPrintMgr.Rotate90Degrees = False
oDPrintMgr.AllColorsAsBlack = False
oDPrintMgr.RemoveLineWeights = False
oDPrintMgr.TilingEnabled = False
oDPrintMgr.SubmitPrint

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 20

ChristianAndersenIsmyname
Advocate
Advocate

Reason behind this is that Line Weight doesn't get removed properly if I'm printing directly from Iventor.

I've heard others have this same issue aswell after upgrading recently.

 

The workaround we do for this is save every drawing as PDF, then print those PDF's.

Therefore this code would save me a lot of time 🙂

Message 8 of 20

ChristianAndersenIsmyname
Advocate
Advocate

I don't have time to check this out right now, but I'll definitely look at this when I get the chance.

0 Likes
Message 9 of 20

ernis
Advocate
Advocate

@WCrihfield 

you are a real genius ilogic 👍. Your code works great for me

0 Likes
Message 10 of 20

ChristianAndersenIsmyname
Advocate
Advocate

I tried your code now, and it seems like it still prints the idw.

image.jpg

The lines are much better from pdf print.

0 Likes
Message 11 of 20

robertast
Collaborator
Collaborator

@WCrihfield 

 

I join the idea that WCrihfield is a genius. WCrihfield, can I contact you directly for a tricky issue? I would like to automate three operations that I constantly do in the same order, I would like to speed it up. I can film a video of my actions. Can you solve this?

0 Likes
Message 12 of 20

robertast
Collaborator
Collaborator

@ChristianAndersenIsmyname 

 

You install "cute PDF printer" and it will print to PDF

 

0 Likes
Message 13 of 20

ChristianAndersenIsmyname
Advocate
Advocate

@robertast

Thats not the issue though, as I'm already creating a PDF earlier in the code.

What I want is to print the PDF that is already generated.

0 Likes
Message 14 of 20

robertast
Collaborator
Collaborator

@ChristianAndersenIsmyname 

 

But I doubt illogic can directly connect and manipulate the saved PDF file if you want to print from the PDF file. But both files can be attached and managed using "Visual Studio" on it you need to try to solve your problem

I'm not sure if I'm right I should ask  @johnsonshiue

0 Likes
Message 15 of 20

WCrihfield
Mentor
Mentor

That last code I posted was purely for printing a drawing document, not a PDF.

But it shows you how to use the DrawingPrintManager, and all the additional options available through using it.

Did you change any of the settings within that code, before you ran it?

There was a setting in it for "RemoveLineWeights that was set to False (because that's how I've been using it).

Did try changing that setting to True?

(Just hoping this method of printing your drawings will replace the need to print from the PDF, when you don't have any other use for the PDF's.)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 16 of 20

ChristianAndersenIsmyname
Advocate
Advocate

Yes, I changed the code. Deleted some thats not needed, and changed that line weight from false to true.

 

oDPrintMgr.Printer = "\\kumerafil1\SHARP MX-4060V .1etg"
oDPrintMgr.PrintRange = PrintRangeEnum.kPrintAllSheets
oDPrintMgr.PrintExcludedSheets = False
oDPrintMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale
'The following, if not specified, defaults to the Printer's default paper size
oDPrintMgr.PaperSize = PaperSizeEnum.kPaperSizeA3
oDPrintMgr.Orientation = PageOrientationTypeEnum.kLandscapePageOrientation
oDPrintMgr.ColorMode = PrintColorModeEnum.kPrintDefaultColorMode
oDPrintMgr.NumberOfCopies = 1
oDPrintMgr.Rotate90Degrees = False
oDPrintMgr.AllColorsAsBlack = False
oDPrintMgr.RemoveLineWeights = True
oDPrintMgr.TilingEnabled = False
oDPrintMgr.SubmitPrint

 

Code above is what I used.

 

Am I being crazy to think this is a stupid thing Inventor does? Am I doing something wrong?

Why doesn't "remove Line Weight" works properly in the print at the first place?

0 Likes
Message 17 of 20

WCrihfield
Mentor
Mentor

We export nearly every drawing out to PDF's here, and often print from whichever one is more convenient at the time.  I have noticed some differences from how the drawing prints directly from Inventor vs from the PDF (manually).  There are several things that can effect this.  Sometimes there's just "something lost in translation". 😁

 

I don't usually mess with the layers much within Inventor,  but one thing I did was open our drawing template file, then edited the Layers and reduced a bunch of line weights.  You can also set which layers will 'scale by line weight'.  It made a big difference.  It's especially noticeable when printing a drawing that was meant for larger paper, out onto smaller (A Size) paper.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 18 of 20

ChristianAndersenIsmyname
Advocate
Advocate

I assumed “remove line weight” removed every weight on every line. But it could be something that’s lost in translation, as you say.

 

I guess it’s easier to check the template and make them thinner as you say, but it doesn’t affect the drawings that are already made, which is a bummer. 

I’ll leave this thread “not yet solved”, as there might be someone with a better workaround or even a code that does what I initially want it to do.

0 Likes
Message 19 of 20

robertast
Collaborator
Collaborator

WCrihfield gave you some very good advice on how to draw a template. And try this method to transfer data from old drawings to a new template.

Print.jpg

Message 20 of 20

WCrihfield
Mentor
Mentor

I don't know how much you use the layers, but I'm thinking the easiest way to transfer the layer settings from the template to the other older files, would be to save the layers within your Template file to the Style Library, then when you open the older files, use the built-in 'update styles' button within the Manage tab > Styles and Standards panel.

But if that solution wouldn't work for you, there is very likely a way to have an external iLogic rule (or VBA Macro) that will compare each of the layers within the given template drawing with the ones in the active drawing, and copy those settings over.  How much do you usually interact with the layers per drawing file?  If you're like me, and you pretty much never even think about them, then the first solution would likely work just fine.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)