Wednesday, September 7, 2016

Getting what you want, not what you need....

We created some iLogic code to set the printer page size and orientation to 11x17, landscape with a scale of 0.5.  The code was ran to ensure that we could print out our station drawings half-size without going to the printer settings to set the page size, orientation and scale.  The code worked great, until we created a drawing template with an 11x17 sheet size as the default.

So, we added a custom property to the drawing called  "plot_scale" and then modified the code to look for that custom property.  If the custom property was not found, the code would query the user for the scale.

A trigger was set to run the rule after the drawing has been opened.  Additionally, the rule has been defined as an external rule, to allow the rule to more easily be implemented on other systems.

iLogic Code:
 ' Rule Name: dwg11x17print  
 ' Date : 9/7/16  
 ' Purpose:  
 ' iLogic rule to set the printer to 11x17  
 ' and check for the scale via a custom iproperty "plot_scale"  
 Sub Main()  
 Dim oDOc as Document  
 oDoc = ThisDoc.Document  
 If oDoc.DocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then  
      Exit Sub  
 End If  
 Dim custPropSet As PropertySet  
 custPropSet = oDoc.PropertySets.Item("Inventor User Defined Properties")  
 Dim oPrintMgr As DrawingPrintManager  
 oPrintMgr = oDoc.PrintManager  
 Dim dScale As Double  
 Dim lPrintScale As Boolean  
 ' Try to see if the custom iProperty exists...  
 Try  
      dScale = custPropSet.item("plot_scale").Value  
      ' MessageBox.Show("Scale custom property = "&CStr(dScale), "iLogic")  
 Catch  
      lPrintScale = InputRadioBox("Select scale for printing","Half scale","Full scale" , True, Title :="SCALE LIST")  
      If lPrintScale Then  
           dScale = 0.5  
      Else   
           dScale = 1.0  
      End If  
 End Try  
 With oPrintMgr  
      .Orientation = kLandscapeOrientation  
      .AllColorsAsBlack = False  
      .ColorMode = 13314 ' Print using a gray scale   
      .ScaleMode = 13827 ' kPrintCustomScale  
      .Scale = dScale  
      .PaperSize = PaperSizeEnum.kPaperSize11x17  
 End With  
 End Sub