I’m struggling with exporting a PDF of the current view to a defined physical size. According to the API docs Model#export should accept a hash with settings, but no settings I provide appear to make any difference. Instead the values from when I last exported a PDF using the UI are used. Does anyone know if the PDF exporter even supports this?
It seems the exporter does accept some options, but only some and only if the exact right data types are used. And all errors are silently swallowed -_- .
height_units as Length::Millimeter is ignored but Length::Inches appears to be supported. window_height as integer is ignored but float seems to be supported.
this julia_test.pdf (8.7 KB) doesn’t show any content at all in the default ‘Preview.app’ but reports extremely large page size and locks the system if you try to resize it…
the second is fan_effects_large.pdf (8.8 KB) a standard export of the same model view…
(Thinking out loud.) Rather than using a literal hash, try using named arguments and Ruby will collect them into a hash automatically. Also be sure to set the model units (as the docs say that it defaults to feet [which is dumb, it should default to the model’s units.])
def model_units()
opts = Sketchup.active_model.options["UnitsOptions"]
fmt = opts["LengthFormat"]
case fmt
when 0 # Decimal
unit = opts["LengthUnit"]
case unit
when 0 # Inches
Length::Inches
when 1 # Feet
Length::Feet
when 2 # mm
Length::Millimeter
when 3 # cm
Length::Centimeter
when 4 # m
Length::Meter
end
when 1 # Architectural
Length::Inches
when 2 # Engineering
Length::Feet
when 3 # Fractional
Length::Inches
end
end ###
This is what I usually do but since the API docs usually use hashes I thought I could give that a try too (and it was also convenient for setting up different settings depending on OS). Turned out the exported did accept the parameters, but not if the height was an integer.
Regarding the Mac exporter, I’m very confused what unit it uses. Could someone try exporting two PDFs with different heights passed, just to see if the value is being used at all?
There are errors in the documentation for PDF export on Mac.
The options linked to pdf export are named:
image_height (not imageHeight)
image_width (not imageWidth)
line_weight
of those options only image_weight is having an effect on files in my initial testing. I’ll continue to investigate and will get the documentation updated.
I want an option for image_weight ! Are you afraid of your laptop being stolen? Just create an image with a weight of 100 kg and no one can carry it until you delete the file :3 .
On a Mac, I’ve preferred to use the print dialog and save as pdf instead of the native pdf exporter as posted here. Page setup effects the result: paper size, paper scale and line weight factor in 2019. A better exporter would probably still be welcome though.