Hello,
I would like to modify the attached Python script to read PDF layers rather than 3DM layers, which is it currently set up to do. I tried modifying the Python code but was unable to figure it out. Can anyone help out? Thanks.
Thanks @scottd! I’ve experimented with Rhino 8 and saw this functionality existed but didn’t have a chance to try it - thanks for the heads up! I’m still using Rhino 7, so this might be a great reason to upgrade to 8!
@scottd I had a follow up question. Do you know of a way to select the geometry from a particular layer using these new components? When I tried to filter my selection based on particular layer, it still seemed to still select every object. See attached. Any help would be appreciated!
Initially the questions was surrounding how to read in a PDF with Python. Here is code to read in a PDF to a headless doc that can be manipulated and potentially written back out:
#! python3
import rhinoscriptsyntax as rs
import scriptcontext as sc
import math
import System
import System.Collections.Generic
import Rhino
import os
doc = Rhino.RhinoDoc.CreateHeadless(None)
options = Rhino.FileIO.FilePdfReadOptions()
options.LoadText = False
#prompt the user for a file to import
filter = "PDF file (*.pdf)|*.pdf||"
path = rs.OpenFileName("Open PDF File", filter)
doc.Import(path, options.ToDictionary())
print(f"{doc.Objects.Count} objects")
for obj in doc.Objects:
nlayer = obj.Attributes.LayerIndex
print(f"Layer Index is {nlayer}")
doc.Dispose()