I am trying to use pyautocad to copy a table from one autocad drawing and paste it in another. Its important that I retain the same table style and location as well. Afterwards the script populates the table.
I've tried using both the COPY and COPYBASE methods (below) but I am still being prompted to manually select the objects and insertion points. Does anyone know the proper way to do this?
import os, timeimport pyautocaddef copy_table(source_file, dest_file): acad = pyautocad.Autocad(create_if_not_exists=True) os.startfile(source_file) time.sleep(5) source_doc = acad.ActiveDocument table = None for obj in acad.iter_objects('AcDbTable'): if obj.ObjectName == "AcDbTable": table = obj break if not table: print("Table not found in the source drawing.") return insertion_point = (1.15, 24.1162) try: acad.Application.SendCommand('ENTSEL\n') acad.Application.SendCommand(f'{table.Handle}\n') acad.Application.SendCommand(f'COPY\n') # I've also tried this but still got prompted to select the table source_doc.SendCommand(f"COPYBASE \n {table.Handle}\n {insertion_point[0]}\n {insertion_point[1]}\n") print("table selected") except Exception as e: print(e) os.startfile(dest_file) time.sleep(5) dest_doc = acad.ActiveDocument # this part works dest_doc.SendCommand('_PASTECLIP\n'+ str(insertion_point[0] + 0) +','+ str(insertion_point[1] + 0) +'\n')