from pyautocad import Autocad, APoint
def copy_layer_contents(source_file, target_file, layer_name):
acad = Autocad(create_if_not_exists=True)
acad.Documents.Open(source_file)
source_doc = acad.ActiveDocument
source_objects = []
for obj in source_doc.ModelSpace:
if obj.Layer == layer_name:
source_objects.append(obj)
source_doc.SelectionSets.Add('source_objects')
source_objects_ss = source_doc.SelectionSets.Item('source_objects')
source_objects_ss.Clear()
for obj in source_objects:
source_objects_ss.SelectByObject(obj)
source_doc.CopyObjects(source_objects_ss)
acad.Documents.Open(target_file)
target_doc = acad.ActiveDocument
target_doc.ModelSpace.Paste()
target_doc.Close(SaveChanges=True)
source_doc.Close(SaveChanges=False)
source_file = r"C:\path\to\source.dwg"
target_file = r"C:\path\to\target.dwg"
layer_name = "LayerName"
copy_layer_contents(source_file, target_file, layer_name)