I am writing a batch printing script so that I do not have to manually open up 100’s of drawings at a time when doing a shop drawing submittal. I have the batching GUI written and it performs perfectly however the resulting prints I get do not reflect what is in my layouts. I have narrowed the culprit down to the print settings and actually found a few different issues. I’ll try to be as clear and concise in my explanations but please ask for additional info/ script examples to help diagnose the issues. First the code I am performing my testing with:
import rhinoscriptsyntax as rs import Rhino class _Printer(): def __init__(self,_printer,_layout,_height,_width): self.layout=_layout self.height=_height self.width=_width self.printer=_printer def PrintImage(self,Num): cmd="-_Print " cmd+="Setup " ## Setup Margins ## cmd+="Margins " cmd+="TopMargin=5 " cmd+="BottomMargin=5 " cmd+="LeftMargin=5 " cmd+="RightMargin=5 " cmd+="_Enter " cmd+="Destination " cmd+="OutputColor " cmd+="DisplayColor " cmd+="Printer " cmd+='"'+str(self.printer)+'"'+" " cmd+="Pagesize " cmd+=str(self.width*25.4)+" " #converts page size to inches cmd+=str(self.height*25.4)+" " #converts page size to inches cmd+="OutputType=Raster " cmd+="_Enter " cmd+="View " cmd+="ViewportArea " cmd+="Extents " for i in range(0,2): #Looping through twice tying to set proper window - not sure if necessary anymore cmd+="ViewportArea " cmd+="Window " cmd+="0.25,0.25,0 " if self.height==8.5 and self.width==11: cmd+=str(16.84)+","+str(12.79)+",0 " elif self.height==11 and self.width==17: cmd+=str(16.85)+","+str(10.85)+",0 " elif self.height==24 and self.width==36: cmd+=str(35.85)+","+str(23.85)+",0 " cmd+="_Enter " cmd+="_Enter " cmd+="_Enter " cmd+="Setup " cmd+="Destination " cmd+="Pagesize " cmd+=str(self.width*25.4)+" " cmd+=str(self.height*25.4)+" " cmd+="_Enter " cmd+="_Enter " if Num==0: rs.Command(cmd) else: cmd+="Preview " rs.Command(cmd) if __name__=="__main__": Dest="C:\\Users\\peters\\Desktop\\" Printer="Adobe PDF" Layout="DRAWING" Height=11 Width=17 p=_Printer(Printer,Layout,Height,Width) p.PrintImage(0) p.PrintImage(1)
Now a quick explanation: I have three page sizes that are commonly printed - 11"x17" standard print size submitted to clients for aproval - my layout page in rhino is setup to print this size by default. 8.5"x11" standard print size for in-house documents it is a scaled down version of the 11x17 and includes an “oversized” stamp and finally 24x36 for settings, elevations and sections
Now on to the issues at hand:
In the print dialog box I can not print the “layout” because it does not always appear in the same location from drawing to drawing - I think this has something to do with the Position : Centered and where the drawing is offset from. However, I can not control any of this from the _-Print menu
Extents does not always work because of the way some drafters tag their models i.e. basepoints are wayyy off in space and I end up with a tiny drawing on a big piece of paper
I assumed printing a window would be foolproof because I am setting the window via 2 points. My assumptions proved to be wrong - A window does not necessarily get set the way I assumed; see the below picture (This is from a previous version of the script - I can upload it but I dont want my post getting longer than it already is)
I set up a for loop to see if by setting the window size twice that it would actually set properly - It seems that some fields do not get overwritten unless they are changed twice for some reason??
I found a work around to this issue by setting the extents first and then a window but I am afraid it will not be a perfect solution (it works on my test drawing but I am afraid the block basepoints will give me problems again) - plus its an ugly solution
Finally you will notice that in my code I call p.PrintImage(0) twice. This is because the adobe pdf page size is set correctly but the printer details and scale are not. Please see the images below. However, if I call the same function a second time it sets the printer details correctly but that leaves me with the annoying task of pressing escape so that round 2 can run (I really really do not want write the code so that a fake escape key is pressed I feel like there should be a cleaner solution out there)
Thanks for bearing with me through this long post! Any insight would be greatly appreciated!!