I try to script the reading blocks inside a file to import them, but at th ebeginning I have no access to read my choosen file…
Any help, I am sure it is just an option to allow me accessing it…
import rhino
import rhinoscriptsyntax as rs
# Prompt the user to select a 3dm file
file_path = rs.OpenFileName("Open 3dm File", "3dm Files (*.3dm)|*.3dm|All Files (*.*)|*.*||")
# Open the file and get a list of block definitions
try:
doc = Rhino.RhinoDoc.Open(file_path)
block_defs = doc.Blocks.GetBlockList()
except Exception as e:
print("An error occurred:", e)
doc = None
block_defs = []
# Display a list of block definitions to the user
selected_index = -1
if block_defs:
names = [block.Name for block in block_defs]
selected_index = rs.GetListBox("Select a block", names)
# Import the selected block definition into the current document
if selected_index >= 0:
block_def = block_defs[selected_index]
Rhino.RhinoDoc.ActiveDoc.Blocks.Import(block_def)
# Close the opened document
if doc:
doc.Close()
Thanks for help