@dharman thank you very much for sharing this! It’s really helped alleviate this part of my workflow!
I’ve been scouring the API docs and cannot seem to figure out how to set the .pdf settings to be black and white. Obviously if my curves are already black this isn’t an issue but when printing things like linked blocks sometimes the layer colors are well… colorful and by default I need all documents to be printed black and white.
I could create a script that sets layer/object colors to black but I want to preserve user’s layer colors if possible
Here’s the bit of code from your Print PDF component where the .pdf is being written:
if P:
pdf = Rhino.FileIO.FilePdf.Create()
dpi = 300
#loop through all layouts and print to single page pdf
for i, view in enumerate(layouts_get_by_names(LN)):
#Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.PageHeight
#Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.PageWidth
w = mmToInch(view.PageHeight)
h = mmToInch(view.PageWidth)
size = System.Drawing.Size(h*dpi, w*dpi)
settings = Rhino.Display.ViewCaptureSettings(view, size, dpi)
if M==True:
settings.RasterMode = True
pdf.AddPage(settings)
if not os.path.exists(FP):
os.mkdir(FP)
filepath = os.path.join(FP, FN+".pdf")
print filepath
pdf.Write(filepath)
If you or anyone else happen to have any leads on setting the .pdf capture to black and white that would be very much appreciated!
Thanks again for sharing!
EDIT:
I think this is what I’m looking for:
https://developer.rhino3d.com/api/rhinocommon/rhino.display.viewcapturesettings.colormode
EDIT2:
It appears that ViewCaptureSettings.ColorMode is read only? Is this the case or am I missing something obvious.
I would like to be able to set the color mode from python like this:
if M==True:
settings.RasterMode = True
settings.ColorMode = CM
Where CM is an input variable of integer type, so by setting the int to 2 I should be setting it to Black And White according to the .ColorMode method.
Thank you!
EDIT 3:
Okay I figured it out, sharing here if it helps anyone:
# Determine the color mode based on the value of CM
if CM == 0:
color_mode = Rhino.Display.ViewCaptureSettings.ColorMode.DisplayColor
elif CM == 1:
color_mode = Rhino.Display.ViewCaptureSettings.ColorMode.PrintColor
elif CM == 2:
color_mode = Rhino.Display.ViewCaptureSettings.ColorMode.BlackAndWhite
else:
# Handle invalid CM values here (optional)
color_mode = Rhino.Display.ViewCaptureSettings.ColorMode.DisplayColor
Perhaps there’s a more concise/elegant way to handle this?